Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-28172 behat specs for content types #339

Merged
merged 5 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ adminui:
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\UpdateContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\RightMenuContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\NotificationContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\ContentTypeContext
83 changes: 83 additions & 0 deletions features/ContentType.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Feature: Content types management
As an administrator
In order to customize my eZ installation
I want to manage my Content types.

Background:
Given I am logged as "admin"
And I go to "Content Types" in "Admin" tab
And I go to "Content" "Content Type Group" page

@javascript @common
Scenario: Changes can be discarded while creating Content Type
When I start creating new "Content Type" in "Content"
And I set fields
| label | value |
| Name | Test CT |
| Identifier | iTestCT |
And I click on the edit action bar button "Discard changes"
Then I should be on "Content Type Group" "Content" page
And there's no "Test CT" on "Content" "Content Type Group" list

@javascript @common
Scenario: New Content Type can be added to Content Type Group
When I start creating new "Content Type" in "Content"
And I set fields
| label | value |
| Name | Test CT |
| Identifier | iTestCT |
| Content name pattern | <name> |
And I add field "Country" to Content Type definition
And I set "Name" in "ezcountry" to "CountryField"
And I click on the edit action bar button "Save"
Then I should be on "Content Type" "Test CT" page
And Content Type has proper Global properties
| label | value |
| Name | Test CT |
| Identifier | iTestCT |
| Content name schema | <name> |
And Content Type "Test CT" has field "CountryField" of type "ezcountry"
And notification that "Content type" "Test CT" is updated appears

@javascript @common
Scenario: I can navigate to Content Type Group through breadcrumb
Given I go to "Test CT" "Content Type" page from "Content"
When I click on "Content" on breadcrumb
Then I should be on "Content Type Group" "Content" page

@javascript @common
Scenario: Changes can be discarded while editing Content type
Given there's "Test CT" on "Content" "Content Type Group" list
When I start editing "Content Type" "Test CT" from "Content"
And I set "Name" to "Test CT edited"
And I click on the edit action bar button "Discard changes"
Then I should be on "Content Type Group" "Content" page
And there's "Test CT" on "Content" "Content Type Group" list
And there's no "Test CT edited" on "Content" "Content Type Group" list

@javascript @common
Scenario: New Field can be added while editing Content Type
Given there's "Test CT" on "Content" "Content Type Group" list
When I start editing "Content Type" "Test CT" from "Content"
And I set "Name" to "Test CT edited"
And I add field "Date" to Content Type definition
And I set "Name" in "ezdate" to "DateField"
And I click on the edit action bar button "Save"
Then I should be on "Content Type" "Test CT edited" page
And Content Type has proper Global properties
| label | value |
| Name | Test CT edited |
| Identifier | iTestCT |
| Content name schema | <name> |
And Content Type "Test CT" has proper fields
| fieldName | fieldType |
| CountryField | ezcountry |
| DateField | ezdate |
And notification that "Content type" "Test CT edited" is updated appears

@javascript @common
Scenario: Content type can be deleted from Content Type Group
Given there's "Test CT edited" on "Content" "Content Type Group" list
When I delete "Content Type" "Test CT edited" from "Content"
Then there's no "Test CT edited" on "Content" "Content Type Group" list
And notification that "Content type" "Test CT edited" is deleted appears
2 changes: 1 addition & 1 deletion features/ContentTypeGroup.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Content types management
Feature: Content type groups management
As an administrator
In order to customize my eZ installation
I want to manage my Content types structure.
Expand Down
36 changes: 21 additions & 15 deletions src/lib/Behat/BusinessContext/AdministrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Behat\Mink\Exception\ElementNotFoundException;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\Dialog;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\ElementFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentTypeGroupPage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentTypeGroupsPage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;

Expand All @@ -17,7 +18,7 @@ class AdministrationContext extends BusinessContext
{
private $itemCreateMapping = [
'Content Type Group' => ContentTypeGroupsPage::PAGE_NAME,
'Content Type' => '',
'Content Type' => ContentTypeGroupPage::PAGE_NAME,
'Language' => '',
'Role' => '',
'Section' => '',
Expand All @@ -42,26 +43,27 @@ public function iSeeList(string $pageName, string $parameter = null): void

/**
* @When I start creating new :newItemType
* @When I start creating new :newItemType in :containerItem
*
* @param string $newItemType
*/
public function iStartCreatingNew(string $newItemType): void
public function iStartCreatingNew(string $newItemType, ?string $containerItem = null): void
{
if (!array_key_exists($newItemType, $this->itemCreateMapping)) {
throw new \InvalidArgumentException(sprintf('Unrecognized item type name: %s', $newItemType));
}
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$newItemType])
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$newItemType], $containerItem)
->adminList->clickPlusButton();
}

/**
* @Then there's :listElementName on :page list
* @Then there's :listElementName on :parameter :page list
*/
public function isElementOnTheList(string $listElementName, string $page): void
public function isElementOnTheList(string $listElementName, string $page, ?string $parameter = null): void
{
$isElementOnTheList = PageObjectFactory::createPage($this->utilityContext, $page)
->adminList->isElementOnList($listElementName);
$isElementOnTheList = PageObjectFactory::createPage($this->utilityContext, $page, $parameter)
->adminList->isLinkedItemOnList($listElementName);

if (!$isElementOnTheList) {
throw new ElementNotFoundException(
Expand All @@ -78,7 +80,7 @@ public function isElementOnTheList(string $listElementName, string $page): void
public function isElementNotOnTheList(string $listElementName, string $page, string $parameter = null): void
{
$isElementOnTheList = PageObjectFactory::createPage($this->utilityContext, $page, $parameter)
->adminList->isElementOnList($listElementName);
->adminList->isLinkedItemOnList($listElementName);

if ($isElementOnTheList) {
throw new ElementNotFoundException(
Expand Down Expand Up @@ -145,31 +147,35 @@ public function itemCannotBeSelected(string $itemType, string $itemName): void

/**
* @Given I go to :itemName :itemType page
* @Given I go to :itemName :itemType page from :itemContainer
*/
public function iGoToListItem(string $itemName, string $itemType): void
public function iGoToListItem(string $itemName, string $itemType, string $itemContainer = null): void
{
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType])
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType], $itemContainer)
->adminList->clickListElement($itemName);
}

/**
* @When I start editing :itemType :itemName
* @When I start editing :itemType :itemName from :containerName
*/
public function iStartEditingItem(string $itemType, string $itemName): void
public function iStartEditingItem(string $itemType, string $itemName, ?string $containerName = null): void
{
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType])
PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType], $containerName)
->adminList->clickEditButton($itemName);
}

/**
* @When I delete :itemType :itemName
* @When I delete :itemType :itemName from :itemContainer
*/
public function iDeleteItem(string $itemType, string $itemName): void
public function iDeleteItem(string $itemType, string $itemName, ?string $itemContainer = null): void
{
$contentTypeGroups = PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType]);
$contentTypeGroups = PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType], $itemContainer);
$contentTypeGroups->adminList->selectListElement($itemName);
$contentTypeGroups->adminList->clickTrashButton();
ElementFactory::createElement($this->utilityContext, Dialog::ELEMENT_NAME)
->confirm();
$dialog = ElementFactory::createElement($this->utilityContext, Dialog::ELEMENT_NAME);
$dialog->verifyVisibility();
$dialog->confirm();
}
}
7 changes: 6 additions & 1 deletion src/lib/Behat/BusinessContext/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
class AuthenticationContext extends BusinessContext
{
/** @var array Dictionary of known user logins and their passwords */
private $userCredentials = ['admin' => 'publish', 'jessica' => 'publish', 'yura' => 'publish', 'anil' => 'publish'];
private $userCredentials = [
'admin' => 'publish',
'jessica' => 'publish',
'yura' => 'publish',
'anil' => 'publish',
];

/**
* @When I login as :username with password :password
Expand Down
66 changes: 66 additions & 0 deletions src/lib/Behat/BusinessContext/ContentTypeContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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\BusinessContext;

use Behat\Gherkin\Node\TableNode;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentTypePage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;

class ContentTypeContext extends BusinessContext
{
/**
* @Then Content Type has proper Global properties
*/
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->getCellValueFromVerticalOrientedTable($row['label']);
if ($actualValue !== $row['value']) {
throw new \Exception(
sprintf(
'Content Type has wrong %s - actual: %s, expected: %s.',
$row['label'],
$actualValue,
$row['value']
));
}
}
}

/**
* @Then Content Type :contentTypeName has field :fieldName of type :fieldType
*/
public function contentTypeHasField(string $contentTypeName, string $fieldName, string $fieldType): void
{
$actualFieldType = PageObjectFactory::createPage($this->utilityContext, ContentTypePage::PAGE_NAME, $contentTypeName)
->contentAdminList->getCellValueFromDoubleHeaderTable('Type', $fieldName);

if ($actualFieldType !== $fieldType) {
throw new \Exception(
sprintf(
'Content Type field %s has wrong type - actual: %s, expected: %s.',
$fieldName,
$actualFieldType,
$fieldType
));
}
}

/**
* @Then Content Type :contentTypeName has proper fields
*/
public function contentTypeHasProperFields(string $contentTypeName, TableNode $table): void
{
$contentTypePage = PageObjectFactory::createPage($this->utilityContext, ContentTypePage::PAGE_NAME, $contentTypeName);
$hash = $table->getHash();
foreach ($hash as $row) {
$this->contentTypeHasField($contentTypeName, $row['fieldName'], $row['fieldType']);
}
}
}
34 changes: 33 additions & 1 deletion src/lib/Behat/BusinessContext/UpdateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;

use Behat\Gherkin\Node\TableNode;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\UpdateItemPage;

Expand All @@ -19,6 +20,37 @@ class UpdateContext extends BusinessContext
public function fillFieldWithValue(string $field, string $value = ''): void
{
PageObjectFactory::createPage($this->utilityContext, UpdateItemPage::PAGE_NAME)
->updateForm->fillFIeldWithValue($field, $value);
->updateForm->fillFieldWithValue($field, $value);
}

/**
* @When I set fields
*/
public function iSetFields(TableNode $table): void
{
$hash = $table->getHash();
foreach ($hash as $row) {
$this->fillFieldWithValue($row['label'], $row['value']);
}
}

/**
* @When I add field :fieldName to Content Type definition
*/
public function iAddField(string $fieldName): void
{
$updateItemPage = PageObjectFactory::createPage($this->utilityContext, UpdateItemPage::PAGE_NAME);
$updateItemPage->updateForm->selectFieldDefinition($fieldName);
$updateItemPage->updateForm->clickAddFieldDefinition();
$updateItemPage->updateForm->verifyNewFieldDefinitionFormExists($fieldName);
}

/**
* @When I set :field in :containerName to :value
*/
public function iSetFieldInContainer(string $field, string $containerName, string $value): void
{
PageObjectFactory::createPage($this->utilityContext, UpdateItemPage::PAGE_NAME)
->updateForm->fillFieldWithValue($field, $value, sprintf('New FieldDefinition (%s)', $containerName));
}
}
Loading