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 Covering of Content Types #312

Merged
merged 4 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ matrix:
- php: 7.1
env: PHPUNIT_CONFIG='phpunit.xml'
- php: 7.1
env: BEHAT_OPTS="--profile=adminui --suite=adminui" SYMFONY_ENV=behat
env: BEHAT_OPTS="--profile=adminui --suite=adminui --no-interaction" SYMFONY_ENV=behat

env:
global:
Expand Down
15 changes: 10 additions & 5 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ adminui:
suites:
adminui:
paths:
- '%paths.base%/vendor/ezsystems/ezplatform-admin-ui/src/features'
- '%paths.base%/vendor/ezsystems/ezplatform-admin-ui/features'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 😄 We should close https://jira.ez.no/browse/EZP-28693 after it's merged, for clarity

filters:
tags: "@common"
contexts:
- EzSystems\EzPlatformAdminUi\Behat\UtilityContext
- EzSystems\EzPlatformAdminUi\Behat\AuthenticationContext
- EzSystems\EzPlatformAdminUi\Behat\NavigationContext
- EzSystems\EzPlatformAdminUi\Behat\Hooks
- EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext
- EzSystems\EzPlatformAdminUi\Behat\Helper\Hooks
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\AuthenticationContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\NavigationContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\AdministrationContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\ContentViewContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\UpdateContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\RightMenuContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\NotificationContext
File renamed without changes.
63 changes: 63 additions & 0 deletions features/ContentTypeGroup.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Feature: Content types management
As an administrator
In order to customize my eZ installation
I want to manage my Content types structure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First two steps of every scenario can be extracted to a Background section:

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

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

@javascript @common
Scenario: Changes can be discarded while creating new Content Type Group
When I start creating new "Content Type Group"
And I set "Name" to "Test CTG"
And I click on the edit action bar button "Discard changes"
Then I should be on "Content Type Groups" page
And I should see "Content Type Groups" list
And there's no "Test CTG" on "Content Type Groups" list

@javascript @common
Scenario: New Content Type Group can be added
When I start creating new "Content Type Group"
And I set "Name" to "Test CTG"
And I click on the edit action bar button "Create"
Then I should be on "Content Type Group" "Test CTG" page

@javascript @common
Scenario: I can navigate to Admin / Content Types through breadcrumb
Given I go to "Test CTG" "Content Type Group" page
When I click on "Content Types" on breadcrumb
Then I should be on "Content Type Groups" page
And I should see "Content Type Groups" list

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

@javascript @common
Scenario: Content Type Group can be edited
Given there's "Test CTG" on "Content Type Groups" list
When I start editing "Content Type Group" "Test CTG"
And I set "Name" to "Test CTG edited"
And I click on the edit action bar button "Save"
Then I should be on "Content Type Group" "Test CTG edited" page
And notification that "Content type group" "Test CTG" is updated appears

@javascript @common
Scenario: Content type group can be deleted
Given there's empty "Test CTG edited" on "Content Type Groups" list
When I delete "Content Type Group" "Test CTG edited"
Then there's no "Test CTG edited" on "Content Type Groups" list
And notification that "Content type group" "Test CTG edited" is deleted appears

@javascript @common
Scenario: Non-empty Content type group cannot be deleted
Given there's non-empty "Content" on "Content Type Groups" list
Then "Content Type Group" "Content" cannot be selected
175 changes: 175 additions & 0 deletions src/lib/Behat/BusinessContext/AdministrationContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?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\Mink\Exception\ElementNotFoundException;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\Dialog;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\ElementFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentTypeGroupsPage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;

/** Context for common actions (creating, editing, deleting, etc) in Admin pages (Content Types, Languages, etc.) */
class AdministrationContext extends BusinessContext
{
private $itemCreateMapping = [
'Content Type Group' => ContentTypeGroupsPage::PAGE_NAME,
'Content Type' => '',
'Language' => '',
'Role' => '',
'Section' => '',
'User' => '',
];
private $emptyHeaderMapping = [
'Content Type Groups' => 'Content Types count',
'Sections' => 'Assigned Content items',
];

/**
* @Then I should see :pageName list
* @Then I should see :pageName :parameter list
*
* @param string $pageName
*/
public function iSeeList(string $pageName, string $parameter = null): void
{
$contentTypeGroupsPage = PageObjectFactory::createPage($this->utilityContext, $pageName, $parameter);
$contentTypeGroupsPage->verifyElements();
}

/**
* @When I start creating new :newItemType
*
* @param string $newItemType
*/
public function iStartCreatingNew(string $newItemType): 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])
->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
{
$isElementOnTheList = PageObjectFactory::createPage($this->utilityContext, $page)
->adminList->isElementOnList($listElementName);

if (!$isElementOnTheList) {
throw new ElementNotFoundException(
$this->utilityContext->getSession(),
sprintf('Element "%s" is not on the %s list.', $listElementName, $page)
);
}
}

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

if ($isElementOnTheList) {
throw new ElementNotFoundException(
$this->utilityContext->getSession(),
sprintf('Element "%s" is on the %s list.', $listElementName, $page)
);
}
}

/**
* Check if item is or is not empty, according to $empty param.
*
* @param string $itemName
* @param string $page
* @param string $shouldBeEmpty
*/
private function verifyContentsStatus(string $itemName, string $page, string $shouldBeEmpty): void
{
$emptyContainerCellValue = '0';

$contentsCount = PageObjectFactory::createPage($this->utilityContext, $page)
->adminList->getListItemAttribute($itemName, $this->emptyHeaderMapping[$page]);

$msg = '';
if ($shouldBeEmpty) {
$msg = ' non';
}

if (($contentsCount !== $emptyContainerCellValue) === $shouldBeEmpty) {
throw new ElementNotFoundException(
$this->utilityContext->getSession(),
sprintf('No%s empty %s on the %s list.', $msg, $itemName, $page));
}
}

/**
* @Given there's empty :itemName on :page list
*/
public function isEmptyElementOnTheList(string $itemName, string $page): void
{
$this->verifyContentsStatus($itemName, $page, true);
}

/**
* @Given there's non-empty :itemName on :page list
*/
public function isNonEmptyElementOnTheList(string $itemName, string $page): void
{
$this->verifyContentsStatus($itemName, $page, false);
}

/**
* @Then :itemType :itemName cannot be selected
*/
public function itemCannotBeSelected(string $itemType, string $itemName): void
{
$isListElementSelectable = PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType])
->adminList->isListElementSelectable($itemName);

if ($isListElementSelectable) {
throw new \Exception(sprintf('Element %s shoudn\'t be selectable.', $itemName));
}
}

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

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

/**
* @When I delete :itemType :itemName
*/
public function iDeleteItem(string $itemType, string $itemName): void
{
$contentTypeGroups = PageObjectFactory::createPage($this->utilityContext, $this->itemCreateMapping[$itemType]);
$contentTypeGroups->adminList->selectListElement($itemName);
$contentTypeGroups->adminList->clickTrashButton();
ElementFactory::createElement($this->utilityContext, Dialog::ELEMENT_NAME)
->confirm();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* @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;
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;

use EzSystems\EzPlatformAdminUi\Behat\PageObject\LoginPage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;
use OutOfBoundsException;

/** Context for authentication actions */
class AuthenticationContext extends BusinessContext
{
/** @var array Dictionary of known user logins and their passwords */
Expand All @@ -34,7 +35,7 @@ public function iLoginAs(string $username, string $password): void
*
* @throws \OutOfBoundsException when username is not recognised
*/
public function iAmLoggedAs(string $username)
public function iAmLoggedAs(string $username): void
{
$loginPage = PageObjectFactory::createPage($this->utilityContext, LoginPage::PAGE_NAME);
$loginPage->open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* @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;
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;

abstract class BusinessContext implements Context
{
Expand Down
32 changes: 32 additions & 0 deletions src/lib/Behat/BusinessContext/ContentViewContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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 EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentStructurePage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;
use PHPUnit\Framework\Assert;

class ContentViewContext extends BusinessContext
{
/**
* @Given I start creating a new Landing Page :name
*/
public function startCreatingNewLandingPage(string $name): void
{
$contentStructurePage = PageObjectFactory::createPage($this->utilityContext, ContentStructurePage::PAGE_NAME);
$contentStructurePage->createLandingPage($name, 'Test Desc');
}

/**
* @Then I (should) see :title title/topic
*/
public function iSeeTitle(string $title): void
{
$contentStructurePage = PageObjectFactory::createPage($this->utilityContext, ContentStructurePage::PAGE_NAME);
Assert::assertEquals($title, $contentStructurePage->getPageHeaderTitle());
}
}
Loading