Skip to content

Commit

Permalink
EZP-29117 - fix behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-tyrala committed Apr 20, 2018
1 parent 0145ae1 commit 7107e41
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
24 changes: 14 additions & 10 deletions src/lib/Behat/BusinessContext/ContentTypeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use Behat\Gherkin\Node\TableNode;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentTypePage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;
use PHPUnit\Framework\Assert;

class ContentTypeContext extends BusinessContext
{
private $contentTypeTableHeaders = ['Name', 'Identifier', 'Description'];

/**
* @Then Content Type has proper Global properties
*/
Expand All @@ -20,16 +23,17 @@ public function contentTypeHasProperGlobalProperties(TableNode $table): void
$hash = $table->getHash();
$contentTypePage = PageObjectFactory::createPage($this->utilityContext, ContentTypePage::PAGE_NAME, $hash[0]['value']);
foreach ($hash as $row) {
$actualValue = $contentTypePage->globalPropertiesAdminList->table->getTableCellValue($row['label']);
if ($actualValue !== $row['value']) {
throw new \Exception(
sprintf(
'Content Type has wrong %s - actual: %s, expected: %s.',
$row['label'],
$actualValue,
$row['value']
));
if (in_array($row['label'], $this->contentTypeTableHeaders)) {
$actualValue = $contentTypePage->contentTypeAdminList->table->getTableCellValue($row['label']);
} else {
$actualValue = $contentTypePage->globalPropertiesTable->getTableCellValue($row['label']);
}

Assert::assertEquals(
$row['value'],
$actualValue,
sprintf('Content Type has wrong %s - actual: %s, expected: %s.', $row['label'], $actualValue, $row['value'])
);
}
}

Expand All @@ -39,7 +43,7 @@ public function contentTypeHasProperGlobalProperties(TableNode $table): void
public function contentTypeHasField(string $contentTypeName, string $fieldName, string $fieldType): void
{
$actualFieldType = PageObjectFactory::createPage($this->utilityContext, ContentTypePage::PAGE_NAME, $contentTypeName)
->contentAdminList->table->getTableCellValue('Type', $fieldName);
->fieldsAdminList->table->getTableCellValue('Type', $fieldName);

if ($actualFieldType !== $fieldType) {
throw new \Exception(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Behat/PageElement/AdminList.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(UtilityContext $context, string $listHeader, string

public function verifyVisibility(): void
{
$actualHeader = $this->context->getElementByTextFragment($this->listHeader, $this->fields['listHeader'], null, $this->listContainer);
$actualHeader = $this->context->getElementByTextFragment($this->listHeader, $this->fields['list'] . ' ' . $this->fields['listHeader']);
if ($actualHeader === null) {
Assert::fail(sprintf('Table header "%s" not found on page', $this->listHeader));
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Behat/PageElement/SystemInfoTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function getTableCellValue(string $header, ?string $secondHeader = null):
{
$columnPosition = $this->context->getElementPositionByText(
$header,
$this->fields['horizontalHeaders']
$this->fields['listElement']
);

return $this->getCellValue(1, $columnPosition);
return $this->getCellValue($columnPosition, 2);
}

public function verifyHeader(string $header): void
Expand Down
37 changes: 26 additions & 11 deletions src/lib/Behat/PageObject/ContentTypePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use EzSystems\EzPlatformAdminUi\Behat\PageElement\AdminList;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\DoubleHeaderTable;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\ElementFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\VerticalOrientedTable;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\SimpleTable;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\SystemInfoTable;

class ContentTypePage extends Page
{
Expand All @@ -20,42 +21,56 @@ class ContentTypePage extends Page
public $contentTypeName;

/** @var string locator for container of Content list */
public $secondListContainerLocator = 'section:nth-of-type(2)';
public $contentFieldDefinitionsListLocator = 'section:nth-of-type(2)';

/** @var string locator for container of Content list */
public $globalPropertiesTableLocator = '.ez-table--list';

/**
* @var \EzSystems\EzPlatformAdminUi\Behat\PageElement\AdminList
*/
public $globalPropertiesAdminList;
public $globalPropertiesTable;
/**
* @var \EzSystems\EzPlatformAdminUi\Behat\PageElement\AdminList
*/
public $contentAdminList;
public $fieldsAdminList;

/**
* @var \EzSystems\EzPlatformAdminUi\Behat\PageElement\AdminList
*/
public $contentTypeAdminList;

public function __construct(UtilityContext $context, string $contentTypeName)
{
parent::__construct($context);
$this->groupName = $contentTypeName;
$this->route = '/admin/contenttypegroup/';
$this->globalPropertiesAdminList = ElementFactory::createElement(

$this->contentTypeAdminList = ElementFactory::createElement(
$this->context,
AdminList::ELEMENT_NAME,
'Global properties',
VerticalOrientedTable::ELEMENT_NAME
'Content Type',
SimpleTable::ELEMENT_NAME
);
$this->globalPropertiesTable = ElementFactory::createElement(
$this->context,
SystemInfoTable::ELEMENT_NAME,
$this->globalPropertiesTableLocator
);
$this->contentAdminList = ElementFactory::createElement(
$this->fieldsAdminList = ElementFactory::createElement(
$this->context,
AdminList::ELEMENT_NAME,
'Content',
DoubleHeaderTable::ELEMENT_NAME,
$this->secondListContainerLocator
$this->contentFieldDefinitionsListLocator
);
$this->pageTitle = $contentTypeName;
$this->pageTitleLocator = '.ez-header h1';
}

public function verifyElements(): void
{
$this->globalPropertiesAdminList->verifyVisibility();
$this->contentAdminList->verifyVisibility();
$this->contentTypeAdminList->verifyVisibility();
$this->fieldsAdminList->verifyVisibility();
}
}

0 comments on commit 7107e41

Please sign in to comment.