Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Changed cs to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel committed Jun 1, 2015
1 parent 67407e3 commit 9259b24
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 183 deletions.
100 changes: 44 additions & 56 deletions Features/Context/PlatformUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,72 +68,68 @@ 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]]);
}
}
}

/**
* @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");
}
}

Expand All @@ -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;
}
}

Expand All @@ -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();
}
Expand All @@ -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");
}
}
}
21 changes: 10 additions & 11 deletions Features/Context/SubContext/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +56,7 @@ public function goToPlatformUiAndLogIn( $username, $password )
*/
public function loggedAsAdminPlatformUi()
{
$this->goToPlatformUiAndLogIn( $this->user, $this->password );
$this->goToPlatformUiAndLogIn($this->user, $this->password);
}

/**
Expand All @@ -65,7 +65,7 @@ public function loggedAsAdminPlatformUi()
public function iLogout()
{
$this->shouldBeLoggedIn = false;
$this->iClickAtLink( "Logout" );
$this->iClickAtLink("Logout");
}

/**
Expand All @@ -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);";
}

Expand All @@ -87,8 +87,7 @@ public function iShouldBeLoggedIn()
*/
public function runAfterStep()
{
if ( $this->shouldBeLoggedIn )
{
if ($this->shouldBeLoggedIn) {
$this->iShouldBeLoggedIn();
}
}
Expand Down
Loading

0 comments on commit 9259b24

Please sign in to comment.