From 9259b247bb083bc09a8bbf70871532db72defca2 Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 1 Jun 2015 11:20:21 +0100 Subject: [PATCH] Changed cs to PSR-2 --- Features/Context/PlatformUI.php | 100 ++++++------- .../Context/SubContext/Authentication.php | 21 ++- Features/Context/SubContext/CommonActions.php | 107 ++++++-------- Features/Context/SubContext/Fields.php | 131 ++++++++++-------- 4 files changed, 176 insertions(+), 183 deletions(-) diff --git a/Features/Context/PlatformUI.php b/Features/Context/PlatformUI.php index 3e33c569a..9f05e185a 100644 --- a/Features/Context/PlatformUI.php +++ b/Features/Context/PlatformUI.php @@ -68,32 +68,29 @@ protected function waitForLoadings() // contenttype menu '.ez-view-createcontentactionview.is-expanded:not(.is-contenttypeselector-loaded)' ); - $loadingSelector = implode( ',', $loadingClasses ); - while ( $page->find( 'css', $loadingSelector ) != null ) - { - usleep( 100 * 1000 ); // 100ms + $loadingSelector = implode(',', $loadingClasses); + while ($page->find('css', $loadingSelector) != null) { + usleep(100 * 1000); // 100ms } } /** * @Given I create a content of content type :type with: */ - public function iCreateContentType( $type, TableNode $fields ) + public function iCreateContentType($type, TableNode $fields) { - $this->clickNavigationZone( "Platform" ); + $this->clickNavigationZone("Platform"); $this->waitForLoadings(); - $this->iClickAtLink( "Content structure" ); + $this->iClickAtLink("Content structure"); $this->waitForLoadings(); - $this->clickActionBar( "Create a content" ); + $this->clickActionBar("Create a content"); $this->waitForLoadings(); - $this->clickContentType( $type ); + $this->clickContentType($type); $this->waitForLoadings(); - foreach ( $fields as $fieldArray ) - { - $keys = array_keys( $fieldArray ); - for ( $i = 0; $i < count( $keys ); $i++ ) - { - $this->fillFieldWithValue( $keys[$i], $fieldArray[$keys[$i]] ); + foreach ($fields as $fieldArray) { + $keys = array_keys($fieldArray); + for ($i = 0; $i < count($keys); $i++) { + $this->fillFieldWithValue($keys[$i], $fieldArray[$keys[$i]]); } } } @@ -101,39 +98,38 @@ public function iCreateContentType( $type, TableNode $fields ) /** * @Then I see Content :contentName of type :contentType */ - public function contentExists( $contentName, $contentType ) + public function contentExists($contentName, $contentType) { $contentId = $this->getLocationId(); - $content = $this->getContentManager()->loadContentWithLocationId( $contentId ); + $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" ); + $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 (an) element :element with (an) file :file */ - public function iSeeElementFile( $element, $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 ); + $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 see elements with the following names: */ - public function iSeeElements( TableNode $elements ) + public function iSeeElements(TableNode $elements) { - foreach ( $elements as $element ) - { + 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" ); + $name = array_values($element)[0]; + $found = $this->getElementByText($name, '.ez-selection-filter-item'); + Assertion::assertNotNull($found, "Element: $name not found"); } } @@ -152,17 +148,15 @@ public function waitForJs() * * @param string $uri */ - public function __construct( $uri, $user = null, $password = null ) + public function __construct($uri, $user = null, $password = null) { parent::__construct(); $this->platformUiUri = $uri; - if ( $user != null ) - { + if ($user != null) { $this->user = $user; } - if ( $password != null ) - { - $this->password = $password; + if ($password != null) { + $this->password = $password; } } @@ -171,9 +165,8 @@ public function __construct( $uri, $user = null, $password = null ) */ private function executeDelayedActions() { - if ( $this->platformStatus == self::WAITING_FOR_PUBLISHING ) - { - $this->clickActionBar( "Publish" ); + if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { + $this->clickActionBar("Publish"); } $this->waitForLoadings(); } @@ -184,27 +177,22 @@ private function executeDelayedActions() * @param string $file file name relative to mink definitions * @param string $selector CSS file upload element selector */ - protected function attachFile( $fileName, $selector ) + protected function attachFile($fileName, $selector) { - if ( $this->getMinkParameter( 'files_path' ) ) - { - $fullPath = rtrim( realpath( $this->getMinkParameter( 'files_path' ) ), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR.$fileName; + if ($this->getMinkParameter('files_path')) { + $fullPath = rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$fileName; - if ( is_file( $fullPath ) ) - { + if (is_file($fullPath)) { $fileInput = 'input[type="file"]' . $selector; - $field = $this->getSession()->getPage()->find( 'css', $fileInput ); + $field = $this->getSession()->getPage()->find('css', $fileInput); - if ( null === $field ) - { - throw new Exception( "File input $selector is not found" ); + if (null === $field) { + throw new Exception("File input $selector is not found"); } - $field->attachFile( $fullPath ); + $field->attachFile($fullPath); } - } - else - { - throw new Exception( "File $fileName is not found at the given location: $fullPath" ); + } else { + throw new Exception("File $fileName is not found at the given location: $fullPath"); } } } diff --git a/Features/Context/SubContext/Authentication.php b/Features/Context/SubContext/Authentication.php index d95c411df..3bd4315f4 100644 --- a/Features/Context/SubContext/Authentication.php +++ b/Features/Context/SubContext/Authentication.php @@ -27,24 +27,24 @@ trait Authentication */ public function goToPlatformUi() { - $this->visit( $this->platformUiUri ); + $this->visit($this->platformUiUri); } /** * @Given I go to PlatformUI app with username :user and password :password */ - public function goToPlatformUiAndLogIn( $username, $password ) + public function goToPlatformUiAndLogIn($username, $password) { // Given I go to PlatformUI app $this->goToPlatformUi(); //wait fos JS $this->waitForJs(); // And I fill in "Username" with "admin" - $this->fillFieldWithValue( 'Username', $username ); + $this->fillFieldWithValue('Username', $username); //And I fill in "Password" with "publish" - $this->fillFieldWithValue( 'Password', $password ); + $this->fillFieldWithValue('Password', $password); //And I click on the "Login" button - $this->iClickAtButton( 'Login' ); + $this->iClickAtButton('Login'); //wait fos JS $this->waitForJs(); //Then I should be logged in @@ -56,7 +56,7 @@ public function goToPlatformUiAndLogIn( $username, $password ) */ public function loggedAsAdminPlatformUi() { - $this->goToPlatformUiAndLogIn( $this->user, $this->password ); + $this->goToPlatformUiAndLogIn($this->user, $this->password); } /** @@ -65,7 +65,7 @@ public function loggedAsAdminPlatformUi() public function iLogout() { $this->shouldBeLoggedIn = false; - $this->iClickAtLink( "Logout" ); + $this->iClickAtLink("Logout"); } /** @@ -75,8 +75,8 @@ public function iShouldBeLoggedIn() { $this->shouldBeLoggedIn = true; - $verification = new WebAssert( $this->getSession() ); - $verification->elementNotExists( 'css', '.ez-loginform' ); + $verification = new WebAssert($this->getSession()); + $verification->elementNotExists('css', '.ez-loginform'); $jsCode = "return (document.querySelector('.ez-loginform') === null);"; } @@ -87,8 +87,7 @@ public function iShouldBeLoggedIn() */ public function runAfterStep() { - if ( $this->shouldBeLoggedIn ) - { + if ($this->shouldBeLoggedIn) { $this->iShouldBeLoggedIn(); } } diff --git a/Features/Context/SubContext/CommonActions.php b/Features/Context/SubContext/CommonActions.php index f245b8c6f..9ea065608 100644 --- a/Features/Context/SubContext/CommonActions.php +++ b/Features/Context/SubContext/CommonActions.php @@ -20,7 +20,7 @@ public function clickLogo() { $page = $this->getSession()->getPage(); $selector = '.ez-logo a'; - $page->find( 'css', $selector )->click(); + $page->find('css', $selector)->click(); } /** @@ -29,9 +29,9 @@ public function clickLogo() * * @param string $tab Text of the element to click */ - public function clickTab( $tab ) + public function clickTab($tab) { - $this->clickElementByText( $tab, ".ez-tabs-label a[href]" ); + $this->clickElementByText($tab, ".ez-tabs-label a[href]"); } /** @@ -40,9 +40,9 @@ public function clickTab( $tab ) * * @param string $zone Text of the element to click */ - public function clickNavigationZone( $zone ) + public function clickNavigationZone($zone) { - $this->clickElementByText( $zone, ".ez-zone-name" ); + $this->clickElementByText($zone, ".ez-zone-name"); } /** @@ -52,9 +52,9 @@ public function clickNavigationZone( $zone ) * @param string $button Text of the element to click * @param string $index WHAT IS THIS?! */ - public function clickButtonWithIndex( $button, $index ) + public function clickButtonWithIndex($button, $index) { - $this->clickElementByText( $button, "button", $index ); + $this->clickElementByText($button, "button", $index); } /** @@ -63,12 +63,12 @@ public function clickButtonWithIndex( $button, $index ) * * @param string $button Text of the element to click */ - public function overNavigationZone( $zone ) + public function overNavigationZone($zone) { $selector = ".ez-zone-name"; - $jsArgs = JsHelper::generateFuncArgs( $zone, $selector ); + $jsArgs = JsHelper::generateFuncArgs($zone, $selector); $jsCode = "return BDD.mouseOverElementByText( $jsArgs );"; - $this->execJavascript( $jsCode ); + $this->execJavascript($jsCode); } /** @@ -77,9 +77,9 @@ public function overNavigationZone( $zone ) * * @param string $item Text of the element to click */ - public function clickNavigationItem( $item ) + public function clickNavigationItem($item) { - $this->clickElementByText( $item, '.ez-navigation-item' ); + $this->clickElementByText($item, '.ez-navigation-item'); } /** @@ -88,9 +88,9 @@ public function clickNavigationItem( $item ) * * @param string $action Text of the element to click */ - public function clickActionBar( $action ) + public function clickActionBar($action) { - $this->clickElementByText( $action, '.ez-action', '.action-label' ); + $this->clickElementByText($action, '.ez-action', '.action-label'); } /** @@ -99,9 +99,9 @@ public function clickActionBar( $action ) * * @param string $contentType Text of the element to click */ - public function clickContentType( $contentType ) + public function clickContentType($contentType) { - $this->clickElementByText( $contentType, '.ez-contenttypeselector-types .ez-selection-filter-item ' ); + $this->clickElementByText($contentType, '.ez-contenttypeselector-types .ez-selection-filter-item '); } /** @@ -110,18 +110,17 @@ public function clickContentType( $contentType ) * * @param string $path The content tree path such as 'Content1/Content2/ContentIWantToClick' */ - public function openTreePath( $path ) + public function openTreePath($path) { - $this->clickActionBar( "Content tree" ); + $this->clickActionBar("Content tree"); $this->waitForLoadings(); - $path = explode( "/", $path ); + $path = explode("/", $path); $node = null; - foreach ( $path as $pathNode ) - { - $node = $this->openTreeNode( $pathNode, $node ); + foreach ($path as $pathNode) { + $node = $this->openTreeNode($pathNode, $node); $this->waitForLoadings(); } - $node->find( 'css', '.ez-tree-navigate' )->click(); + $node->find('css', '.ez-tree-navigate')->click(); } /** @@ -131,35 +130,29 @@ public function openTreePath( $path ) * @param NodeElement $node The base node that I want to expand from, if null provided defaults to the content tree root * @return NodeElement The node that was opened */ - private function openTreeNode( $pathNode, $node ) + private function openTreeNode($pathNode, $node) { $page = $this->getSession()->getPage(); $notFound = true; - if ( $node == null ) - { - $node = $page->find( 'css', '.ez-platformui-app-body' ); + if ($node == null) { + $node = $page->find('css', '.ez-platformui-app-body'); } - $subNodes = $node->findAll( 'css', '.ez-tree-node' ); - foreach ( $subNodes as $subNode ) - { - $leafNode = $subNode->find( 'css', '.ez-tree-navigate' ); - if ( $leafNode->getText() == $pathNode ) - { + $subNodes = $node->findAll('css', '.ez-tree-node'); + foreach ($subNodes as $subNode) { + $leafNode = $subNode->find('css', '.ez-tree-navigate'); + if ($leafNode->getText() == $pathNode) { $notFound = false; - if ( $subNode->hasClass( 'is-tree-node-close' ) ) - { - $toggleNode = $subNode->find( 'css', '.ez-tree-node-toggle' ); - if ( $toggleNode->isVisible() ) - { + if ($subNode->hasClass('is-tree-node-close')) { + $toggleNode = $subNode->find('css', '.ez-tree-node-toggle'); + if ($toggleNode->isVisible()) { $toggleNode->click(); } } return $subNode; } } - if ( $notFound ) - { - throw new \Exception( "The path node: $pathNode was not found for the given path" ); + if ($notFound) { + throw new \Exception("The path node: $pathNode was not found for the given path"); } return $node; } @@ -170,17 +163,14 @@ private function openTreeNode( $pathNode, $node ) * @param string $text Text value of the element * @param string $selector CSS selector of the element */ - protected function clickElementByText( $text, $selector, $textSelector= null, $index = 1 ) + protected function clickElementByText($text, $selector, $textSelector = null, $index = 1) { $index + 1; //DO NOT FORGET SOMETHING THAT I DON'T REMENBER - $element = $this->getElementByText( $text, $selector, $textSelector ); - if ( $element ) - { + $element = $this->getElementByText($text, $selector, $textSelector); + if ($element) { $element->click(); - } - else - { - throw new \Exception( "Can't click \" $text \" element: Not Found" ); + } else { + throw new \Exception("Can't click \" $text \" element: Not Found"); } } @@ -192,22 +182,17 @@ protected function clickElementByText( $text, $selector, $textSelector= null, $i * @param string $textSelector extra CSS selector for text of the element * @return array */ - protected function getElementByText( $text, $selector, $textSelector = null ) + protected function getElementByText($text, $selector, $textSelector = null) { $page = $this->getSession()->getPage(); - $elements = $page->findAll( 'css', $selector ); - foreach ( $elements as $element ) - { - if ( $textSelector != null ) - { - $elementText = $element->find( 'css', $textSelector )->getText(); - } - else - { + $elements = $page->findAll('css', $selector); + foreach ($elements as $element) { + if ($textSelector != null) { + $elementText = $element->find('css', $textSelector)->getText(); + } else { $elementText = $element->getText(); } - if ( $elementText == $text ) - { + if ($elementText == $text) { return $element; } } diff --git a/Features/Context/SubContext/Fields.php b/Features/Context/SubContext/Fields.php index 072b030f6..e0577c821 100644 --- a/Features/Context/SubContext/Fields.php +++ b/Features/Context/SubContext/Fields.php @@ -21,17 +21,17 @@ trait Fields public function createAContentOfThisType() { $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState( FieldType::CONTENT_TYPE_PUBLISHED ); - $type = $fieldManager->getThisContentTypeName( 'eng-GB' ); + $fieldManager->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED); + $type = $fieldManager->getThisContentTypeName('eng-GB'); $this->loggedAsAdminPlatformUi(); - $this->clickNavigationZone( "Platform" ); + $this->clickNavigationZone("Platform"); $this->waitForLoadings(); - $this->iClickAtLink( "Content structure" ); + $this->iClickAtLink("Content structure"); $this->waitForLoadings(); - $this->clickActionBar( "Create a content" ); + $this->clickActionBar("Create a content"); $this->waitForLoadings(); - $this->clickContentType( $type ); + $this->clickContentType($type); $this->waitForLoadings(); $this->platformStatus = self::WAITING_FOR_PUBLISHING; } @@ -42,17 +42,17 @@ public function createAContentOfThisType() public function editThisContent() { $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState( FieldType::CONTENT_PUBLISHED ); - $name = $fieldManager->getThisContentName( 'eng-GB' ); + $fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); + $name = $fieldManager->getThisContentName('eng-GB'); $this->loggedAsAdminPlatformUi(); - $this->clickNavigationZone( "Platform" ); + $this->clickNavigationZone("Platform"); $this->waitForLoadings(); - $this->iClickAtLink( "Content structure" ); + $this->iClickAtLink("Content structure"); $this->waitForLoadings(); - $this->openTreePath( $name ); + $this->openTreePath($name); $this->waitForLoadings(); - $this->clickActionBar( "Edit" ); + $this->clickActionBar("Edit"); $this->waitForLoadings(); $this->platformStatus = self::WAITING_FOR_PUBLISHING; } @@ -63,15 +63,15 @@ public function editThisContent() public function viewThisContent() { $fieldManager = $this->getFieldTypeManager(); - $fieldManager->setFieldContentState( FieldType::CONTENT_PUBLISHED ); - $name = $fieldManager->getThisContentName( 'eng-GB' ); + $fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); + $name = $fieldManager->getThisContentName('eng-GB'); $this->loggedAsAdminPlatformUi(); - $this->clickNavigationZone( "Platform" ); + $this->clickNavigationZone("Platform"); $this->waitForLoadings(); - $this->iClickAtLink( "Content structure" ); + $this->iClickAtLink("Content structure"); $this->waitForLoadings(); - $this->openTreePath( $name ); + $this->openTreePath($name); $this->waitForLoadings(); } @@ -79,11 +79,11 @@ public function viewThisContent() * @When I set :value as the Field Value * @And I set :value as the Field Value */ - public function setFieldValue( $value ) + public function setFieldValue($value) { $fieldManager = $this->getFieldTypeManager(); - $name = $fieldManager->getThisFieldTypeName( 'eng-GB' ); - $this->fillFieldWithValue( $name, $value ); + $name = $fieldManager->getThisFieldTypeName('eng-GB'); + $this->fillFieldWithValue($name, $value); } /** @@ -92,13 +92,40 @@ public function setFieldValue( $value ) */ public function publishContent() { - if ( $this->platformStatus == self::WAITING_FOR_PUBLISHING ) - { - $this->clickActionBar( "Publish" ); + if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { + $this->clickActionBar("Publish"); + } else { + throw new \Exception("Cannot publish content, application in wrong state"); } - else - { - throw new \Exception( "Cannot publish content, application in wrong state" ); + } + + /** + * @When I check the Field Value + * @And I check the Field Value + */ + public function checkFieldValue() + { + if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { + $fieldManager = $this->getFieldTypeManager(); + $name = $fieldManager->getThisFieldTypeName('eng-GB'); + $this->checkOption($name); + } else { + throw new \Exception("Cannot publish content, application in wrong state"); + } + } + + /** + * @When I uncheck the Field Value + * @And I uncheck the Field Value + */ + public function uncheckFieldValue() + { + if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { + $fieldManager = $this->getFieldTypeManager(); + $name = $fieldManager->getThisFieldTypeName('eng-GB'); + $this->uncheckOption($name); + } else { + throw new \Exception("Cannot publish content, application in wrong state"); } } @@ -106,42 +133,38 @@ public function publishContent() * @Then I should see an/a :type field * @Then I should see an/a :label label related with the :type field */ - public function seeFieldtOfType( $type, $label = null ) + public function seeFieldtOfType($type, $label = null) { $this->executeDelayedActions(); - $verification = new WebAssert( $this->getSession() ); - $internalName = $this->getFieldTypeManager()->getFieldTypeInternalIdentifier( $type ); + $verification = new WebAssert($this->getSession()); + $internalName = $this->getFieldTypeManager()->getFieldTypeInternalIdentifier($type); $selector = ".ez-fieldview-$internalName"; - $verification->elementExists( 'css', $selector ); - if ( $label != null ) - { - $verification->elementTextContains( 'css', '.ez-fieldview-name', $label ); + $verification->elementExists('css', $selector); + if ($label != null) { + $verification->elementTextContains('css', '.ez-fieldview-name', $label); } } /** * @Then I should see an/a field with value :value */ - public function seeFieldtWithValue( $value ) + public function seeFieldtWithValue($value) { $this->executeDelayedActions(); - $verification = new WebAssert( $this->getSession() ); - $verification->elementTextContains( 'css', '.ez-fieldview-value-content', $value ); + $verification = new WebAssert($this->getSession()); + $verification->elementTextContains('css', '.ez-fieldview-value-content', $value); } /** * @Then the :label field should be marked as mandatory */ - public function seeRequiredFieldtOfType( $label ) + public function seeRequiredFieldtOfType($label) { - if ( $this->platformStatus == self::WAITING_FOR_PUBLISHING ) - { - $verification = new WebAssert( $this->getSession() ); - $verification->elementTextContains( 'css', '.ez-fielddefinition-name', $label . '*' ); - } - else - { - throw new \Exception( "Cannot publish content, application in wrong state" ); + if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { + $verification = new WebAssert($this->getSession()); + $verification->elementTextContains('css', '.ez-fielddefinition-name', $label . '*'); + } else { + throw new \Exception("Cannot publish content, application in wrong state"); } } @@ -152,7 +175,7 @@ public function seeRequiredFieldtOfType( $label ) */ public function setFieldValueToNothing() { - $this->setFieldValue( "" ); + $this->setFieldValue(""); } /** @@ -160,10 +183,10 @@ public function setFieldValueToNothing() * * Creates a Content with the previously defined ContentType */ - public function failsWithMessage( $message ) + public function failsWithMessage($message) { - $verification = new WebAssert( $this->getSession() ); - $verification->elementTextContains( 'css', '.ez-editfield-error-message', $message ); + $verification = new WebAssert($this->getSession()); + $verification->elementTextContains('css', '.ez-editfield-error-message', $message); } /** @@ -172,13 +195,11 @@ public function failsWithMessage( $message ) public function contentIsPublished() { $page = $this->getSession()->getPage(); - $errors = $page->findAll( 'css', '.ez-editfield-error-message' ); - foreach ( $errors as $error ) - { + $errors = $page->findAll('css', '.ez-editfield-error-message'); + foreach ($errors as $error) { $errorMessage = $error->getText(); - if ( $errorMessage != '' ) - { - throw new \Exception( "Content could not be published with error message: $errorMessage" ); + if ($errorMessage != '') { + throw new \Exception("Content could not be published with error message: $errorMessage"); } } }