diff --git a/behat_suites.yml b/behat_suites.yml index 08ac3da95..e5ac07041 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -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 diff --git a/features/User/Registration/user_registration.feature b/features/User/Registration/user_registration.feature index 25b223299..99e8b6e9a 100644 --- a/features/User/Registration/user_registration.feature +++ b/features/User/Registration/user_registration.feature @@ -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 @@ -29,6 +26,9 @@ Scenario: The user group where registered users are created can be customized default: user_registration: group_id: + site_group: + user_registration: + group_id: """ When I register a user account Then the user is created in this user group diff --git a/features/Context/ContentEdit.php b/lib/Behat/Context/ContentEditContext.php similarity index 92% rename from features/Context/ContentEdit.php rename to lib/Behat/Context/ContentEditContext.php index d0d953cbf..ccd5598dd 100644 --- a/features/Context/ContentEdit.php +++ b/lib/Behat/Context/ContentEditContext.php @@ -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; @@ -10,7 +10,7 @@ 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. @@ -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; @@ -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'); } /** @@ -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(); } /** diff --git a/features/Context/ContentType.php b/lib/Behat/Context/ContentTypeContext.php similarity index 96% rename from features/Context/ContentType.php rename to lib/Behat/Context/ContentTypeContext.php index 89018e164..858e1d000 100644 --- a/features/Context/ContentType.php +++ b/lib/Behat/Context/ContentTypeContext.php @@ -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; @@ -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; diff --git a/features/Context/FieldTypeFormContext.php b/lib/Behat/Context/FieldTypeFormContext.php similarity index 97% rename from features/Context/FieldTypeFormContext.php rename to lib/Behat/Context/FieldTypeFormContext.php index f8e06f15a..abb1c31bd 100644 --- a/features/Context/FieldTypeFormContext.php +++ b/lib/Behat/Context/FieldTypeFormContext.php @@ -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; @@ -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'); } /** diff --git a/features/Context/PagelayoutContext.php b/lib/Behat/Context/PagelayoutContext.php similarity index 61% rename from features/Context/PagelayoutContext.php rename to lib/Behat/Context/PagelayoutContext.php index 84d1e5cb6..d4b4fec77 100644 --- a/features/Context/PagelayoutContext.php +++ b/lib/Behat/Context/PagelayoutContext.php @@ -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 @@ -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'); + } + } } diff --git a/features/Context/SelectionFieldTypeFormContext.php b/lib/Behat/Context/SelectionFieldTypeFormContext.php similarity index 94% rename from features/Context/SelectionFieldTypeFormContext.php rename to lib/Behat/Context/SelectionFieldTypeFormContext.php index 41dc417a6..aa240b62d 100644 --- a/features/Context/SelectionFieldTypeFormContext.php +++ b/lib/Behat/Context/SelectionFieldTypeFormContext.php @@ -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; @@ -14,7 +14,7 @@ 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; @@ -22,7 +22,7 @@ final class SelectionFieldTypeFormContext extends RawMinkContext implements Snip public function gatherContexts(BeforeScenarioScope $scope) { $this->fieldTypeFormContext = $scope->getEnvironment()->getContext( - 'EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext' + 'EzSystems\RepositoryForms\Behat\Context\FieldTypeFormContext' ); } diff --git a/features/Context/UserRegistrationContext.php b/lib/Behat/Context/UserRegistrationContext.php similarity index 94% rename from features/Context/UserRegistrationContext.php rename to lib/Behat/Context/UserRegistrationContext.php index 96b2b7681..461b8bd05 100644 --- a/features/Context/UserRegistrationContext.php +++ b/lib/Behat/Context/UserRegistrationContext.php @@ -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; @@ -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; @@ -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')); @@ -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); } @@ -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')); } /**