Skip to content

Commit

Permalink
EZEE-1836: Fix broken tests (#338)
Browse files Browse the repository at this point in the history
* EZEE-1836: DBP is passing

* EZEE-1836: FlexWF passing

* EZEE-1836: Form manager before rebasing

* EZEE-1836: All tests passing

* EZEE-1836: Changes before review

* EZEE-1836: Change Travis settings

* EZEE-1836: Changes after review

* EZEE-1836: Remove email notification setting
  • Loading branch information
mnocon authored and Łukasz Serwatka committed Feb 9, 2018
1 parent bf02192 commit 2456675
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ install:
script:
- if [ "${PHPUNIT_CONFIG}" != '' ]; then ./vendor/bin/phpunit -c "${PHPUNIT_CONFIG}"; fi
- if [ "${BEHAT_OPTS}" != "" ]; then cd "$HOME/build/ezplatform"; docker-compose exec --user www-data app sh -c "./bin/behat $BEHAT_OPTS" ; fi

notifications:
email: false
7 changes: 0 additions & 7 deletions src/lib/Behat/BusinessContext/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class AuthenticationContext extends BusinessContext

/**
* @When I login as :username with password :password
*
* @param string $username
* @param string $password
*/
public function iLoginAs(string $username, string $password): void
{
Expand All @@ -35,10 +32,6 @@ public function iLoginAs(string $username, string $password): void

/**
* @Given I am logged as :username
*
* @param string $username
*
* @throws \OutOfBoundsException when username is not recognised
*/
public function iAmLoggedAs(string $username): void
{
Expand Down
48 changes: 47 additions & 1 deletion src/lib/Behat/BusinessContext/ContentViewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;

use EzSystems\EzPlatformAdminUi\Behat\PageElement\LanguagePicker;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\LeftMenu;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\RightMenu;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\UniversalDiscoveryWidget;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentStructurePage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;
use PHPUnit\Framework\Assert;
Expand All @@ -18,7 +22,49 @@ class ContentViewContext extends BusinessContext
public function startCreatingNewLandingPage(string $name): void
{
$contentStructurePage = PageObjectFactory::createPage($this->utilityContext, ContentStructurePage::PAGE_NAME);
$contentStructurePage->createLandingPage($name, 'Test Desc');
$updatePage = $contentStructurePage->startCreatingContent('Landing page');

$updatePage->updateForm->fillFIeldWithValue('Title', $name);
$updatePage->updateForm->fillFIeldWithValue('Description', $name);
}

/**
* @Given I start creating a new Article :name
*/
public function startCreatingArticle(string $name): void
{
$contentStructurePage = PageObjectFactory::createPage($this->utilityContext, ContentStructurePage::PAGE_NAME);
$updatePage = $contentStructurePage->startCreatingContent('Article');

$updatePage->updateForm->fillFIeldWithValue('Title', $name);
$updatePage->updateForm->fillRichtextWithValue('Test desc');
}

/**
* @Given I start editing the content in :language language
*/
public function startEditingContent(string $language): void
{
$rightMenu = new RightMenu($this->utilityContext);
$rightMenu->clickButton('Edit');

$languagePicker = new LanguagePicker($this->utilityContext);
$languagePicker->chooseLanguage($language);
}

/**
* @Given I open UDW and go to :itemPath
*/
public function iOpenUDWAndGoTo(string $itemPath): void
{
$leftMenu = new LeftMenu($this->utilityContext);
$leftMenu->verifyVisibility();
$leftMenu->clickButton('Browse');

$udw = new UniversalDiscoveryWidget($this->utilityContext);
$udw->verifyVisibility();
$udw->selectContent($itemPath);
$udw->confirm();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Behat/BusinessContext/RightMenuContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class RightMenuContext extends BusinessContext
/**
* @Given I click (on) the edit action bar button :button
* Click on a AdminUI edit action bar
*
* @param string $button Text of the element to click
*/
public function clickEditActionBar(string $button): void
{
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions src/lib/Behat/Helper/UtilityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ function () use ($selector, $baseElement) {
}
}

/**
* Filters an array of elements and returns the visible ones.
*
* @param NodeElement[] $elements
*
* @return NodeElement[]
*/
public function getVisibleElements(array $elements): array
{
return array_filter($elements, function ($element) { return $element->isVisible(); });
}

/**
* Checks the visibility of a HTML element found by class.
*
Expand Down
7 changes: 7 additions & 0 deletions src/lib/Behat/PageElement/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Breadcrumb extends Element
protected $fields = [
'breadcrumbItem' => '.breadcrumb-item',
'breadcrumbItemLink' => '.breadcrumb-item a',
'activeBreadcrumb' => '.breadcrumb-item.active',
];

/** @var string Name by which Element is recognised */
public const ELEMENT_NAME = 'Breadcrumb';

Expand All @@ -25,4 +27,9 @@ public function clickBreadcrumbItem(string $itemName): void
{
$this->context->getElementByText($itemName, $this->fields['breadcrumbItemLink'])->click();
}

public function getActiveName(): string
{
return $this->context->findElement($this->fields['activeBreadcrumb'])->getText();
}
}
7 changes: 5 additions & 2 deletions src/lib/Behat/PageElement/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ abstract class Element
/** @var int */
public $defaultTimeout = 5;

/* \EzSystems\EzPlatformAdminUi\Behat\UtilityContext */
/* \EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext */
protected $context;

protected $fields;

public function __construct(UtilityContext $context)
{
$this->context = $context;
}

abstract public function verifyVisibility(): void;
public function verifyVisibility(): void
{
}
}
25 changes: 25 additions & 0 deletions src/lib/Behat/PageElement/LanguagePicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageElement;

use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;

class LanguagePicker extends Element
{
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->fields = [
'languageSelector' => '#content_edit_language .form-check-label',
];
}

public function chooseLanguage($language)
{
$this->context->getElementByText($language, $this->fields['languageSelector'])->click();
}
}
37 changes: 37 additions & 0 deletions src/lib/Behat/PageElement/LeftMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageElement;

use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;
use PHPUnit\Framework\Assert;

class LeftMenu extends Element
{
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->fields = [
'buttonSelector' => '.ez-sticky-container .btn',
'menuSelector' => '.ez-side-menu',
];
}

/**
* Clicks a button on the left menu (Search, Browse, Trash).
*
* @param string $buttonName
*/
public function clickButton(string $buttonName)
{
$this->context->getElementByText($buttonName, $this->fields['buttonSelector'])->click();
}

public function verifyVisibility(): void
{
Assert::assertTrue($this->context->findElement($this->fields['menuSelector'])->isVisible());
}
}
7 changes: 7 additions & 0 deletions src/lib/Behat/PageElement/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Notification extends Element
protected $fields = [
'alert' => '.alert',
'successAlert' => '.alert-success',
'failureAlert' => '.alert-danger',
];

/** @var string Name by which Element is recognised */
public const ELEMENT_NAME = 'Notification';

Expand All @@ -26,6 +28,11 @@ public function verifyAlertSuccess(): void
$this->context->assertElementOnPage($this->fields['successAlert']);
}

public function verifyAlertFailure(): void
{
$this->context->assertElementOnPage($this->fields['failureAlert']);
}

public function getMessage(): string
{
return $this->context->findElement($this->fields['alert'])->getText();
Expand Down
62 changes: 62 additions & 0 deletions src/lib/Behat/PageElement/UniversalDiscoveryWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageElement;

use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;
use PHPUnit\Framework\Assert;

class UniversalDiscoveryWidget extends Element
{
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->fields = [
'tabSelector' => '.c-tab-nav-item',
'confirmButton' => '.m-ud__action--confirm',
'selectContentButton' => '.c-meta-preview__btn--select',
'elementSelector' => '.c-finder-tree-branch:nth-of-type(%d) .c-finder-tree-leaf',
];
}

/**
* @param string $itemPath
*/
public function selectContent(string $itemPath): void
{
$pathParts = explode('/', $itemPath);
$depth = 1;
foreach ($pathParts as $part) {
$this->context->getElementByText($part, sprintf($this->fields['elementSelector'], $depth))->click();
++$depth;
}

$this->context->findElement($this->fields['selectContentButton'])->click();
}

public function confirm(): void
{
$this->context->getElementByText('Confirm', $this->fields['confirmButton'])->click();
}

public function verifyVisibility(): void
{
$this->assertExpectedTabsExist();
}

private function assertExpectedTabsExist(): void
{
$expectedTabTitles = ['Browse', 'Search'];

$actualTabTitles = [];
$tabs = $this->context->findAllWithWait($this->fields['tabSelector']);
foreach ($tabs as $tab) {
$actualTabTitles[] = $tab->getText();
}

Assert::assertArraySubset($expectedTabTitles, $actualTabTitles);
}
}
8 changes: 8 additions & 0 deletions src/lib/Behat/PageElement/UpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UpdateForm extends Element
protected $fields = [
'formElement' => '.form-group',
'mainFormSection' => '.px-5:nth-child(1) .card-body',
'richTextSelector' => '.ez-data-source__richtext',
'fieldTypesList' => '#ezrepoforms_contenttype_update_fieldTypeSelection',
'addFieldDefinition' => 'ezrepoforms_contenttype_update_addFieldDefinition',
'fieldDefinitionContainer' => '.ez-card--fieldtype-container',
Expand Down Expand Up @@ -53,6 +54,13 @@ public function fillFieldWithValue(string $fieldName, string $value, ?string $co
$fieldNode->setValue($value);
}

public function fillRichtextWithValue(string $value): void
{
$summaryField = $this->context->findElement($this->fields['richTextSelector']);
$summaryField->click();
$summaryField->setValue($value);
}

public function getContainerByHeader(string $containerName): NodeElement
{
$containerIndex = $this->context->getElementPositionByText($containerName, $this->fields['fieldDefinitionName']);
Expand Down
13 changes: 4 additions & 9 deletions src/lib/Behat/PageObject/ContentStructurePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,17 @@ public function __construct(UtilityContext $context)
$this->rightMenu = new RightMenu($this->context);
}

public function createLandingPage(string $name, string $description): void
{
$this->startCreatingContent('Landing page');
$this->context->getSession()->getPage()->findField('Title')->setValue($name);
$this->context->getSession()->getPage()->findField('Description')->setValue($description);
}

/**
* Clicks "Create" and selects Content Type in displayed search.
*
* @param $contentType
* @param string $contentType
*/
public function startCreatingContent(string $contentType): void
public function startCreatingContent(string $contentType): UpdateItemPage
{
$this->rightMenu->clickButton('Create');
$this->context->getElementByText($contentType, '.form-check-label')->click();

return PageObjectFactory::createPage($this->context, UpdateItemPage::PAGE_NAME);
}

public function verifyElements(): void
Expand Down
13 changes: 11 additions & 2 deletions src/lib/Behat/PageObject/PageObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageObject;

use EzSystems\FormBuilderBundle\Tests\Behat\PageObject\FormDeletionConfirmationPage;
use EzSystems\FormBuilderBundle\Tests\Behat\PageObject\FormDetailsPage;
use EzSystems\FormBuilderBundle\Tests\Behat\PageObject\FormManagerPage;
use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;
use EzSystems\StudioUIBundle\Tests\Behat\PageObject\LandingPageEditorPage;

Expand All @@ -16,9 +19,9 @@ class PageObjectFactory
*
* @param UtilityContext $context
* @param string $pageName Name of the Page to creator
* @param string $parameter additional parameter for constructor, e.g. name of item
* @param null[]|string[] $parameters additional parameters
*
* @return LoginPage|DashboardPage|ContentStructurePage|ContentTypeGroupsPage|UpdateItemPage|ContentTypePage to interact with
* @return LoginPage|DashboardPage|ContentStructurePage|ContentTypeGroupsPage|UpdateItemPage|ContentTypePage|FormManagerPage|FormDetailsPage|FormDeletionConfirmationPage
*/
public static function createPage(UtilityContext $context, string $pageName, ?string ...$parameters): Page
{
Expand All @@ -39,6 +42,12 @@ public static function createPage(UtilityContext $context, string $pageName, ?st
return new ContentTypePage($context, $parameters[0]);
case LandingPageEditorPage::PAGE_NAME:
return new LandingPageEditorPage($context);
case FormManagerPage::PAGE_NAME:
return new FormManagerPage($context);
case FormDetailsPage::PAGE_NAME:
return new FormDetailsPage($context, $parameters[0]);
case FormDeletionConfirmationPage::PAGE_NAME:
return new FormDeletionConfirmationPage($context);
default:
throw new \InvalidArgumentException(sprintf('Unrecognised page name: %s', $pageName));
}
Expand Down

0 comments on commit 2456675

Please sign in to comment.