diff --git a/tests/Core/PantherTestCase.php b/tests/Core/PantherTestCase.php new file mode 100644 index 0000000..f81c358 --- /dev/null +++ b/tests/Core/PantherTestCase.php @@ -0,0 +1,50 @@ +client = static::createPantherClient([ + 'external_base_uri' => 'http://localhost:9080' + ]); + $this->query = $this->container()->get(UserRepositoryQuery::class); + } + + protected function authenticateAdmin(): void + { + $this->client->request('GET', '/login'); + $this->client->submitForm('Login', [ + '_username' => 'admin@localhost', + '_password' => 'admin_password', + ]); + $this->client->waitFor('.nav-item-label'); + } + + protected function authenticateWriter(): void + { + $this->client->request('GET', '/login'); + $this->client->submitForm('Login', [ + '_username' => 'writer@localhost', + '_password' => 'writer_password', + ]); + $this->client->waitFor('.nav-item-label'); + } +} diff --git a/tests/Core/Site/NavigationTest.php b/tests/Core/Site/NavigationTest.php new file mode 100644 index 0000000..1108a13 --- /dev/null +++ b/tests/Core/Site/NavigationTest.php @@ -0,0 +1,39 @@ +authenticateAdmin(); + + $this->client->request('GET', '/admin/site/tree'); + $this->client->waitFor('.toast-body.text-text-warning'); + $this->assertSelectorTextContains('.toast-body.text-text-warning', 'You must add a navigation.'); + + $this->client->request('GET', '/admin/site/navigation'); + $this->assertSelectorTextContains('h1', 'Navigations'); + + $this->client->request('GET', '/admin/site/navigation/new'); + $this->assertSelectorTextContains('h1', 'New navigation'); + $this->client->submitForm('Save', [ + 'navigation[label]' => 'Test navigation', + 'navigation[locale]' => 'en', + 'navigation[code]' => 'nav', + 'navigation[domain]' => 'localhost', + ]); + + $this->client->waitFor('.toast-body.text-text-success'); + $this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.'); + + $this->client->request('GET', '/admin/site/navigation'); + $this->assertSelectorTextContains('.table tbody tr td', 'Test navigation'); + } +} diff --git a/tests/Core/Site/PageTest.php b/tests/Core/Site/PageTest.php new file mode 100644 index 0000000..0a7a529 --- /dev/null +++ b/tests/Core/Site/PageTest.php @@ -0,0 +1,30 @@ +client->request('GET', '/admin/site/tree'); + $this->client->executeScript("document.querySelector('#node-2 .float-right button[data-modal]').click()"); + + $this->client->waitFor('#form-node-edit'); + $this->client->executeScript("document.querySelector('#node-page-action .card-header label').click()"); + $this->client->executeScript("document.querySelector('a[href=\"#form-node-edit-routing\"]').click()"); + $this->client->executeScript("document.querySelector('#node_url').value='/foo'"); + $this->client->executeScript("document.querySelector('#node_code').value='/foo'"); + $this->client->executeScript("document.querySelector('.modal.show .modal-footer button[type=\"submit\"]').click()"); + + $this->client->waitFor('.toast-body.text-text-success'); + $this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.'); + + $this->assertSelectorTextContains('#node-2 .float-right a', 'Page'); + } +} diff --git a/tests/Core/Site/TreeTest.php b/tests/Core/Site/TreeTest.php new file mode 100644 index 0000000..d51d114 --- /dev/null +++ b/tests/Core/Site/TreeTest.php @@ -0,0 +1,32 @@ +client->request('GET', '/admin/site/tree'); + $this->assertSelectorTextContains('button[data-toggle="modal"]', 'Add a menu'); + $this->client->executeScript("document.querySelector('button[data-toggle=\"modal\"]').click()"); + + $this->client->waitFor('#form-menu-new'); + $this->client->submitForm('Save', [ + 'menu[label]' => 'Test menu', + 'menu[code]' => 'menu', + ]); + + $this->client->waitFor('.toast-body.text-text-success'); + $this->assertSelectorTextContains('.toast-body.text-text-success', 'The data has been saved.'); + + $this->client->request('GET', '/admin/site/tree'); + $this->assertSelectorTextContains('.h4', 'Test menu'); + $this->assertSelectorTextContains('#node-2 .col-6', 'First element'); + } +}