Skip to content
Open
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
50 changes: 50 additions & 0 deletions behat_suites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

use Behat\Config\Config;
use Behat\Config\Profile;
use Behat\Config\Suite;
use Behat\MinkExtension\Context\MinkContext;
use Ibexa\Bundle\Core\Features\Context\YamlConfigurationContext;
use Ibexa\ContentForms\Behat\Context\ContentEditContext;
use Ibexa\ContentForms\Behat\Context\ContentTypeContext;
use Ibexa\ContentForms\Behat\Context\FieldTypeFormContext;
use Ibexa\ContentForms\Behat\Context\PagelayoutContext;
use Ibexa\ContentForms\Behat\Context\SelectionFieldTypeFormContext;
use Ibexa\ContentForms\Behat\Context\UserRegistrationContext;

return (new Config())
->withProfile((new Profile('setup-content-forms'))
->withSuite((new Suite('setup'))
->withContexts(
UserRegistrationContext::class,
YamlConfigurationContext::class
)
->withPaths('vendor/ibexa/content-forms/features/User/Setup')))
->withProfile((new Profile('content-forms'))
->withSuite((new Suite('content_edit'))
->withContexts(
ContentEditContext::class,
ContentTypeContext::class,
PagelayoutContext::class
)
->withPaths('vendor/ibexa/content-forms/features/ContentEdit'))
->withSuite((new Suite('fieldtype_form'))
->withContexts(
ContentTypeContext::class,
FieldTypeFormContext::class,
SelectionFieldTypeFormContext::class
)
->withPaths('vendor/ibexa/content-forms/features/FieldTypeForm'))
->withSuite((new Suite('user_registration'))
->withContexts(
UserRegistrationContext::class,
MinkContext::class,
YamlConfigurationContext::class
)
->withPaths('vendor/ibexa/content-forms/features/User/Registration')));
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"symfony/yaml": "^7.4"
},
"require-dev": {
"behat/behat": "^3.5",
"behat/behat": "^3.32 || ^4.0",
"ibexa/behat": "~6.0.x-dev",
"ibexa/code-style": "~2.0.0",
"ibexa/doctrine-schema": "~6.0.x-dev",
Expand Down
24 changes: 0 additions & 24 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ parameters:
count: 1
path: src/lib/Behat/Context/ContentTypeContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\ContentTypeContext\:\:iRemoveFieldFromContentType\(\) has parameter \$fieldIdentifier with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/Behat/Context/ContentTypeContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\ContentTypeContext\:\:newContentTypeCreateStruct\(\) has parameter \$identifier with no type specified\.$#'
identifier: missingType.parameter
Expand Down Expand Up @@ -96,30 +90,12 @@ parameters:
count: 2
path: src/lib/Behat/Context/FieldTypeFormContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\FieldTypeFormContext\:\:aContentTypeWithAGivenFieldDefinition\(\) has parameter \$contentTypeName with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/Behat/Context/FieldTypeFormContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\FieldTypeFormContext\:\:aContentTypeWithAGivenFieldDefinition\(\) has parameter \$fieldTypeIdentifier with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/Behat/Context/FieldTypeFormContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\FieldTypeFormContext\:\:getRequiredFieldTypeExceptions\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Behat/Context/FieldTypeFormContext.php

-
message: '#^Method Ibexa\\ContentForms\\Behat\\Context\\FieldTypeFormContext\:\:itShouldContainAGivenTypeInputField\(\) has parameter \$inputType with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/Behat/Context/FieldTypeFormContext.php

-
message: '#^Call to an undefined method Behat\\Testwork\\Environment\\Environment\:\:getContext\(\)\.$#'
identifier: method.notFound
Expand Down
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
SymfonySetList::SYMFONY_70,
SymfonySetList::SYMFONY_71,
SymfonySetList::SYMFONY_72,
]);
])
->withAttributesSets(behat: true);
52 changes: 17 additions & 35 deletions src/lib/Behat/Context/ContentEditContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Hook\BeforeScenario;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Step\Given;
use Behat\Step\Then;
use Behat\Step\When;
use Exception;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;

Expand All @@ -29,26 +33,22 @@ final class ContentEditContext extends MinkContext implements Context, SnippetAc
*/
private static string $constrainedFieldIdentifier = 'constrained_field';

/** @BeforeScenario */
#[BeforeScenario]
public function gatherContexts(BeforeScenarioScope $scope): void
{
$environment = $scope->getEnvironment();

$this->contentTypeContext = $environment->getContext(ContentTypeContext::class);
}

/**
* @Then /^I should see a folder content edit form$/
* @Then /^I should see a content edit form$/
*/
#[Then('/^I should see a folder content edit form$/')]
#[Then('/^I should see a content edit form$/')]
public function iShouldSeeAContentEditForm(): void
{
$this->assertSession()->elementExists('css', 'form[name=ezplatform_content_forms_content_edit]');
}

/**
* @Then /^I am on the View of the Content that was published$/
*/
#[Then('/^I am on the View of the Content that was published$/')]
public function iAmOnTheViewOfTheContentThatWasPublished(): void
{
if (!isset($this->createdContentName)) {
Expand All @@ -59,19 +59,15 @@ public function iAmOnTheViewOfTheContentThatWasPublished(): void
$this->assertElementContainsText('span.ibexa_string-field', $this->createdContentName);
}

/**
* @When /^I fill in the folder edit form$/
*/
#[When('/^I fill in the folder edit form$/')]
public function iFillInTheFolderEditForm(): void
{
// will only work for single value fields
$this->createdContentName = 'Behat content edit @' . microtime(true);
$this->fillField('ezplatform_content_forms_content_edit_fieldsData_name_value', $this->createdContentName);
}

/**
* @Given /^that I have permission to create folders$/
*/
#[Given('/^that I have permission to create folders$/')]
public function thatIHavePermissionToCreateFolders(): void
{
$this->visit('/login');
Expand All @@ -80,17 +76,13 @@ public function thatIHavePermissionToCreateFolders(): void
$this->getSession()->getPage()->find('css', 'form')->submit();
}

/**
* @Given /^that I have permission to create content of this type$/
*/
#[Given('/^that I have permission to create content of this type$/')]
public function thatIHavePermissionToCreateContentOfThisType(): void
{
$this->thatIHavePermissionToCreateFolders();
}

/**
* @When /^I go to the content creation page for this type$/
*/
#[When('/^I go to the content creation page for this type$/')]
public function iGoToTheContentCreationPageForThisType(): void
{
$uri = sprintf(
Expand All @@ -101,9 +93,7 @@ public function iGoToTheContentCreationPageForThisType(): void
$this->visit($uri);
}

/**
* @Given /^I fill in the constrained field with an invalid value$/
*/
#[Given('/^I fill in the constrained field with an invalid value$/')]
public function iFillInTheConstrainedFieldWithAnInvalidValue(): void
{
$this->fillField(
Expand All @@ -123,9 +113,7 @@ public function iFillInTheConstrainedFieldWithAnInvalidValue(): void
}
}

/**
* @Then /^I am shown the content creation form$/
*/
#[Then('/^I am shown the content creation form$/')]
public function iAmShownTheContentCreationForm(): void
{
$uri = sprintf(
Expand All @@ -142,9 +130,7 @@ public function iAmShownTheContentCreationForm(): void
);
}

/**
* @Given /^there is a relevant error message linked to the invalid field$/
*/
#[Given('/^there is a relevant error message linked to the invalid field$/')]
public function thereIsARelevantErrorMessageLinkedToTheInvalidField(): void
{
$selector = sprintf(
Expand All @@ -156,9 +142,7 @@ public function thereIsARelevantErrorMessageLinkedToTheInvalidField(): void
$this->assertSession()->elementTextContains('css', $selector, 'The string cannot be shorter than 5 characters.');
}

/**
* @Given /^that there is a content type with any kind of constraints on a Field Definition$/
*/
#[Given('/^that there is a content type with any kind of constraints on a Field Definition$/')]
public function thereIsAContentTypeWithAnyKindOfConstraintsOnAFieldDefinition(): void
{
$contentTypeCreateStruct = $this->contentTypeContext->newContentTypeCreateStruct();
Expand All @@ -179,9 +163,7 @@ public function thereIsAContentTypeWithAnyKindOfConstraintsOnAFieldDefinition():
$this->contentTypeContext->createContentType($contentTypeCreateStruct);
}

/**
* @When /^a content creation form is displayed$/
*/
#[When('/^a content creation form is displayed$/')]
public function aContentCreationFormIsDisplayed(): void
{
$this->visit('/content/create/nodraft/folder/eng-GB/2');
Expand Down
11 changes: 4 additions & 7 deletions src/lib/Behat/Context/ContentTypeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Step\Given;
use Ibexa\Contracts\Core\Repository\ContentTypeService;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
Expand All @@ -32,9 +33,7 @@ public function __construct(
$permissionResolver->setCurrentUserReference(new UserReference(14));
}

/**
* @Given /^there is a content type "([^"]*)" with the id "([^"]*)"$/
*/
#[Given('/^there is a content type "([^"]*)" with the id "([^"]*)"$/')]
public function thereIsAContentTypeWithId(string $contentTypeIdentifier, int $id): void
{
try {
Expand All @@ -45,10 +44,8 @@ public function thereIsAContentTypeWithId(string $contentTypeIdentifier, int $id
}
}

/**
* @Given I remove :fieldIdentifier field from :contentTypeIdentifier content type
*/
public function iRemoveFieldFromContentType($fieldIdentifier, string $contentTypeIdentifier): void
#[Given('I remove :fieldIdentifier field from :contentTypeIdentifier content type')]
public function iRemoveFieldFromContentType(string $fieldIdentifier, string $contentTypeIdentifier): void
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
$contentTypeDraft = $this->contentTypeService->createContentTypeDraft($contentType);
Expand Down
46 changes: 17 additions & 29 deletions src/lib/Behat/Context/FieldTypeFormContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Hook\BeforeScenario;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Step\Given;
use Behat\Step\Then;
use Behat\Step\When;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
use Webmozart\Assert\Assert as Assertion;
Expand All @@ -29,18 +33,16 @@ final class FieldTypeFormContext extends RawMinkContext implements SnippetAccept

private ContentTypeContext $contentTypeContext;

/** @BeforeScenario */
#[BeforeScenario]
public function gatherContexts(BeforeScenarioScope $scope): void
{
$environment = $scope->getEnvironment();
$this->contentTypeContext = $environment->getContext(ContentTypeContext::class);
}

/**
* @Given a content type with a(n) :fieldTypeIdentifier field definition
* @Given a content type :contentTypeName with a(n) :fieldTypeIdentifier field definition
*/
public function aContentTypeWithAGivenFieldDefinition($fieldTypeIdentifier, $contentTypeName = null): void
#[Given('a content type with a(n) :fieldTypeIdentifier field definition')]
#[Given('a content type :contentTypeName with a(n) :fieldTypeIdentifier field definition')]
public function aContentTypeWithAGivenFieldDefinition(string $fieldTypeIdentifier, ?string $contentTypeName = null): void
{
if (isset(self::$fieldTypeIdentifierMap[$fieldTypeIdentifier])) {
$fieldTypeIdentifier = self::$fieldTypeIdentifierMap[$fieldTypeIdentifier];
Expand Down Expand Up @@ -77,9 +79,7 @@ public function aContentTypeWithAGivenFieldDefinition($fieldTypeIdentifier, $con
$this->contentTypeContext->createContentType($contentTypeCreateStruct);
}

/**
* @When /^I view the edit form for this field$/
*/
#[When('/^I view the edit form for this field$/')]
public function iEditOrCreateContentOfThisType(): void
{
$this->visitPath(
Expand All @@ -90,9 +90,7 @@ public function iEditOrCreateContentOfThisType(): void
);
}

/**
* @When /^I view the edit user form for this field$/
*/
#[When('/^I view the edit user form for this field$/')]
public function iEditOrCreateContentOfUserType(): void
{
$this->visitPath(
Expand All @@ -103,9 +101,7 @@ public function iEditOrCreateContentOfUserType(): void
);
}

/**
* @Then the edit form should contain an identifiable widget for :fieldTypeIdentifier field definition
*/
#[Then('the edit form should contain an identifiable widget for :fieldTypeIdentifier field definition')]
public function theEditFormShouldContainAFieldsetNamedAfterTheFieldDefinition(string $fieldTypeIdentifier): void
{
$this->assertSession()->elementTextContains(
Expand All @@ -115,10 +111,8 @@ public function theEditFormShouldContainAFieldsetNamedAfterTheFieldDefinition(st
);
}

/**
* @Given it should contain a :type input field
*/
public function itShouldContainAGivenTypeInputField($inputType): void
#[Given('it should contain a :type input field')]
public function itShouldContainAGivenTypeInputField(string $inputType): void
{
$this->assertSession()->elementExists(
'css',
Expand All @@ -131,9 +125,7 @@ public function itShouldContainAGivenTypeInputField($inputType): void
);
}

/**
* @Given /^it should contain the following set of labels, and input fields of the following types:$/
*/
#[Given('/^it should contain the following set of labels, and input fields of the following types:$/')]
public function itShouldContainTheFollowingSetOfLabelsAndInputFieldsTypes(TableNode $table): void
{
$inputNodeElements = $this->getSession()->getPage()->findAll(
Expand All @@ -158,10 +150,8 @@ public function itShouldContainTheFollowingSetOfLabelsAndInputFieldsTypes(TableN
}
}

/**
* @Given /^the field definition is required$/
* @Given /^the field definition is marked as required$/
*/
#[Given('/^the field definition is required$/')]
#[Given('/^the field definition is marked as required$/')]
public function theFieldDefinitionIsMarkedAsRequired(): void
{
$this->contentTypeContext->updateFieldDefinition(
Expand All @@ -170,9 +160,7 @@ public function theFieldDefinitionIsMarkedAsRequired(): void
);
}

/**
* @Then the value input fields for :fieldIdentifier field should be flagged as required
*/
#[Then('the value input fields for :fieldIdentifier field should be flagged as required')]
public function theInputFieldsShouldBeFlaggedAsRequired(string $fieldTypeIdentifier): void
{
$inputNodeElements = $this->getSession()->getPage()->findAll(
Expand Down
Loading
Loading