From 604181ff3133c305574e46cec2b174a1aca5e9ac Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 1 Jun 2016 09:32:05 +0100 Subject: [PATCH 1/8] [Behat] Separate CommonActions into meaningfull Contexts --- Features/Context/ContentActions.php | 43 +- Features/Context/Fields.php | 76 +-- Features/Context/PlatformUI.php | 78 +++- Features/Context/Role.php | 41 +- .../Context/SubContext/Authentication.php | 92 +++- .../Context/SubContext/BrowserContext.php | 160 +++++++ Features/Context/SubContext/CommonActions.php | 431 ------------------ .../Context/SubContext/ContentEditContext.php | 113 +++++ .../Context/SubContext/DashboardContext.php | 201 ++++++++ Features/Context/Users.php | 58 ++- behat_suites.yml | 34 +- 11 files changed, 813 insertions(+), 514 deletions(-) create mode 100644 Features/Context/SubContext/BrowserContext.php delete mode 100644 Features/Context/SubContext/CommonActions.php create mode 100644 Features/Context/SubContext/ContentEditContext.php create mode 100644 Features/Context/SubContext/DashboardContext.php diff --git a/Features/Context/ContentActions.php b/Features/Context/ContentActions.php index 584b7827f..a389d4ea8 100644 --- a/Features/Context/ContentActions.php +++ b/Features/Context/ContentActions.php @@ -9,8 +9,38 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use PHPUnit_Framework_Assert as Assertion; + class ContentActions extends PlatformUI { + /** + */ + private $contentEditContext; + private $dashboardContext; + + /** + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->contentEditContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext' + ); + $this->dashboardContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' + ); + } + + /** + */ + private function iSeeNotification($message) + { + $this->sleep(); + $result = $this->getElementByText($message, '.ez-notification-text'); + Assertion::AssertNotNull($result); + } + /** * @Then I am notified that :name has been copied under :destiny */ @@ -25,10 +55,11 @@ public function iSeeCopiedNotification($name, $destiny) */ public function moveInto($name, $destiny) { - $this->onFullView($name); - $this->clickActionBar('Move'); - $this->selectFromUniversalDiscovery("eZ Platform/$destiny"); - $this->confirmSelection(); + $this->contentEditContext->onFullView($name); + $this->waitWhileLoading(); + $this->dashboardContext->clickActionBar('Move'); + $this->dashboardContext->selectFromUniversalDiscovery("eZ Platform/$destiny"); + $this->dashboardContext->confirmSelection(); $destinyName = explode('/', $destiny); $destinyName = end($destinyName); $this->iSeeMovedNotification($name, $destinyName); @@ -58,9 +89,9 @@ public function iSeeMovedNotification($name, $destiny) */ public function removeContent($name) { - $this->onFullView($name); + $this->contentEditContext->onFullView($name); $this->waitWhileLoading(); - $this->clickActionBar('Send to Trash'); + $this->dashboardContext->clickActionBar('Send to Trash'); } /** diff --git a/Features/Context/Fields.php b/Features/Context/Fields.php index 6a00caf20..b0fcf53cd 100644 --- a/Features/Context/Fields.php +++ b/Features/Context/Fields.php @@ -9,14 +9,33 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; -use EzSystems\BehatBundle\ObjectManager\FieldType; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Mink\WebAssert; +use EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext as FieldType; class Fields extends PlatformUI { const NOTIFICATION_CONTENT_PUBLISHED = 'Content has been published'; const NOTIFICATION_PUBLISH_ERROR = 'An error occured while publishing the draft'; + /** + */ + private $fieldtypeContext; + private $dashboardContext; + + /** + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->fieldtypeContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext' + ); + $this->dashboardContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' + ); + } + protected function getFieldIdentCss($identifier, $contentId = '') { return "ez-field-$contentId-$identifier"; @@ -49,12 +68,11 @@ protected function getEditLabelCss($type, $fieldIdentifier = '', $contentId = '' protected function getThisFieldIdent() { - $fieldManager = $this->getFieldTypeManager(); - $identifier = $fieldManager->getThisFieldTypeIdentifier(); + $identifier = $this->fieldtypeContext->getThisFieldTypeIdentifier(); // check if we are editing a field for draft or published content - if ($fieldManager->getFieldContentState() == FieldType::CONTENT_PUBLISHED) { - $contentId = $fieldManager->getThisContentId(); + if ($this->fieldtypeContext->getFieldContentState() == FieldType::CONTENT_PUBLISHED) { + $contentId = $this->fieldtypeContext->getThisContentId(); } else { $contentId = ''; } @@ -67,14 +85,13 @@ protected function getThisFieldIdent() */ public function createAContentOfThisType() { - $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED); - $name = $fieldManager->getThisContentTypeName(); + $this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED); + $name = $this->fieldtypeContext->getThisContentTypeName(); - $this->clickNavigationZone('Content'); - $this->clickNavigationItem('Content structure'); - $this->clickActionBar('Create'); - $this->clickContentType($name); + $this->dashboardContext->clickNavigationZone('Content'); + $this->dashboardContext->clickNavigationItem('Content structure'); + $this->dashboardContext->clickActionBar('Create'); + $this->dashboardContext->clickContentType($name); $this->platformStatus = self::WAITING_FOR_PUBLISHING; } @@ -83,14 +100,13 @@ public function createAContentOfThisType() */ public function editThisContent() { - $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); - $name = $fieldManager->getThisContentName(); + $this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_PUBLISHED); + $name = $this->fieldtypeContext->getThisContentName(); - $this->clickNavigationZone('Content'); - $this->clickNavigationItem('Content structure'); - $this->clickOnTreePath($name); - $this->clickActionBar('Edit'); + $this->dashboardContext->clickNavigationZone('Content'); + $this->dashboardContext->clickNavigationItem('Content structure'); + $this->dashboardContext->clickOnTreePath($name); + $this->dashboardContext->clickActionBar('Edit'); $this->platformStatus = self::WAITING_FOR_PUBLISHING; // assert $this->iSeeContentEditView(); @@ -147,7 +163,7 @@ public function uncheckFieldValue() public function publishContent() { if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { - $this->clickEditActionBar('Publish'); + $this->dashboardContext->clickEditActionBar('Publish'); } else { throw new \Exception('Cannot publish content, application in wrong state'); } @@ -161,9 +177,8 @@ public function publishContent() public function seeRequiredFieldtOfType($label) { if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { - $fieldManager = $this->getFieldTypeManager(); // $type = ... - //$name = $fieldManager->getThisFieldTypeName(); + //$name = $fieldtypeContext->getThisFieldTypeName(); $verification = new WebAssert($this->getSession()); //$verification->elementTextContains('css', $this->getEditLabelCss($type, $name), $label . '*');. @@ -186,7 +201,7 @@ public function iSeeContentEditView() */ public function contentIsPublished() { - $this->iSeeNotification(self::NOTIFICATION_CONTENT_PUBLISHED); + $this->dashboardContext->iSeeNotification(self::NOTIFICATION_CONTENT_PUBLISHED); } /** @@ -205,11 +220,11 @@ public function failsWithMessage($message) public function seeFieldtOfType($type, $label = null) { if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { - $this->clickEditActionBar('Publish'); + $this->dashboardContext->clickEditActionBar('Publish'); } $verification = new WebAssert($this->getSession()); // for view we need the internal field identifier... - $internalName = $this->getFieldTypeManager()->getFieldTypeInternalIdentifier($type); + $internalName = $this->fieldtypeContext->getFieldTypeInternalIdentifier($type); $verification->elementExists('css', ".ez-fieldview-$internalName .ez-fieldview-value-content"); if ($label != null) { @@ -222,13 +237,12 @@ public function seeFieldtOfType($type, $label = null) */ public function viewThisContent() { - $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); - $name = $fieldManager->getThisContentName(); + $this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_PUBLISHED); + $name = $this->fieldtypeContext->getThisContentName(); - $this->clickNavigationZone('Content'); - $this->clickNavigationItem('Content structure'); - $this->clickOnTreePath($name); + $this->dashboardContext->clickNavigationZone('Content'); + $this->dashboardContext->clickNavigationItem('Content structure'); + $this->dashboardContext->clickOnTreePath($name); } /** diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index 91c68d106..b9a7584c3 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -9,9 +9,9 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; -use EzSystems\BehatBundle\Context\Browser\Context; +use Behat\MinkExtension\Context\RawMinkContext; -class PlatformUI extends Context +class PlatformUI extends RawMinkContext { /** * Default Platform URI. @@ -44,9 +44,6 @@ class PlatformUI extends Context const NOT_WAITING = 0; const WAITING_FOR_PUBLISHING = 1; - use SubContext\Authentication; - use SubContext\CommonActions; - /** * PlatformUI relative URL path. * @@ -74,15 +71,15 @@ class PlatformUI extends Context protected $password = 'publish'; /** - * Stores the status of the platform. - * @var int + * Mapping of pages URL's. */ - protected $platformStatus = self::NOT_WAITING; + protected $pageIdentifierMap = array(); /** - * Mapping of the new paths of contents after being moved. + * Stores the status of the platform. + * @var int */ - protected $newPathsMap = array(); + protected $platformStatus = self::NOT_WAITING; /** * Initialize class. @@ -91,9 +88,6 @@ class PlatformUI extends Context */ public function __construct($uri = self::PLATFORM_URI, $user = null, $password = null) { - parent::__construct(); - $this->pageIdentifierMap['roles'] = '/ez#/admin/pjax%2Frole'; - $this->pageIdentifierMap['users'] = '/ez#/view/%2Fapi%2Fezp%2Fv2%2Fcontent%2Flocations%2F1%2F5/eng-GB'; $this->platformUiUri = $uri; if ($user != null) { $this->user = $user; @@ -118,7 +112,6 @@ public function afterScenario() { $this->closeConfirmBox(); $this->closeEditView(); - $this->iLogout(); } /** @@ -130,11 +123,41 @@ public function beforeStep() $this->waitWhileLoading(); } - /** - * @AfterStep - */ - public function afterStep() + public function fillFieldWithValue($field, $value = '') { + $fieldNode = $this->spin( + function () use ($field) { + $fieldNode = $this->getSession()->getPage()->findField($field); + if ($fieldNode == null) { + throw new \Exception('Field not found'); + } + + return $fieldNode; + } + ); + + $this->spin( + function () use ($fieldNode, $field, $value) { + // make sure any autofocus elements don't mis-behave when setting value + $fieldNode->blur(); + usleep(10 * 1000); + $fieldNode->focus(); + usleep(10 * 1000); + + // setting value on pre-filled inputs can cause issues, clearing before + $fieldNode->setValue(''); + $fieldNode->setValue($value); + + // verication that the field was really filled in correctly + $this->sleep(); + $check = $this->getSession()->getPage()->findField($field)->getValue(); + if ($check != $value) { + throw new \Exception('Failed to set the field value: ' . $check); + } + + return true; + } + ); } /** @@ -284,7 +307,7 @@ function () use ($selector, $baseElement, $checkVisibility) { * @param string $selector CSS selector of the element * @param string $textSelector Extra CSS selector for text of the element * @param string $baseElement Element in which the search is based - * @param int $iteration Iteration number, used to control number of executions + * * @return array */ protected function getElementByText($text, $selector, $textSelector = null, $baseElement = null) @@ -394,6 +417,23 @@ protected function closeConfirmBox() } } + public function iSeeTitle($title) + { + $page = $this->getSession()->getPage(); + $this->spin( + function () use ($title, $page) { + $titleElements = $page->findAll('css', 'h1, h2, h3'); + foreach ($titleElements as $titleElement) { + $elementText = $titleElement->getText(); + if ($elementText == $title) { + return $titleElement; + } + } + throw new \Exception("Title '$title' not found"); + } + ); + } + /** * Close the Edit view, if it is open. */ diff --git a/Features/Context/Role.php b/Features/Context/Role.php index be9126de8..af316de5a 100644 --- a/Features/Context/Role.php +++ b/Features/Context/Role.php @@ -10,16 +10,43 @@ namespace EzSystems\PlatformUIBundle\Features\Context; use Behat\Gherkin\Node\TableNode; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; class Role extends PlatformUI { /** - * @Given I am on the RolesUI + */ + private $dashboardContext; + + /** + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->dashboardContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' + ); + } + + /** + * @Given I am on the Roles page */ public function onRolesPage() { - $this->clickNavigationZone('Admin Panel'); - $this->clickNavigationItem('Roles'); + $this->getSession()->visit( + $this->locatePath( + self::PLATFORM_URI . '#/admin/pjax%2Frole' + ) + ); + } + + /** + * @Given I am on the RolesUI + */ + public function onRolesUI() + { + $this->dashboardContext->clickNavigationZone('Admin Panel'); + $this->dashboardContext->clickNavigationItem('Roles'); } /** @@ -70,7 +97,7 @@ public function iEditRole($name) */ public function roleDetailsView($role) { - $this->onRolesPage(); + $this->onRolesUI(); $this->clickElementByText($role, '.ez-role-name a'); } @@ -112,7 +139,7 @@ public function noAssigmentsForThisRole() */ public function roleWasPublished() { - $this->iSeeNotification('The role was published.'); + $this->dashboardContext->iSeeNotification('The role was published.'); } /** @@ -132,9 +159,9 @@ public function roleWasNotPublished($name) */ public function nameAlreadyExists($name) { - $this->iSeeNotification('Form did not validate. Please review errors below.'); + $this->dashboardContext->iSeeNotification('Form did not validate. Please review errors below.'); $element = $this->getElementByText( - 'Identifier "' . $name . '" already exists. Role identifier must be unique.', + 'Identifier "' . $name . '" already exists. Role identifier must be unique.', 'li' ); if (!$element) { diff --git a/Features/Context/SubContext/Authentication.php b/Features/Context/SubContext/Authentication.php index bbe5e7e95..4d85852ae 100644 --- a/Features/Context/SubContext/Authentication.php +++ b/Features/Context/SubContext/Authentication.php @@ -9,8 +9,19 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context\SubContext; -trait Authentication +use EzSystems\PlatformUIBundle\Features\Context\PlatformUI; +use EzSystems\PlatformBehatBundle\Context\RepositoryContext; +use eZ\Publish\API\Repository\Repository; +use eZ\Publish\API\Repository\UserService; +use eZ\Publish\API\Repository\RoleService; + +class Authentication extends PlatformUI { + use RepositoryContext; + + const DEFAULT_LANGUAGE = 'eng-GB'; + const USERGROUP_ROOT_CONTENT_ID = 4; + /** * Control variable to check if logged in. * @@ -18,12 +29,85 @@ trait Authentication */ protected $shouldBeLoggedIn; + /** + * @var \eZ\Publish\API\Repository\UserService + */ + protected $userService; + + /** + * @var \eZ\Publish\API\Repository\RoleService + */ + protected $roleService; + + /** + * @injectService $repository @ezpublish.api.repository + * @injectService $userService @ezpublish.api.service.user + * @injectService $roleService @ezpublish.api.service.role + */ + public function __construct(Repository $repository, UserService $userService, RoleService $roleService) + { + $this->setRepository($repository); + $this->userService = $userService; + $this->roleService = $roleService; + } + + /** + * Get credentials for a specific role + * + * @uses \EzSystems\BehatBundle\Context\Object\User + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * + * @param string $role Role intended for testing + * + * @return array Associative with 'login' and 'password' + */ + protected function getCredentialsFor($roleIdentifier) + { + $role = $this->roleService->loadRoleByIdentifier($roleIdentifier); + + // create a new user, uses 'User' trait + $username = 'User' . uniqid(); + $password = $username; + $email = "${username}@ez.no"; + $userCreateStruct = $this->userService->newUserCreateStruct( + $username, + $email, + $password, + self::DEFAULT_LANGUAGE + ); + $userCreateStruct->setField('first_name', $username); + $userCreateStruct->setField('last_name', $username); + + $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID); + $user = $this->userService->createUser($userCreateStruct, array($parentGroup)); + + // Assign role to created user (without limitation) + $this->roleService->assignRoleToUser($role, $user); + + return array( + 'login' => $username, + 'password' => $password, + ); + } + + /** + * @AfterScenario + */ + public function afterScenarioLogout() + { + $this->iLogout(); + } + /** * @Given I go to homepage */ public function goToPlatformUi($url = '') { - $this->visit($this->platformUiUri . $url); + $this->getSession()->visit( + $this->locatePath( + self::PLATFORM_URI . $url + ) + ); } /** @@ -35,7 +119,7 @@ public function goToPlatformUiAndLogIn($username, $password) $this->waitWhileLoading(); $this->fillFieldWithValue('username', $username); $this->fillFieldWithValue('password', $password); - $this->iClickAtButton('Login'); + $this->clickElementByText('Login', 'button'); $this->iShouldBeLoggedIn(); } @@ -68,7 +152,7 @@ public function iLogout() $this->waitWhileLoading(); $el->click(); $this->waitWhileLoading(); - $this->iClickAtLink('Logout'); + $this->clickElementByText('Logout', 'a'); } /** diff --git a/Features/Context/SubContext/BrowserContext.php b/Features/Context/SubContext/BrowserContext.php new file mode 100644 index 000000000..e4b844f32 --- /dev/null +++ b/Features/Context/SubContext/BrowserContext.php @@ -0,0 +1,160 @@ +xpath = new Xpath($this->getSession()); + } + + /** + * Getter for Xpath + * + * @return \EzSystems\BehatBundle\Helper\Xpath + */ + public function getXpath() + { + return $this->xpath; + } + + /** + * @Given I clicked on/at (the) :link link + * @When I click on/at (the) :link link + * + * Click a link with text ':link' + */ + public function clickLink($link) + { + $this->clickElementByText($link, 'a'); + } + + /** + * @Given I clicked on/at (the) :button button + * @When I click on/at (the) :button button + * + * Clicks the button identified by ':button' + */ + public function iClickAtButton($button) + { + $this->clickElementByText($button, 'button'); + } + + /** + * @When I fill in :field with :value + * @When I set :field as empty + * + * Spin function make it possible to retry in case of failure + */ + public function fillFieldWithValue($field, $value = '') + { + $fieldNode = $this->spin( + function () use ($field) { + $fieldNode = $this->getSession()->getPage()->findField($field); + if ($fieldNode == null) { + throw new \Exception('Field not found'); + } + + return $fieldNode; + } + ); + + $this->spin( + function () use ($fieldNode, $field, $value) { + // make sure any autofocus elements don't mis-behave when setting value + $fieldNode->blur(); + usleep(10 * 1000); + $fieldNode->focus(); + usleep(10 * 1000); + + // setting value on pre-filled inputs can cause issues, clearing before + $fieldNode->setValue(''); + $fieldNode->setValue($value); + + // verication that the field was really filled in correctly + $this->sleep(); + $check = $this->getSession()->getPage()->findField($field)->getValue(); + if ($check != $value) { + throw new \Exception('Failed to set the field value: ' . $check); + } + + return true; + } + ); + } + + /** + * @Then I (should) see :title title/topic + */ + public function iSeeTitle($title) + { + $page = $this->getSession()->getPage(); + $this->spin( + function () use ($title, $page) { + $titleElements = $page->findAll('css', 'h1, h2, h3'); + foreach ($titleElements as $titleElement) { + $elementText = $titleElement->getText(); + if ($elementText == $title) { + return $titleElement; + } + } + throw new \Exception("Title '$title' not found"); + } + ); + } + + /** + * @Then I should see a :label input field + */ + public function seeInputField($label) + { + $field = $this->getSession()->getPage()->findField($label); + if (!$field) { + throw new \Exception("Field '$label' not found"); + } + } + + /** + * @Given I checked :label checkbox + * @When I check :label checkbox + * + * Toggles the value for the checkbox with name ':label' + */ + public function checkOption($option) + { + $fieldElements = $this->getXpath()->findFields($option); + EzAssertion::assertElementFound($option, $fieldElements, null, 'checkbox'); + + // this is needed for the cases where are checkboxes and radio's + // side by side, for main option the radio and the extra being the + // checkboxes values + if (strtolower($fieldElements[0]->getAttribute('type')) !== 'checkbox') { + $value = $fieldElements[0]->getAttribute('value'); + $fieldElements = $this->getXpath()->findXpath("//input[@type='checkbox' and @value='$value']"); + EzAssertion::assertElementFound($value, $fieldElements, null, 'checkbox'); + } + + $fieldElements[0]->check(); + } +} diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php deleted file mode 100644 index 0bd5ddd71..000000000 --- a/Features/Context/SubContext/CommonActions.php +++ /dev/null @@ -1,431 +0,0 @@ -clickElementByText($link, 'a'); - } - - /** - * @Given I clicked on/at (the) :button button - * @When I click on/at (the) :button button - * - * Clicks the button identified by ':button' - */ - public function iClickAtButton($button) - { - $this->clickElementByText($button, 'button'); - } - - /** - * @When I fill in :field with :value - * @When I set :field as empty - * - * Spin function make it possible to retry in case of failure - */ - public function fillFieldWithValue($field, $value = '') - { - $fieldNode = $this->spin( - function () use ($field) { - $fieldNode = $this->getSession()->getPage()->findField($field); - if ($fieldNode == null) { - throw new \Exception('Field not found'); - } - - return $fieldNode; - } - ); - - $this->spin( - function () use ($fieldNode, $field, $value) { - // make sure any autofocus elements don't mis-behave when setting value - $fieldNode->blur(); - usleep(10 * 1000); - $fieldNode->focus(); - usleep(10 * 1000); - - // setting value on pre-filled inputs can cause issues, clearing before - $fieldNode->setValue(''); - $fieldNode->setValue($value); - - // verication that the field was really filled in correctly - $this->sleep(); - $check = $this->getSession()->getPage()->findField($field)->getValue(); - if ($check != $value) { - throw new \Exception('Failed to set the field value: ' . $check); - } - - return true; - } - ); - } - - /** - * @Then I (should) see :title title/topic - */ - public function iSeeTitle($title) - { - $page = $this->getSession()->getPage(); - $this->spin( - function () use ($title, $page) { - $titleElements = $page->findAll('css', 'h1, h2, h3'); - foreach ($titleElements as $titleElement) { - $elementText = $titleElement->getText(); - if ($elementText == $title) { - return $titleElement; - } - } - throw new \Exception("Title '$title' not found"); - } - ); - } - - /** - * @Then I should see a :label input field - */ - public function seeInputField($label) - { - $field = $this->getSession()->getPage()->findField($label); - if (!$field) { - throw new \Exception("Field '$label' not found"); - } - } - - /** - * @Given I checked :label checkbox - * @When I check :label checkbox - * - * Toggles the value for the checkbox with name ':label' - */ - public function checkOption($option) - { - $fieldElements = $this->getXpath()->findFields($option); - EzAssertion::assertElementFound($option, $fieldElements, null, 'checkbox'); - - // this is needed for the cases where are checkboxes and radio's - // side by side, for main option the radio and the extra being the - // checkboxes values - if (strtolower($fieldElements[0]->getAttribute('type')) !== 'checkbox') { - $value = $fieldElements[0]->getAttribute('value'); - $fieldElements = $this->getXpath()->findXpath("//input[@type='checkbox' and @value='$value']"); - EzAssertion::assertElementFound($value, $fieldElements, null, 'checkbox'); - } - - $fieldElements[0]->check(); - } - - /** - * @Given I click (on) the logo - * Clicks on the PlatformUI logo - */ - public function clickLogo() - { - $page = $this->getSession()->getPage(); - $selector = '.ez-logo a'; - $page->find('css', $selector)->click(); - } - - /** - * @Given I click (on) the tab :tab - * Clicks on a PlatformUI tab - * - * @param string $tab Text of the element to click - */ - public function clickTab($tab) - { - $this->clickElementByText($tab, '.ez-tabs-label a[href]'); - } - - /** - * @Given I click (on) the navigation zone :zone - * Click on a PlatformUI menu zone - * - * @param string $zone Text of the element to click - */ - public function clickNavigationZone($zone) - { - $this->clickElementByText($zone, '.ez-zone-name'); - $this->waitWhileLoading(); - // Clicking navigation zone triggers load of first item, - // we must wait before interacting with the page (see EZP-25128) - // this method sleeps for a default amount (see EzSystems\PlatformUIBundle\Features\Context\PlaformUI) - $this->sleep(); - } - - /** - * @Given I click on the :button button number :index - * Click on a PlatformUI button - * - * @param string $button Text of the element to click - * @param string $index WHAT IS THIS?! - */ - public function clickButtonWithIndex($button, $index) - { - $this->clickElementByText($button, 'button', $index); - } - - /** - * @Given I click (on) the navigation item :item - * Click on a PlatformUI sub-menu option - * - * @param string $item Text of the element to click - */ - public function clickNavigationItem($item) - { - $this->clickElementByText($item, '.ez-navigation-item'); - $this->waitWhileLoading(); - } - - /** - * @Given I click (on) the discovery bar button :button - * Click on a PlatformUI discovery bar - * - * @param string $button Text of the element to click - */ - public function clickDiscoveryBar($button) - { - $this->clickElementByText($button, '.ez-view-discoverybarview .ez-action', '.action-label'); - $this->waitWhileLoading(); - } - - /** - * @Given I click (on) the action bar button :button - * Click on a PlatformUI action bar - * - * @param string $button Text of the element to click - */ - public function clickActionBar($button) - { - $this->clickElementByText($button, '.ez-actionbar-container .ez-action', '.action-label'); - $this->waitWhileLoading(); - } - - /** - * @Given I click (on) the edit action bar button :button - * Click on a PlatformUI edit action bar - * - * @param string $button Text of the element to click - */ - public function clickEditActionBar($button) - { - $this->clickElementByText($button, '.ez-editactionbar-container .ez-action', '.action-label'); - $this->waitWhileLoading(); - } - - /** - * @Given I click (on) the content tree with path :path - * @Then I see :path in the content tree - * Explores the content tree, expanding it and click on the desired element - * - * @param string $path The content tree path such as 'Content1/Content2/ContentIWantToClick' - */ - public function clickOnTreePath($path) - { - $node = $this->findWithWait('.ez-view-discoverybarview'); - $this->clickDiscoveryBar('Content tree'); - $this->openTreePath($path, $node); - } - - /** - * @Given I click (on) the content type :contentType - * Click on a PlatformUI side menu content type - * - * @param string $contentType Text of the element to click - */ - public function clickContentType($contentType) - { - $this->clickElementByText($contentType, '.ez-contenttypeselector-types .ez-selection-filter-item '); - $this->waitWhileLoading(); - } - - /** - * @Given I create a content of content type :type with: - */ - public function iCreateContentType($type, TableNode $fields) - { - $this->clickNavigationZone('Platform'); - $this->iClickAtLink('Content structure'); - $this->clickActionBar('Create a content'); - $this->clickContentType($type); - foreach ($fields as $fieldArray) { - $keys = array_keys($fieldArray); - for ($i = 0; $i < count($keys); ++$i) { - $this->fillFieldWithValue($keys[$i], $fieldArray[$keys[$i]]); - } - } - } - - /** - * @When I select the :path folder in the Universal Discovery Widget - */ - public function selectFromUniversalDiscovery($path) - { - // wait wihile UDW is hidden... - $this->waitWhileLoading('.is-universaldiscovery-hidden'); - $node = $this->findWithWait('.ez-view-universaldiscoveryview'); - $node = $this->findWithWait('.ez-view-universaldiscoverybrowseview .ez-ud-browse-tree', $node); - $this->openTreePath($path, $node); - } - - /** - * @When I confirm the selection - * Confirm selection in Universal descovery. - */ - public function confirmSelection() - { - $this->clickElementByText('Confirm selection', '.ez-universaldiscovery-confirm'); - } - - /** - * @Given I am on :name full view - */ - public function onFullView($name) - { - $path = $this->getBasicContentManager()->getContentPath($name); - $this->goToContentWithPath($path); - } - - /** - * Opens a content in PlatformUi. - */ - private function goToContentWithPath($path) - { - $this->clickNavigationZone('Content'); - $this->clickNavigationItem('Content structure'); - $this->clickOnTreePath($path); - } - - /** - * @Then I am on the :name location view - */ - public function onLocationView($name) - { - // little info about content in platformUI, - // for now only verifies if the title matches - $this->waitWhileLoading(); - $this->iSeeTitle($name); - } - - /** - * @Then I don't see :path in the content tree - * @Then I do not see :path in the content tree - * Explores the content tree, expanding it and click on the desired element. - * - * @param string $path The content tree path such as 'Content1/Content2/ContentIWantToClick' - */ - public function dontSeeTreePath($path) - { - $found = true; - try { - $this->clickOnTreePath($path); - } catch (\Exception $e) { - $found = false; - } - - if ($found) { - throw new \Exception("Tree path '$path' was found"); - } - - return true; - } - - /** - * @Then I see Content :contentName of type :contentType - */ - public function contentExists($contentName, $contentType) - { - $contentId = $this->getLocationId(); - $content = $this->getContentManager()->loadContentWithLocationId($contentId); - $contentInfo = $content->contentInfo; - $contentTypeName = $this->getContentManager()->getContentType($content); - Assertion::assertEquals($contentName, $contentInfo->name, 'Content has wrong name'); - Assertion::assertEquals($contentType, $contentTypeName, 'Content has wrong type'); - } - - /** - * @Then I am notified that :message - */ - public function iSeeNotification($message) - { - $this->sleep(); - $result = $this->getElementByText($message, '.ez-notification-text'); - if (!$result) { - throw new \Exception("The notification with message '$message' was not shown"); - } - } - - /** - * @Then I am not notified that :message - */ - public function iDoNotSeeNotification($message) - { - try { - $this->iSeeNotification($message); - } catch (\Exception $e) { - return; - } - throw new \Exception("Unexpected notification shown with message '$message'"); - } - - /** - * @Then I should see elements with the following names: - */ - public function iSeeElements(TableNode $elements) - { - foreach ($elements as $element) { - $found = false; - $name = array_values($element)[0]; - $found = $this->getElementByText($name, '.ez-selection-filter-item'); - Assertion::assertNotNull($found, "Element: $name not found"); - } - } - - /** - * @Then I should see (an) element :element with (an) file :file - */ - public function iSeeElementFile($element, $file) - { - $url = $this->getFileUrl($element, '.ez-fieldview-label'); - $fileContentActual = file_get_contents($url); - $file = rtrim( - realpath($this->getMinkParameter('files_path')), - DIRECTORY_SEPARATOR - ) . DIRECTORY_SEPARATOR . $file; - $fileContentExpected = file_get_contents($file); - Assertion::assertEquals($fileContentActual, $fileContentExpected); - } - - /** - * @Then /^I should be on the dashboard$/ - */ - public function iShouldBeOnTheDashboard() - { - $this->assertSession()->elementExists('css', '.ez-view-dashboardview'); - } - - /** - * @Given /^I am redirected to a location view$/ - */ - public function iHaveBeenRedirectedToALocationView() - { - $this->assertSession()->elementExists('css', '.ez-mainviews .ez-view-locationviewview'); - } -} diff --git a/Features/Context/SubContext/ContentEditContext.php b/Features/Context/SubContext/ContentEditContext.php new file mode 100644 index 000000000..7df7de34d --- /dev/null +++ b/Features/Context/SubContext/ContentEditContext.php @@ -0,0 +1,113 @@ +basicContentContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext' + ); + $this->dashboardContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' + ); + $this->browserContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext' + ); + } + + /** + * @Given I create a content of content type :type with: + */ + public function iCreateContentType($type, TableNode $fields) + { + $this->dashboardContext->clickNavigationZone('Platform'); + $this->dashboardContext->clickLink('Content structure'); + $this->dashboardContext->clickActionBar('Create a content'); + $this->dashboardContext->clickContentType($type); + foreach ($fields as $fieldArray) { + $keys = array_keys($fieldArray); + for ($i = 0; $i < count($keys); ++$i) { + $this->browserContext->fillFieldWithValue($keys[$i], $fieldArray[$keys[$i]]); + } + } + } + + /** + * @Given I am on :name full view + */ + public function onFullView($name) + { + $path = $this->basicContentContext->getContentPath($name); + $this->goToContentWithPath($path); + } + + /** + * Opens a content in PlatformUi. + */ + private function goToContentWithPath($path) + { + $this->dashboardContext->clickNavigationZone('Content'); + $this->dashboardContext->clickNavigationItem('Content structure'); + $this->waitWhileLoading(); + $this->dashboardContext->clickOnTreePath($path); + } + + /** + * @Then I am on the :name location view + */ + public function onLocationView($name) + { + // little info about content in platformUI, + // for now only verifies if the title matches + $this->waitWhileLoading(); + $this->browserContext->iSeeTitle($name); + } + + /** + * @Then I see Content :contentName of type :contentType + */ + public function contentExists($contentName, $contentType) + { + $contentId = $this->getLocationId(); + $content = $this->getContentManager()->loadContentWithLocationId($contentId); + $contentInfo = $content->contentInfo; + $contentTypeName = $this->getContentManager()->getContentType($content); + Assertion::assertEquals($contentName, $contentInfo->name, 'Content has wrong name'); + Assertion::assertEquals($contentType, $contentTypeName, 'Content has wrong type'); + } + + /** + * @Then I should see elements with the following names: + */ + public function iSeeElements(TableNode $elements) + { + foreach ($elements as $element) { + $found = false; + $name = array_values($element)[0]; + $found = $this->getElementByText($name, '.ez-selection-filter-item'); + Assertion::assertNotNull($found, "Element: $name not found"); + } + } +} diff --git a/Features/Context/SubContext/DashboardContext.php b/Features/Context/SubContext/DashboardContext.php new file mode 100644 index 000000000..a91650b93 --- /dev/null +++ b/Features/Context/SubContext/DashboardContext.php @@ -0,0 +1,201 @@ +getSession()->getPage(); + $selector = '.ez-logo a'; + $page->find('css', $selector)->click(); + } + + /** + * @Given I click (on) the navigation zone :zone + * Click on a PlatformUI menu zone. + * + * @param string $zone Text of the element to click + */ + public function clickNavigationZone($zone) + { + $this->clickElementByText($zone, '.ez-zone-name'); + $this->waitWhileLoading(); + // Clicking navigation zone triggers load of first item, + // we must wait before interacting with the page (see EZP-25128) + // this method sleeps for a default amount (see EzSystems\PlatformUIBundle\Features\Context\PlaformUI) + $this->sleep(); + } + + /** + * @Given I click (on) the navigation item :item + * Click on a PlatformUI sub-menu option. + * + * @param string $item Text of the element to click + */ + public function clickNavigationItem($item) + { + $this->clickElementByText($item, '.ez-navigation-item'); + $this->waitWhileLoading(); + } + + /** + * @Given I click (on) the discovery bar button :button + * Click on a PlatformUI discovery bar. + * + * @param string $button Text of the element to click + */ + public function clickDiscoveryBar($button) + { + $this->clickElementByText($button, '.ez-view-discoverybarview .ez-action', '.action-label'); + $this->waitWhileLoading(); + } + + /** + * @Given I click (on) the action bar button :button + * Click on a PlatformUI action bar. + * + * @param string $button Text of the element to click + */ + public function clickActionBar($button) + { + $this->clickElementByText($button, '.ez-actionbar-container .ez-action', '.action-label'); + $this->waitWhileLoading(); + } + + /** + * @Given I click (on) the edit action bar button :button + * Click on a PlatformUI edit action bar. + * + * @param string $button Text of the element to click + */ + public function clickEditActionBar($button) + { + $this->clickElementByText($button, '.ez-editactionbar-container .ez-action', '.action-label'); + $this->waitWhileLoading(); + } + + /** + * @Given I click (on) the content tree with path :path + * @Then I see :path in the content tree + * Explores the content tree, expanding it and click on the desired element. + * + * @param string $path The content tree path such as 'Content1/Content2/ContentIWantToClick' + */ + public function clickOnTreePath($path) + { + $node = $this->findWithWait('.ez-view-discoverybarview'); + $this->clickDiscoveryBar('Content tree'); + $this->openTreePath($path, $node); + } + + /** + * @Given I click (on) the content type :contentType + * Click on a PlatformUI side menu content type. + * + * @param string $contentType Text of the element to click + */ + public function clickContentType($contentType) + { + $this->clickElementByText($contentType, '.ez-contenttypeselector-types .ez-selection-filter-item '); + $this->waitWhileLoading(); + } + + /** + * @Then I don't see :path in the content tree + * @Then I do not see :path in the content tree + * Explores the content tree, expanding it and click on the desired element. + * + * @param string $path The content tree path such as 'Content1/Content2/ContentIWantToClick' + */ + public function dontSeeTreePath($path) + { + $found = true; + try { + $this->clickOnTreePath($path); + } catch (\Exception $e) { + $found = false; + } + + if ($found) { + throw new \Exception("Tree path '$path' was found"); + } + + return true; + } + + /** + * @When I select the :path folder in the Universal Discovery Widget + */ + public function selectFromUniversalDiscovery($path) + { + // wait wihile UDW is hidden... + $this->waitWhileLoading('.is-universaldiscovery-hidden'); + $node = $this->findWithWait('.ez-view-universaldiscoveryview'); + $node = $this->findWithWait('.ez-view-universaldiscoverybrowseview .ez-ud-browse-tree', $node); + $this->openTreePath($path, $node); + } + + /** + * @When I confirm the selection + * Confirm selection in Universal descovery. + */ + public function confirmSelection() + { + $this->clickElementByText('Confirm selection', '.ez-universaldiscovery-confirm'); + } + + /** + * @Then I am notified that :message + */ + public function iSeeNotification($message) + { + $this->sleep(); + $result = $this->getElementByText($message, '.ez-notification-text'); + if (!$result) { + throw new \Exception("The notification with message '$message' was not shown"); + } + } + + /** + * @Then I am not notified that :message + */ + public function iDoNotSeeNotification($message) + { + try { + $this->iSeeNotification($message); + } catch (\Exception $e) { + return; + } + throw new \Exception("Unexpected notification shown with message '$message'"); + } + + /** + * @Then I should be on the dashboard + */ + public function iShouldBeOnTheDashboard() + { + $this->assertSession()->elementExists('css', '.ez-view-dashboardview'); + } + + /** + * @Given I am redirected to a location view + */ + public function iHaveBeenRedirectedToALocationView() + { + $this->assertSession()->elementExists('css', '.ez-mainviews .ez-view-locationviewview'); + } +} diff --git a/Features/Context/Users.php b/Features/Context/Users.php index e82b0d420..9f6e08605 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -9,28 +9,64 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; class Users extends PlatformUI { + /** + * @var \EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + */ + private $dashboardContext; + + /** + * @var \EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + */ + private $browserContext; + + /** + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $this->dashboardContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' + ); + $this->browserContext = $scope->getEnvironment()->getContext( + 'EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext' + ); + } + + /** + * @Given I am on the Users page + */ + public function onUsersPage() + { + $this->getSession()->visit( + $this->locatePath( + self::PLATFORM_URI . '#/view/%2Fapi%2Fezp%2Fv2%2Fcontent%2Flocations%2F1%2F5/eng-GB' + ) + ); + } + /** * @When I create a new User * @When I fill a new User fields with: */ public function iCreateUser(TableNode $users = null) { - $this->clickActionBar('Create'); + $this->dashboardContext->clickActionBar('Create'); $this->waitWhileLoading('.ez-contenttypes-loading'); - $this->checkOption('Users'); - $this->clickContentType('User'); + $this->browserContext->checkOption('Users'); + $this->dashboardContext->clickContentType('User'); if ($users) { foreach ($users as $user) { - $this->fillFieldWithValue('First name', $user['First name']); - $this->fillFieldWithValue('Last name', $user['Last name']); - $this->fillFieldWithValue('Login', $user['Login']); - $this->fillFieldWithValue('Email', $user['Email']); - $this->fillFieldWithValue('Password', $user['Password']); - $this->fillFieldWithValue('Confirm password', $user['Password']); + $this->browserContext->fillFieldWithValue('First name', $user['First name']); + $this->browserContext->fillFieldWithValue('Last name', $user['Last name']); + $this->browserContext->fillFieldWithValue('Login', $user['Login']); + $this->browserContext->fillFieldWithValue('Email', $user['Email']); + $this->browserContext->fillFieldWithValue('Password', $user['Password']); + $this->browserContext->fillFieldWithValue('Confirm password', $user['Password']); } } } @@ -40,10 +76,10 @@ public function iCreateUser(TableNode $users = null) */ public function editUserUser($username) { - $this->clickOnTreePath("$username $username"); + $this->dashboardContext->clickOnTreePath("$username $username"); $this->sleep(); //safegaurd for application delays $this->waitWhileLoading(); - $this->clickActionBar('Edit'); + $this->dashboardContext->clickActionBar('Edit'); } /** diff --git a/behat_suites.yml b/behat_suites.yml index 7107ff056..e5a248206 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -3,20 +3,44 @@ platformui: # basic platform suite: login, logout, etc standard: paths: [ vendor/ezsystems/platform-ui-bundle/Features/Standard ] - contexts: [ EzSystems\PlatformUIBundle\Features\Context\PlatformUI ] + contexts: + - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication + - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext # content operations: CRUD, navigation, moving contentactions: paths: [ vendor/ezsystems/platform-ui-bundle/Features/ContentActions ] - contexts: [ EzSystems\PlatformUIBundle\Features\Context\ContentActions ] + contexts: + - EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication + - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext + - EzSystems\PlatformUIBundle\Features\Context\ContentActions # role features role: paths: [ vendor/ezsystems/platform-ui-bundle/Features/RoleUI ] - contexts: [ EzSystems\PlatformUIBundle\Features\Context\Role ] + contexts: + - EzSystems\PlatformBehatBundle\Context\Object\RoleContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication + - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + - EzSystems\PlatformUIBundle\Features\Context\Role # fieldtype specific tests - definition, validation, publishing, etc fieldtype_integer: paths: [ vendor/ezsystems/platform-ui-bundle/Features/Stories/FieldTypes/IntegerFieldType.feature ] - contexts: [ EzSystems\PlatformUIBundle\Features\Context\Fields ] + contexts: + - EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication + - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + - EzSystems\PlatformUIBundle\Features\Context\Fields # user features user: paths: [ vendor/ezsystems/platform-ui-bundle/Features/Users/users.feature ] - contexts: [ EzSystems\PlatformUIBundle\Features\Context\Users ] + contexts: + - EzSystems\PlatformBehatBundle\Context\Object\UserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication + - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + - EzSystems\PlatformUIBundle\Features\Context\Users From 39359830f1085d83c986782ab70baae729f9e0e7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 1 Jun 2016 15:39:42 +0100 Subject: [PATCH 2/8] [Behat] Remove not used method from platformUI context --- Features/Context/PlatformUI.php | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index b9a7584c3..218eb793e 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -449,32 +449,10 @@ protected function closeEditView() } } /** - * Attaches a file to a input field on the HTML. * - * @param string $file file name relative to mink definitions - * @param string $selector CSS file upload element selector */ - protected function attachFile($fileName, $selector) { - if ($this->getMinkParameter('files_path')) { - $fullPath = rtrim( - realpath( - $this->getMinkParameter('files_path') - ), - DIRECTORY_SEPARATOR - ) . DIRECTORY_SEPARATOR . $fileName; - - if (is_file($fullPath)) { - $fileInput = 'input[type="file"]' . $selector; - $field = $this->getSession()->getPage()->find('css', $fileInput); - - if (null === $field) { - throw new Exception("File input $selector is not found"); - } - $field->attachFile($fullPath); } - } else { - throw new Exception("File $fileName is not found at the given location: $fullPath"); } } } From f62f4dde22683f13319c80499c2db685623c1bf4 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 1 Jun 2016 16:14:22 +0100 Subject: [PATCH 3/8] [Behat] gather contexts using annotions in the properties --- Features/Context/ContentActions.php | 19 +++------- Features/Context/Fields.php | 19 +++------- Features/Context/PlatformUI.php | 37 +++++++++++++++++++ Features/Context/Role.php | 15 ++------ .../Context/SubContext/Authentication.php | 6 +-- .../Context/SubContext/BrowserContext.php | 2 +- .../Context/SubContext/ContentEditContext.php | 30 ++++++--------- Features/Context/Users.php | 24 +++--------- 8 files changed, 74 insertions(+), 78 deletions(-) diff --git a/Features/Context/ContentActions.php b/Features/Context/ContentActions.php index a389d4ea8..be6b849eb 100644 --- a/Features/Context/ContentActions.php +++ b/Features/Context/ContentActions.php @@ -9,28 +9,21 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; use PHPUnit_Framework_Assert as Assertion; class ContentActions extends PlatformUI { /** + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext + * @Context $contentEditContext EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext */ - private $contentEditContext; - private $dashboardContext; + protected $contentEditContext; /** - * @BeforeScenario + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ - public function gatherContexts(BeforeScenarioScope $scope) - { - $this->contentEditContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext' - ); - $this->dashboardContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' - ); - } + protected $dashboardContext; /** */ diff --git a/Features/Context/Fields.php b/Features/Context/Fields.php index b0fcf53cd..ea055619d 100644 --- a/Features/Context/Fields.php +++ b/Features/Context/Fields.php @@ -9,7 +9,6 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Mink\WebAssert; use EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext as FieldType; @@ -19,22 +18,16 @@ class Fields extends PlatformUI const NOTIFICATION_PUBLISH_ERROR = 'An error occured while publishing the draft'; /** + * @var EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext + * @Context $fieldtypeContext EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext */ - private $fieldtypeContext; - private $dashboardContext; + protected $fieldtypeContext; /** - * @BeforeScenario + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ - public function gatherContexts(BeforeScenarioScope $scope) - { - $this->fieldtypeContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext' - ); - $this->dashboardContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' - ); - } + protected $dashboardContext; protected function getFieldIdentCss($identifier, $contentId = '') { diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index 218eb793e..08e018295 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -9,6 +9,8 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; +use ReflectionClass; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\MinkExtension\Context\RawMinkContext; class PlatformUI extends RawMinkContext @@ -97,6 +99,22 @@ public function __construct($uri = self::PLATFORM_URI, $user = null, $password = } } + /** + * @BeforeScenario + */ + public function gatherContexts(BeforeScenarioScope $scope) + { + $refClass = new ReflectionClass($this); + $refProperties = $refClass->getProperties(); + foreach ($refProperties as $refProperty) { + preg_match_all('#@(.*?)\n#s', $refProperty->getDocComment(), $matches); + $contexts = $this->parseAnnotations($matches[1]); + foreach ($contexts as $property => $context) { + $this->$property = $scope->getEnvironment()->getContext($context); + } + } + } + /** * @BeforeScenario */ @@ -448,11 +466,30 @@ protected function closeEditView() } catch (\Exception $e) { } } + /** + * Returns an array with the properties contexts, + * if the properties use the Context Annotation. * + * @return array array of methods and their service dependencies */ + private function parseAnnotations($annotations) { + // parse array from (numeric key => 'annotation ') to (annotation => value) + $propertiesContexts = []; + foreach ($annotations as $annotation) { + if (!preg_match('/^(\w+)\s+\$(\w+)\s+([\w\.\\\\]+)/', $annotation, $matches)) { + continue; + } + + array_shift($matches); + $tag = array_shift($matches); + if ($tag == 'Context') { + list($property, $context) = $matches; + $propertiesContexts[$property] = $context; } } + + return $propertiesContexts; } } diff --git a/Features/Context/Role.php b/Features/Context/Role.php index af316de5a..8296c7ba2 100644 --- a/Features/Context/Role.php +++ b/Features/Context/Role.php @@ -10,23 +10,14 @@ namespace EzSystems\PlatformUIBundle\Features\Context; use Behat\Gherkin\Node\TableNode; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; class Role extends PlatformUI { /** + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ - private $dashboardContext; - - /** - * @BeforeScenario - */ - public function gatherContexts(BeforeScenarioScope $scope) - { - $this->dashboardContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' - ); - } + protected $dashboardContext; /** * @Given I am on the Roles page diff --git a/Features/Context/SubContext/Authentication.php b/Features/Context/SubContext/Authentication.php index 4d85852ae..588493ca7 100644 --- a/Features/Context/SubContext/Authentication.php +++ b/Features/Context/SubContext/Authentication.php @@ -52,7 +52,7 @@ public function __construct(Repository $repository, UserService $userService, Ro } /** - * Get credentials for a specific role + * Get credentials for a specific role. * * @uses \EzSystems\BehatBundle\Context\Object\User * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException @@ -85,8 +85,8 @@ protected function getCredentialsFor($roleIdentifier) $this->roleService->assignRoleToUser($role, $user); return array( - 'login' => $username, - 'password' => $password, + 'login' => $username, + 'password' => $password, ); } diff --git a/Features/Context/SubContext/BrowserContext.php b/Features/Context/SubContext/BrowserContext.php index e4b844f32..35ecfdd22 100644 --- a/Features/Context/SubContext/BrowserContext.php +++ b/Features/Context/SubContext/BrowserContext.php @@ -30,7 +30,7 @@ public function prepareHelpers() } /** - * Getter for Xpath + * Getter for Xpath. * * @return \EzSystems\BehatBundle\Helper\Xpath */ diff --git a/Features/Context/SubContext/ContentEditContext.php b/Features/Context/SubContext/ContentEditContext.php index 7df7de34d..08b92dc95 100644 --- a/Features/Context/SubContext/ContentEditContext.php +++ b/Features/Context/SubContext/ContentEditContext.php @@ -10,32 +10,26 @@ namespace EzSystems\PlatformUIBundle\Features\Context\SubContext; use PHPUnit_Framework_Assert as Assertion; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; use EzSystems\PlatformUIBundle\Features\Context\PlatformUI; class ContentEditContext extends PlatformUI { /** + * @Context $basicContentContext EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext */ - private $basicContentContext; - private $dashboardContext; - private $browserContext; + protected $basicContentContext; /** - * @BeforeScenario + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ - public function gatherContexts(BeforeScenarioScope $scope) - { - $this->basicContentContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext' - ); - $this->dashboardContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' - ); - $this->browserContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext' - ); - } + protected $dashboardContext; + + /** + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + */ + protected $browserContext; /** * @Given I create a content of content type :type with: @@ -54,7 +48,7 @@ public function iCreateContentType($type, TableNode $fields) } } - /** + /** * @Given I am on :name full view */ public function onFullView($name) diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 9f6e08605..29e0b271c 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -9,33 +9,21 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; class Users extends PlatformUI { /** - * @var \EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext + * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ - private $dashboardContext; + protected $dashboardContext; /** - * @var \EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext */ - private $browserContext; - - /** - * @BeforeScenario - */ - public function gatherContexts(BeforeScenarioScope $scope) - { - $this->dashboardContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext' - ); - $this->browserContext = $scope->getEnvironment()->getContext( - 'EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext' - ); - } + protected $browserContext; /** * @Given I am on the Users page From 5a37f9da92705f1e2c33264665acfaee316cdb75 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 2 Jun 2016 13:49:14 +0100 Subject: [PATCH 4/8] [Behat] Fix iSeeTitle() method in wrong Context --- Features/Context/PlatformUI.php | 17 ----------------- Features/Context/Role.php | 10 ++++++++-- Features/Context/Users.php | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index 08e018295..a2404b755 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -435,23 +435,6 @@ protected function closeConfirmBox() } } - public function iSeeTitle($title) - { - $page = $this->getSession()->getPage(); - $this->spin( - function () use ($title, $page) { - $titleElements = $page->findAll('css', 'h1, h2, h3'); - foreach ($titleElements as $titleElement) { - $elementText = $titleElement->getText(); - if ($elementText == $title) { - return $titleElement; - } - } - throw new \Exception("Title '$title' not found"); - } - ); - } - /** * Close the Edit view, if it is open. */ diff --git a/Features/Context/Role.php b/Features/Context/Role.php index 8296c7ba2..7da8e0555 100644 --- a/Features/Context/Role.php +++ b/Features/Context/Role.php @@ -19,6 +19,12 @@ class Role extends PlatformUI */ protected $dashboardContext; + /** + * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext + */ + protected $browserContext; + /** * @Given I am on the Roles page */ @@ -97,7 +103,7 @@ public function roleDetailsView($role) */ public function iSeeRolePage() { - $this->iSeeTitle('Roles'); + $this->browserContext->iSeeTitle('Roles'); } /** @@ -165,7 +171,7 @@ public function nameAlreadyExists($name) */ public function roleAssigmentLabel() { - $this->iSeeTitle('Invalid argument: The role name must be unique.'); + $this->browserContext->iSeeTitle('Invalid argument: The role name must be unique.'); } /** diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 29e0b271c..3deda8c3e 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -76,7 +76,7 @@ public function editUserUser($username) public function iSeeUsersPage() { $this->sleep(); // safegaurd for application delays - $this->iSeeTitle('Users'); + $this->browserContext->iSeeTitle('Users'); } /** From 678d2a1ed834c8ea24b5e15ac55df7d0872378fa Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 3 Jun 2016 08:17:57 +0100 Subject: [PATCH 5/8] [Behat] Improve gatherContexts, use @var annotation instead of custom @Context --- Features/Context/ContentActions.php | 2 - Features/Context/Fields.php | 2 - Features/Context/PlatformUI.php | 42 ++++++------------- Features/Context/Role.php | 2 - .../Context/SubContext/ContentEditContext.php | 4 +- Features/Context/Users.php | 2 - 6 files changed, 13 insertions(+), 41 deletions(-) diff --git a/Features/Context/ContentActions.php b/Features/Context/ContentActions.php index be6b849eb..eced2e2e3 100644 --- a/Features/Context/ContentActions.php +++ b/Features/Context/ContentActions.php @@ -15,13 +15,11 @@ class ContentActions extends PlatformUI { /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext - * @Context $contentEditContext EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext */ protected $contentEditContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext - * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ protected $dashboardContext; diff --git a/Features/Context/Fields.php b/Features/Context/Fields.php index ea055619d..72f802ae3 100644 --- a/Features/Context/Fields.php +++ b/Features/Context/Fields.php @@ -19,13 +19,11 @@ class Fields extends PlatformUI /** * @var EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext - * @Context $fieldtypeContext EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext */ protected $fieldtypeContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext - * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ protected $dashboardContext; diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index a2404b755..346e2cbe4 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -101,16 +101,24 @@ public function __construct($uri = self::PLATFORM_URI, $user = null, $password = /** * @BeforeScenario + * + * Default gather contexts method. + * Uses doc comment type hint to get the contexts and set them */ public function gatherContexts(BeforeScenarioScope $scope) { $refClass = new ReflectionClass($this); $refProperties = $refClass->getProperties(); foreach ($refProperties as $refProperty) { - preg_match_all('#@(.*?)\n#s', $refProperty->getDocComment(), $matches); - $contexts = $this->parseAnnotations($matches[1]); - foreach ($contexts as $property => $context) { - $this->$property = $scope->getEnvironment()->getContext($context); + $propertyName = $refProperty->getName(); + // get property type hint from doc comment + preg_match_all('#@var\s(.*?)\n#s', $refProperty->getDocComment(), $matches); + foreach ($matches[1] as $typeHint) { + // checks if the type hint implements Behat Context + $implements = @class_implements($typeHint); + if (!empty($implements) && in_array('Behat\Behat\Context\Context', $implements)) { + $this->$propertyName = $scope->getEnvironment()->getContext($typeHint); + } } } } @@ -449,30 +457,4 @@ protected function closeEditView() } catch (\Exception $e) { } } - - /** - * Returns an array with the properties contexts, - * if the properties use the Context Annotation. - * - * @return array array of methods and their service dependencies - */ - private function parseAnnotations($annotations) - { - // parse array from (numeric key => 'annotation ') to (annotation => value) - $propertiesContexts = []; - foreach ($annotations as $annotation) { - if (!preg_match('/^(\w+)\s+\$(\w+)\s+([\w\.\\\\]+)/', $annotation, $matches)) { - continue; - } - - array_shift($matches); - $tag = array_shift($matches); - if ($tag == 'Context') { - list($property, $context) = $matches; - $propertiesContexts[$property] = $context; - } - } - - return $propertiesContexts; - } } diff --git a/Features/Context/Role.php b/Features/Context/Role.php index 7da8e0555..a81357aa6 100644 --- a/Features/Context/Role.php +++ b/Features/Context/Role.php @@ -15,13 +15,11 @@ class Role extends PlatformUI { /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext - * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ protected $dashboardContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext */ protected $browserContext; diff --git a/Features/Context/SubContext/ContentEditContext.php b/Features/Context/SubContext/ContentEditContext.php index 08b92dc95..54d24effc 100644 --- a/Features/Context/SubContext/ContentEditContext.php +++ b/Features/Context/SubContext/ContentEditContext.php @@ -15,19 +15,17 @@ class ContentEditContext extends PlatformUI { /** - * @Context $basicContentContext EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext + * @var EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext */ protected $basicContentContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext - * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ protected $dashboardContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext */ protected $browserContext; diff --git a/Features/Context/Users.php b/Features/Context/Users.php index 3deda8c3e..7518f8103 100644 --- a/Features/Context/Users.php +++ b/Features/Context/Users.php @@ -15,13 +15,11 @@ class Users extends PlatformUI { /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext - * @Context $dashboardContext EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext */ protected $dashboardContext; /** * @var EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - * @Context $browserContext EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext */ protected $browserContext; From 225ab8a534ca54f5d3c20fa24a78d0ff021bcc40 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 3 Jun 2016 08:33:40 +0100 Subject: [PATCH 6/8] [Behat] Remove not used property --- Features/Context/PlatformUI.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index 346e2cbe4..12769dae0 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -72,11 +72,6 @@ class PlatformUI extends RawMinkContext */ protected $password = 'publish'; - /** - * Mapping of pages URL's. - */ - protected $pageIdentifierMap = array(); - /** * Stores the status of the platform. * @var int From f204c59852a8fb6c3b36412a018cffd85d7ea10e Mon Sep 17 00:00:00 2001 From: Miguel Jacinto Date: Mon, 27 Jun 2016 15:32:06 +0100 Subject: [PATCH 7/8] [Behat] Fix kernel behat contexts namespace --- Features/Context/Fields.php | 4 ++-- Features/Context/SubContext/ContentEditContext.php | 2 +- behat_suites.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Features/Context/Fields.php b/Features/Context/Fields.php index 72f802ae3..7ce13da9a 100644 --- a/Features/Context/Fields.php +++ b/Features/Context/Fields.php @@ -10,7 +10,7 @@ namespace EzSystems\PlatformUIBundle\Features\Context; use Behat\Mink\WebAssert; -use EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext as FieldType; +use eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext as FieldType; class Fields extends PlatformUI { @@ -18,7 +18,7 @@ class Fields extends PlatformUI const NOTIFICATION_PUBLISH_ERROR = 'An error occured while publishing the draft'; /** - * @var EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext + * @var eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext */ protected $fieldtypeContext; diff --git a/Features/Context/SubContext/ContentEditContext.php b/Features/Context/SubContext/ContentEditContext.php index 54d24effc..b4fffa5a2 100644 --- a/Features/Context/SubContext/ContentEditContext.php +++ b/Features/Context/SubContext/ContentEditContext.php @@ -15,7 +15,7 @@ class ContentEditContext extends PlatformUI { /** - * @var EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext + * @var eZ\Bundle\EzPublishCoreBundle\Features\Context\BasicContentContext */ protected $basicContentContext; diff --git a/behat_suites.yml b/behat_suites.yml index e5a248206..82ad1e6f1 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -11,7 +11,7 @@ platformui: contentactions: paths: [ vendor/ezsystems/platform-ui-bundle/Features/ContentActions ] contexts: - - EzSystems\PlatformBehatBundle\Context\Object\BasicContentContext + - eZ\Bundle\EzPublishCoreBundle\Features\Context\BasicContentContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext @@ -21,7 +21,7 @@ platformui: role: paths: [ vendor/ezsystems/platform-ui-bundle/Features/RoleUI ] contexts: - - EzSystems\PlatformBehatBundle\Context\Object\RoleContext + - eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext @@ -30,7 +30,7 @@ platformui: fieldtype_integer: paths: [ vendor/ezsystems/platform-ui-bundle/Features/Stories/FieldTypes/IntegerFieldType.feature ] contexts: - - EzSystems\PlatformBehatBundle\Context\Object\FieldTypeContext + - eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext @@ -39,7 +39,7 @@ platformui: user: paths: [ vendor/ezsystems/platform-ui-bundle/Features/Users/users.feature ] contexts: - - EzSystems\PlatformBehatBundle\Context\Object\UserContext + - eZ\Bundle\EzPublishCoreBundle\Features\Context\UserContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\BrowserContext - EzSystems\PlatformUIBundle\Features\Context\SubContext\Authentication - EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext From e36e132fdad2c85735318eccd2c2221c8533e164 Mon Sep 17 00:00:00 2001 From: Miguel Jacinto Date: Mon, 27 Jun 2016 15:40:48 +0100 Subject: [PATCH 8/8] [Behat] Remove xPath Helper --- .../Context/SubContext/BrowserContext.php | 50 +++++-------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/Features/Context/SubContext/BrowserContext.php b/Features/Context/SubContext/BrowserContext.php index 35ecfdd22..17d027067 100644 --- a/Features/Context/SubContext/BrowserContext.php +++ b/Features/Context/SubContext/BrowserContext.php @@ -9,36 +9,11 @@ */ namespace EzSystems\PlatformUIBundle\Features\Context\SubContext; -use EzSystems\BehatBundle\Helper\EzAssertion; use EzSystems\PlatformUIBundle\Features\Context\PlatformUI; use EzSystems\PlatformBehatBundle\Helper\Xpath; class BrowserContext extends PlatformUI { - /** - * @var \EzSystems\BehatBundle\Helper\Xpath - */ - private $xpath; - - /** - * @BeforeScenario - */ - public function prepareHelpers() - { - // initialize Helpers - $this->xpath = new Xpath($this->getSession()); - } - - /** - * Getter for Xpath. - * - * @return \EzSystems\BehatBundle\Helper\Xpath - */ - public function getXpath() - { - return $this->xpath; - } - /** * @Given I clicked on/at (the) :link link * @When I click on/at (the) :link link @@ -143,18 +118,17 @@ public function seeInputField($label) */ public function checkOption($option) { - $fieldElements = $this->getXpath()->findFields($option); - EzAssertion::assertElementFound($option, $fieldElements, null, 'checkbox'); - - // this is needed for the cases where are checkboxes and radio's - // side by side, for main option the radio and the extra being the - // checkboxes values - if (strtolower($fieldElements[0]->getAttribute('type')) !== 'checkbox') { - $value = $fieldElements[0]->getAttribute('value'); - $fieldElements = $this->getXpath()->findXpath("//input[@type='checkbox' and @value='$value']"); - EzAssertion::assertElementFound($value, $fieldElements, null, 'checkbox'); - } - - $fieldElements[0]->check(); + $session = $this->getSession(); + $selectorsHandler = $session->getSelectorsHandler(); + $literal = $selectorsHandler->xpathLiteral($option); + + // To be able to work on mink 1.6 (ezplatform) & mink 1.5 (5.4+ezpublish-community) w/o deprecation exceptions + $selector = $selectorsHandler->isSelectorRegistered('named_partial') ? + $selectorsHandler->getSelector('named_partial') : + $selectorsHandler->getSelector('named'); + $xpath = $selector->translateToXPath(array('field', $literal)); + + $fieldElement = $session->getPage()->find('xpath', $xpath); + $fieldElement->check(); } }