From 79876ad644284175a8ea098542aef54bc74188d5 Mon Sep 17 00:00:00 2001 From: astridx Date: Sat, 10 Dec 2016 11:22:19 +0100 Subject: [PATCH 1/7] create tests for com_modules --- .../Acceptance/Administrator/AdminPage.php | 59 +++- .../Administrator/ModuleEditPage.php | 94 ++++++ .../Administrator/ModuleManagerPage.php | 53 +++ .../Step/Acceptance/Administrator/Admin.php | 4 + .../Step/Acceptance/Administrator/Module.php | 315 ++++++++++++++++++ tests/codeception/acceptance/modules.feature | 59 ++++ 6 files changed, 580 insertions(+), 4 deletions(-) create mode 100644 tests/codeception/_support/Page/Acceptance/Administrator/ModuleEditPage.php create mode 100644 tests/codeception/_support/Page/Acceptance/Administrator/ModuleManagerPage.php create mode 100644 tests/codeception/_support/Step/Acceptance/Administrator/Module.php create mode 100644 tests/codeception/acceptance/modules.feature diff --git a/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php b/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php index f67b37c480..8889b69aae 100644 --- a/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php +++ b/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php @@ -101,9 +101,11 @@ public function search($keyword) } /** - * Method to search user with username + * Method to search item with name or title + * We put the delay before the checkAllResults() because otherwise it + * does not work inside the module manager * - * @param string $keyword The username of user + * @param string $keyword The name or title of an item * * @since __DEPLOY_VERSION__ * @@ -115,6 +117,7 @@ public function haveItemUsingSearch($keyword) $I->amOnPage(static::$url); $I->search($keyword); + $I->wait(1); $I->checkAllResults(); $I->wait(1); } @@ -228,6 +231,12 @@ public function clickToolbarButton($button) case "featured": $I->click(['xpath' => "//div[@id='toolbar-featured']//button"]); break; + case "duplicate": + $I->click(['xpath' => "//div[@id='toolbar-copy']//button"]); + break; + case "check-in": + $I->click(['xpath' => "//div[@id='toolbar-checkin']//button"]); + break; } } @@ -388,8 +397,8 @@ public function displaySearchTools() $I->comment("Search tools button does not exist on this page, skipping"); return; } -} - try { + + try { $I->dontSeeElement(['class' => 'js-stools-container-filters']); } catch (Exception $e) { $I->comment("Search tools already visible on the page, skipping"); @@ -398,4 +407,46 @@ public function displaySearchTools() $I->click('Search Tools'); } + + /** + * Assure the item is unpublished. + * + * @param string $item The item name + * @param string $pageTitle The page title + * + * @since __DEPLOY_VERSION__ + * + * @return void + */ + public function seeItemInUnpublished($item, $pageTitle) + { + $I = $this; + + $I->click('Search Tools'); + $I->wait(1); + $I->selectOptionInChosenById(static::$filterPublished, 'Unpublished'); + $I->waitForPageTitle($pageTitle); + $I->see($item, static::$seeName); + } + + /** + * Assure the item is Published. + * + * @param string $item The item name + * @param string $pageTitle The page title + * + * @since __DEPLOY_VERSION__ + * + * @return void + */ + public function seeItemInPublished($item, $pageTitle) + { + $I = $this; + + $I->click('Search Tools'); + $I->wait(1); + $I->selectOptionInChosenById(static::$filterPublished, 'Published'); + $I->waitForPageTitle($pageTitle); + $I->see($item, static::$seeName); + } } diff --git a/tests/codeception/_support/Page/Acceptance/Administrator/ModuleEditPage.php b/tests/codeception/_support/Page/Acceptance/Administrator/ModuleEditPage.php new file mode 100644 index 0000000000..f3c3c0c776 --- /dev/null +++ b/tests/codeception/_support/Page/Acceptance/Administrator/ModuleEditPage.php @@ -0,0 +1,94 @@ + 'jform_title']; + + /** + * Page object for content body editor field for module edit. + * + * @var array + * @since __DEPLOY_VERSION__ + */ + public static $contentField = ['id' => 'jform_content']; + + /** + * Page object for the toggle button. + * + * @var string + * @since __DEPLOY_VERSION__ + * @todo move this into admin page + */ + public static $toggleEditor = "Toggle editor"; + + /** + * Method is a page object to fill module title. + * + * @param string $title Module title + * + * @since __DEPLOY_VERSION__ + * + * @return void + */ + public function fillModuleTitle($title) + { + $I = $this; + + $I->fillField(self::$titleField, $title); + } + + /** + * Method is a page object to fill module content. + * + * @param string $content Module content + * + * @since __DEPLOY_VERSION__ + * + * @return void + */ + public function fillModuleContent($content) + { + $I = $this; + $I->click(self::$toggleEditor); + $I->fillField(self::$contentField, $content); + } + +} diff --git a/tests/codeception/_support/Page/Acceptance/Administrator/ModuleManagerPage.php b/tests/codeception/_support/Page/Acceptance/Administrator/ModuleManagerPage.php new file mode 100644 index 0000000000..4295907c5a --- /dev/null +++ b/tests/codeception/_support/Page/Acceptance/Administrator/ModuleManagerPage.php @@ -0,0 +1,53 @@ + "//table[@id='moduleList']//tr[1]/td[4]"]; + + /** + * Page title of the module manager page. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + public static $pageTitleText = "Modules (Site)"; + + /** + * Locator for status filter under search tool + * + * @var array + * @since __DEPLOY_VERSION__ + */ + public static $filterPublished = 'filter_state'; + +} diff --git a/tests/codeception/_support/Step/Acceptance/Administrator/Admin.php b/tests/codeception/_support/Step/Acceptance/Administrator/Admin.php index 24b3bdec86..13b03bfd5c 100644 --- a/tests/codeception/_support/Step/Acceptance/Administrator/Admin.php +++ b/tests/codeception/_support/Step/Acceptance/Administrator/Admin.php @@ -18,6 +18,8 @@ use Page\Acceptance\Administrator\UserAclPage; use Page\Acceptance\Administrator\UserGroupPage; use Page\Acceptance\Administrator\UserManagerPage; +use Page\Acceptance\Administrator\ModuleManagerPage; +use Page\Acceptance\Administrator\ModuleEditPage; /** * Acceptance Step object class for admin steps. @@ -111,6 +113,8 @@ public function __construct(Scenario $scenario) $this->userAclPage = new UserAclPage($scenario); $this->menuManagerPage = new MenuManagerPage($scenario); $this->extensionManagerPage = new ExtensionManagerPage($scenario); + $this->moduleManagerPage = new ModuleManagerPage($scenario); + $this->moduleEditPage = new ModuleEditPage($scenario); } /** diff --git a/tests/codeception/_support/Step/Acceptance/Administrator/Module.php b/tests/codeception/_support/Step/Acceptance/Administrator/Module.php new file mode 100644 index 0000000000..14d6cf5bd0 --- /dev/null +++ b/tests/codeception/_support/Step/Acceptance/Administrator/Module.php @@ -0,0 +1,315 @@ +adminPage->clickToolbarButton('New'); + // @todo create a page object for module type selection page + + $I->scrollTo(['xpath' => "//a/strong[text()='Custom']"],0,-150); + $I->click("Custom"); + $I->wait(1); + // fill the fields + $I->moduleEditPage->fillModuleTitle(self::$moduleTitle); + $I->scrollTo(['css' => 'div.toggle-editor']); + $I->moduleEditPage->fillModuleContent("Content of my custom Module"); + } + + /** + * @When I Save the module + */ + public function iSaveTheModule() + { + $I = $this; + + $I->adminPage->clickToolbarButton('Save & Close'); + } + + /** + * @Then I should see the success message + */ + public function iShouldSeeTheSuccessMessage() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "Module successfully saved"); + } + + /** + * @Then I should see the custom module is created + */ + public function iShouldSeeTheCustomModuleIsCreated() + { + $I = $this; + + $I->moduleManagerPage->seeItemIsCreated(self::$moduleTitle); + } + + /** + * @When I am in the module manager + */ + public function iAmInTheModuleManager() + { + $I = $this; + + $I->amOnPage(ModuleManagerPage::$url); + } + + /** + * @Given I have an module to edit + */ + public function iHaveAnModuleToEdit() + { + $I = $this; + + $I->adminPage->clickToolbarButton('New'); + $I->wait(1); + // @todo create a page object for module type selection page + $I->scrollTo(['xpath' => "//a/strong[text()='Custom']"],0,-150); + $I->click("Custom"); + $I->wait(1); + // fill the fields + $I->moduleEditPage->fillModuleTitle(self::$moduleTitle); + $I->scrollTo(['css' => 'div.toggle-editor']); + $I->moduleEditPage->fillModuleContent("Content of my custom Module"); + $I->adminPage->clickToolbarButton('Save & Close'); + } + + /** + * @Given I edit the module title + */ + public function iEditTheModuleTitle() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->adminPage->clickToolbarButton('edit'); + $I->fillField(ModuleEditPage::$titleField, self::$moduleTitle_Edit); + } + + /** + * @Then I should see the module is saved with the new title + */ + public function iShouldSeeTheModuleIsSavedWithTheNewTitle() + { + $I = $this; + + $I->moduleManagerPage->seeItemIsCreated(self::$moduleTitle_Edit); + } + + /** + * @Given I have a custom module + */ + public function iHaveACustomModule() + { + $I = $this; + + $I->moduleManagerPage->seeItemIsCreated(self::$moduleTitle); + } + + /** + * @When I unpublish the custom module + */ + public function iUnpublishTheCustomModule() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->adminPage->clickToolbarButton('unpublish'); + } + + /** + * @Then I should see the custom module is now unpublished + */ + public function iShouldSeeTheCustomModuleIsNowUnpublished() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully unpublished"); + $I->moduleManagerPage->seeItemInUnpublished(self::$moduleTitle, ModuleManagerPage::$pageTitleText); + } + + /** + * @When I publish the module + */ + public function iPublishTheModule() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->wait(1); + $I->adminPage->clickToolbarButton('publish'); + } + + /** + * @Then I should see the custom module is now published + */ + public function iShouldSeeTheCustomModuleIsNowPublished() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully published"); + $I->moduleManagerPage->seeItemInPublished(self::$moduleTitle, ModuleManagerPage::$pageTitleText); + } + + /** + * @When I duplicate the custom module + */ + public function iDuplicateTheCustomModule() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->adminPage->clickToolbarButton('duplicate'); + } + + /** + * @Then I should see the duplicated module + */ + public function iShouldSeeTheDuplicatedModule() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully duplicated"); + $I->moduleManagerPage->seeItemInUnpublished(self::$moduleTitle . " (2)", ModuleManagerPage::$pageTitleText); + } + + /** + * @When I trash the module + */ + public function iTrashTheModule() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->adminPage->clickToolbarButton('trash'); + } + + /** + * @Then I should see the module is now trashed + */ + public function iShouldSeeTheModuleIsNowTrashed() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully trashed"); + $I->moduleManagerPage->seeItemInTrash(self::$moduleTitle, ModuleManagerPage::$pageTitleText); + } + + /** + * @When I empty trash + */ + public function iEmptyTrash() + { + $I = $this; + + $I->moduleManagerPage->seeItemInTrash(self::$moduleTitle, ModuleManagerPage::$pageTitleText); + $I->moduleManagerPage->checkAllResults(); + $I->moduleManagerPage->clickToolbarButton('empty trash'); + $I->acceptPopup(); + } + + /** + * @Then I should see an empty trash + */ + public function iShouldSeeAnEmptyTrash() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully deleted."); + $I->moduleManagerPage->see("There are no modules matching your query", ['css'=>'div.alert']); + + } + + /** + * @Given the custom module is checked out + */ + public function theCustomModuleIsCheckedOut() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->adminPage->clickToolbarButton('edit'); + $I->iAmInTheModuleManager(); + + + } + + /** + * @When I check in the custom module + */ + public function iCheckInTheCustomModule() + { + $I = $this; + + $I->moduleManagerPage->haveItemUsingSearch(self::$moduleTitle); + $I->moduleManagerPage->clickToolbarButton('check-in'); + } + + /** + * @Then I should see the custom module is now checked in + */ + public function iShouldSeeTheCustomModuleIsNowCheckedIn() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully checked in."); + $I->dontSeeElement(['class'=>'icon-checkedout']); + } + + /** + * @Given I have a trashed module + */ + public function iHaveATrashedModule() + { + $I = $this; + + $I->moduleManagerPage->seeItemInTrash(self::$moduleTitle, ModuleManagerPage::$pageTitleText); + } + + /** + * @Then I should see the trashed module is now published + */ + public function iShouldSeeTheTrashedModuleIsNowPublished() + { + $I = $this; + + $I->moduleManagerPage->seeSystemMessage(ModuleManagerPage::$pageTitleText, "successfully published."); + $I->wait(1); + $I->moduleManagerPage->selectOptionInChosenById(ModuleManagerPage::$filterPublished, 'Published'); + $I->moduleManagerPage->waitForPageTitle(ModuleManagerPage::$pageTitleText); + $I->moduleManagerPage->see(self::$moduleTitle, ModuleManagerPage::$seeName); + } + +} diff --git a/tests/codeception/acceptance/modules.feature b/tests/codeception/acceptance/modules.feature new file mode 100644 index 0000000000..2388688a56 --- /dev/null +++ b/tests/codeception/acceptance/modules.feature @@ -0,0 +1,59 @@ +Feature: modules + In order to manage modules in the web + As an owner + I need to create edit publish unpublish duplicate checkin trash restore module + + Background: + When I Login into Joomla administrator with username "admin" and password "admin" + And I see the administrator dashboard + And I am in the module manager + + Scenario: Create a new module + When I create new custom module + And I Save the module + Then I should see the success message + And I should see the custom module is created + + Scenario: Edit module + Given I have an module to edit + And I edit the module title + And I Save the module + Then I should see the module is saved with the new title + + Scenario: Unpublish a module + Given I have a custom module + When I unpublish the custom module + Then I should see the custom module is now unpublished + + Scenario: Publish a module + Given I have a custom module + When I publish the module + Then I should see the custom module is now published + + Scenario: Duplicate a module + Given I have a custom module + When I duplicate the custom module + Then I should see the duplicated module + + Scenario: Check-in a module + Given I have a custom module + And the custom module is checked out + When I check in the custom module + Then I should see the custom module is now checked in + + Scenario: Trash a module + Given I have a custom module + When I trash the module + Then I should see the module is now trashed + + Scenario: Publish a trashed module + Given I have a trashed module + When I publish the module + Then I should see the trashed module is now published + + Scenario: Empty Trash + Given I create new custom module + And I Save the module + When I trash the module + And I empty trash + Then I should see an empty trash From a3ea45dda06ad320d3046307f83fc2d535548100 Mon Sep 17 00:00:00 2001 From: David Neukirchen Date: Sun, 11 Dec 2016 16:21:22 +0100 Subject: [PATCH 2/7] Fix typo (#109) * Fix typo * Code style * Add new line before try catch --- .../Acceptance/Administrator/AdminPage.php | 90 ++++++++++--------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php b/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php index f67b37c480..6e8d1a31cc 100644 --- a/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php +++ b/tests/codeception/_support/Page/Acceptance/Administrator/AdminPage.php @@ -85,7 +85,7 @@ class AdminPage extends \AcceptanceTester /** * Method to search using given keyword * - * @param string $keyword The keyword to search + * @param string $keyword The keyword to search * * @since __DEPLOY_VERSION__ * @@ -103,7 +103,7 @@ public function search($keyword) /** * Method to search user with username * - * @param string $keyword The username of user + * @param string $keyword The username of user * * @since __DEPLOY_VERSION__ * @@ -122,8 +122,8 @@ public function haveItemUsingSearch($keyword) /** * Method is used to see system message after waiting for page title. * - * @param string $title The webpage title - * @param string $message The unpublish successful message + * @param string $title The webpage title + * @param string $message The unpublish successful message * * @since __DEPLOY_VERSION__ * @@ -140,7 +140,7 @@ public function seeSystemMessage($title, $message) /** * Method is to Wait for page title until default timeout. * - * @param string $title Page Title text + * @param string $title Page Title text * * @since __DEPLOY_VERSION__ * @@ -155,7 +155,7 @@ public function waitForPageTitle($title) /** * Function to select Toolbar buttons in Joomla! Admin Toolbar Panel * - * @param string $button The full name of the button + * @param string $button The full name of the button * * @since __DEPLOY_VERSION__ * @@ -251,8 +251,8 @@ public function checkAllResults() /** * Selects an option in a Chosen Selector based on its id * - * @param string $selectId The id of the element + * @param string $option The text in the