Skip to content

Commit

Permalink
EZP-29143 run test features on Demo version without changing feature …
Browse files Browse the repository at this point in the history
…files (#250)

* EZP-29143 run test features on Demo version without changing feature files

* EZP-29143 run test features on Demo version without changing feature files - review changes
  • Loading branch information
m-tyrala authored and Łukasz Serwatka committed Aug 23, 2018
1 parent 1602dc8 commit b6cc9c8
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 36 deletions.
16 changes: 9 additions & 7 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ repository-forms:
paths:
- vendor/ezsystems/repository-forms/features/ContentEdit
contexts:
- EzSystems\RepositoryForms\Features\Context\ContentEdit
- EzSystems\RepositoryForms\Features\Context\ContentType
- EzSystems\RepositoryForms\Features\Context\PagelayoutContext
- EzSystems\RepositoryForms\Behat\Context\ContentEditContext
- EzSystems\RepositoryForms\Behat\Context\ContentTypeContext
- EzSystems\RepositoryForms\Behat\Context\PagelayoutContext
- EzSystems\EzPlatformAdminUi\Behat\Helper\Hooks
fieldtype_form:
paths:
- vendor/ezsystems/repository-forms/features/FieldTypeForm
contexts:
- EzSystems\RepositoryForms\Features\Context\ContentType
- EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext
- EzSystems\RepositoryForms\Features\Context\SelectionFieldTypeFormContext
- EzSystems\RepositoryForms\Behat\Context\ContentTypeContext
- EzSystems\RepositoryForms\Behat\Context\FieldTypeFormContext
- EzSystems\RepositoryForms\Behat\Context\SelectionFieldTypeFormContext
user_registration:
paths:
- vendor/ezsystems/repository-forms/features/User/Registration
contexts:
- EzSystems\RepositoryForms\Features\Context\UserRegistrationContext
- EzSystems\RepositoryForms\Behat\Context\UserRegistrationContext
- Behat\MinkExtension\Context\MinkContext
- eZ\Bundle\EzPublishCoreBundle\Features\Context\YamlConfigurationContext
- EzSystems\EzPlatformAdminUi\Behat\Helper\Hooks
10 changes: 5 additions & 5 deletions features/User/Registration/user_registration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ Scenario: Registration is disabled for users who do not have the "user/register"

Scenario: A new user account can be registered from "/register"
Given I do have the user/register policy
And I go to "/register"
Then I can see the registration form
And it matches the structure of the configured registration user Content Type
And it has a register button
When I fill in the form with valid values
When I go to "/register"
And I fill in the form with valid values
And I click on the register button
Then I am on the registration confirmation page
And I see a registration confirmation message
Expand All @@ -29,6 +26,9 @@ Scenario: The user group where registered users are created can be customized
default:
user_registration:
group_id: <userGroupContentId>
site_group:
user_registration:
group_id: <userGroupContentId>
"""
When I register a user account
Then the user is created in this user group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\MinkContext;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct;

final class ContentEdit extends MinkContext implements Context, SnippetAcceptingContext
final class ContentEditContext extends MinkContext implements Context, SnippetAcceptingContext
{
/**
* Name of the content that was created using the edit form. Used to validate that the content was created.
Expand All @@ -19,7 +19,7 @@ final class ContentEdit extends MinkContext implements Context, SnippetAccepting
private $createdContentName;

/**
* @var \EzSystems\RepositoryForms\Features\Context\ContentType
* @var \EzSystems\RepositoryForms\Behat\Context\ContentTypeContext
*/
private $contentTypeContext;

Expand All @@ -34,7 +34,7 @@ public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();

$this->contentTypeContext = $environment->getContext('EzSystems\RepositoryForms\Features\Context\ContentType');
$this->contentTypeContext = $environment->getContext('EzSystems\RepositoryForms\Behat\Context\ContentTypeContext');
}

/**
Expand Down Expand Up @@ -75,9 +75,9 @@ public function iFillInTheFolderEditForm()
public function thatIHavePermissionToCreateFolders()
{
$this->visit('/login');
$this->fillField('Username', 'admin');
$this->fillField('Password', 'publish');
$this->pressButton('Login');
$this->fillField('_username', 'admin');
$this->fillField('_password', 'publish');
$this->getSession()->getPage()->find('css', 'form')->submit();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
Expand All @@ -16,7 +16,7 @@
use EzSystems\PlatformBehatBundle\Context\RepositoryContext;
use PHPUnit\Framework\Assert as Assertion;

final class ContentType extends RawMinkContext implements Context, SnippetAcceptingContext
final class ContentTypeContext extends RawMinkContext implements Context, SnippetAcceptingContext
{
use RepositoryContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
Expand All @@ -22,14 +22,14 @@ final class FieldTypeFormContext extends RawMinkContext implements SnippetAccept
'selection' => 'ezselection',
];

/** @var \EzSystems\RepositoryForms\Features\Context\ContentType */
/** @var \EzSystems\RepositoryForms\Behat\Context\ContentTypeContext */
private $contentTypeContext;

/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
$this->contentTypeContext = $environment->getContext('EzSystems\RepositoryForms\Features\Context\ContentType');
$this->contentTypeContext = $environment->getContext('EzSystems\RepositoryForms\Behat\Context\ContentTypeContext');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\RawMinkContext;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\Behat\Helper\EzEnvironmentConstants;
use EzSystems\EzPlatformAdminUi\Behat\Helper\InstallType;
use PHPUnit\Framework\Assert as Assertion;

class PagelayoutContext extends RawMinkContext implements Context, SnippetAcceptingContext
Expand Down Expand Up @@ -41,8 +43,24 @@ public function aPagelayoutIsConfigured()
*/
public function itIsRenderedUsingTheConfiguredPagelayout()
{
$pageLayout = $this->configResolver->getParameter('pagelayout');
$pageLayout = $this->getPageLayout();

$searchedPattern = sprintf(self::TWIG_DEBUG_STOP_REGEX, preg_quote($pageLayout, null));
Assertion::assertRegExp($searchedPattern, $this->getSession()->getPage()->getOuterHtml());
}

public function getPageLayout(): string
{
$installType = EzEnvironmentConstants::getInstallType();
switch ($installType) {
case InstallType::PLATFORM:
case InstallType::ENTERPRISE:
return $this->configResolver->getParameter('pagelayout', null, 'site');
case InstallType::PLATFORM_DEMO:
case InstallType::ENTERPRISE_DEMO:
return str_replace('@ezdesign', 'app/Resources/views/themes/tastefulplanet', $this->configResolver->getParameter('pagelayout', null, 'site'));
default:
throw new \Exception('Unrecognised install type');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
Expand All @@ -14,15 +14,15 @@ final class SelectionFieldTypeFormContext extends RawMinkContext implements Snip
private static $fieldIdentifier = 'field';

/**
* @var \EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext
* @var \EzSystems\RepositoryForms\Behat\Context\FieldTypeFormContext
*/
private $fieldTypeFormContext;

/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$this->fieldTypeFormContext = $scope->getEnvironment()->getContext(
'EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext'
'EzSystems\RepositoryForms\Behat\Context\FieldTypeFormContext'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @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\RepositoryForms\Features\Context;
namespace EzSystems\RepositoryForms\Behat\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
Expand All @@ -18,6 +18,7 @@
use eZ\Publish\API\Repository\Values\User\User;
use eZ\Publish\API\Repository\Values\User\UserGroup;
use eZ\Publish\Core\Repository\Values\User\RoleCreateStruct;
use EzSystems\EzPlatformAdminUi\Behat\Helper\EzEnvironmentConstants;
use EzSystems\PlatformBehatBundle\Context\RepositoryContext;
use PHPUnit\Framework\Assert as Assertion;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -128,8 +129,12 @@ private function createRegistrationRole($withUserRegisterPolicy = true)

$roleService = $this->getRepository()->getRoleService();
$roleCreateStruct = new RoleCreateStruct(['identifier' => $roleIdentifier]);
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('user', 'login'));
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'read'));

$policiesSet = explode(',', EzEnvironmentConstants::get('CREATE_REGISTRATION_ROLE_POLICIES'));
foreach ($policiesSet as $policy) {
[$module, $function] = explode('/', $policy);
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct($module, $function));
}

if ($withUserRegisterPolicy === true) {
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('user', 'register'));
Expand All @@ -156,9 +161,9 @@ private function loginAs(User $user)
{
$this->visitPath('/login');
$page = $this->getSession()->getPage();
$page->fillField('username', $user->login);
$page->fillField('password', self::$password);
$page->findButton('Login')->press();
$page->fillField('_username', $user->login);
$page->fillField('_password', self::$password);
$this->getSession()->getPage()->find('css', 'form')->submit();
$this->assertSession()->statusCodeEquals(200);
}

Expand Down Expand Up @@ -240,7 +245,7 @@ public function iAmOnTheRegistrationConfirmationPage()
*/
public function iSeeARegistrationConfirmationMessage()
{
$this->assertSession()->pageTextContains('Your account has been created');
$this->assertSession()->pageTextContains(EzEnvironmentConstants::get('REGISTRATION_CONFIRMATION_MESSAGE'));
}

/**
Expand Down

0 comments on commit b6cc9c8

Please sign in to comment.