diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 0000000..2f89d6c --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,8 @@ +# Migration + +A migration map of the step definitions available in v2 to v3. + +| V2 | V3 | +|------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **[`ParagraphsTrait`](src/ParagraphsTrait.php) ([example](tests/behat/features/paragraphs.feature))** | | +| `When :field_name in :bundle :entity_type with :entity_field_name of :entity_field_identifer has :paragraph_type paragraph:` | `Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:` | diff --git a/README.md b/README.md index f18f8eb..2be425b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ composer require --dev drevops/behat-steps:^2 ## Usage -Add required traits to your `FeatureContext.php` ([example](tests/behat/bootstrap/FeatureContext.php)): +Add required traits to your +`FeatureContext.php` ([example](tests/behat/bootstrap/FeatureContext.php)): ```php [^"]*)" user is "(?P[^"]*)" with "(?P[^"]*)" content:$/` | Assert that an email message was sent or not sent to a user with the specified content. | -| `Then an email :field contains` | Assert that an email message field contains the specified value. | -| `Then an email :field contains exact` | Assert that an email message field contains the exact specified value. | -| `Then an email :field does not contain` | Assert that an email message field does not contain the specified value. | -| `Then an email :field does not contains exact` | Assert that an email message field does not contain the exact specified value. | -| `When I follow the link number :number in the email with the subject` | Visit a link from the email with the specified subject. | -| `Then file :name attached to the email with the subject` | Assert that a file is attached to an email message with the specified subject. | -|   | | -| **[`FieldTrait`](src/FieldTrait.php) ([example](tests/behat/features/field.feature))** | | -| `Then I see field :name` | Assert that a field exists on the page using its id, name, label, or value. | -| `Then I don't see field :name` | Assert that a field does not exist on the page using its id, name, label, or value. | -| `Then field :name :exists on the page` | Assert whether the field exists on the page using its id, name, label, or value. | -| `Then field :name is :disabled on the page` | Assert whether the field is disabled on the page. | -| `Then field :name should be :presence on the page and have state :state` | Assert whether the field exists on the page and has a specified state. | -| `Then I fill color in :field for :value` | Fills value for color field. | -| `Then color field :field value is :value` | Asserts that a color field has a value. | -|   | | -| **[`FileDownloadTrait`](src/FileDownloadTrait.php) ([example](tests/behat/features/file-download.feature))** | | -| `Then I download file from :url` | Download a file from the specified URL. | -| `Then I download file from link :link` | Download a file from the specified HTML link. | -| `Then I see download :link link :presence(on the page)` | Assert that an HTML link is present or absent on the page. | -| `Then downloaded file contains:` | Assert the contents of the downloaded file. | -| `Then downloaded file name is :name` | Assert the file name of the downloaded file. | -| `Then downloaded file is zip archive that contains files:` | Assert that the downloaded file is a ZIP archive containing specified files. | -| `Then downloaded file is zip archive that does not contain files:` | Assert that the downloaded file is a ZIP archive that does not contain specified files. | -|   | | -| **[`FileTrait`](src/FileTrait.php) ([example](tests/behat/features/file.feature))** | | -| `Given managed file:` | Create a managed file with the properties provided in the table. | -| `Given no managed files:` | Delete managed files defined by the provided properties or fields. | -| `Given unmanaged file :uri created` | Create an unmanaged file. | -| `Given unmanaged file :uri created with content :content` | Create an unmanaged file with specified content. | -| `Then unmanaged file :uri exists` | Assert that an unmanaged file with the specified URI exists. | -| `Then unmanaged file :uri does not exist` | Assert that an unmanaged file with the specified URI does not exist. | -| `Then unmanaged file :uri has content :content` | Assert that an unmanaged file exists and has the specified content. | -| `Then unmanaged file :uri does not have content :content` | Assert that an unmanaged file exists and does not have the specified content. | -|   | | -| **[`JsTrait`](src/JsTrait.php) ([example](tests/behat/features/js.feature))** | | -| `When I accept confirmation dialogs` | Accept confirmation dialogs appearing on the page. | -| `When I do not accept confirmation dialogs` | Do not accept confirmation dialogs appearing on the page. | -| `When /^(?:\|I )click (an?\|on) "(?P[^"]*)" element$/` | Click on the element defined by the selector. | -| `When I trigger JS :event event on :selector element` | Trigger an event on the specified element. | -| `Then /^I scroll to an? element with id "([^"]*)"$/` | Scroll to an element with ID. | -| `Then the element with id :id should be at the top of the page` | Assert the element with id at the top of page. | -|   | | -| **[`KeyboardTrait`](src/KeyboardTrait.php) ([example](tests/behat/features/keyboard.feature))** | | -| `Given I press the :keys keys` | Press multiple keyboard keys. | -| `Given I press the :keys keys on :selector` | Press multiple keyboard keys on the specified element. | -| `Given I press the :char key` | Press the specified keyboard key. | -| `Given I press the :char key on :selector` | Press the specified keyboard key on the specified element. | -|   | | -| **[`LinkTrait`](src/LinkTrait.php) ([example](tests/behat/features/link.feature))** | | -| `Then I should see the link :text with :href` | Assert the presence of a link with the specified href. | -| `Then I should see the link :text with :href in :locator` | Assert the presence of a link with the specified href in the specified locator. | -| `Then I should not see the link :text with :href` | Assert that a link with the specified href does not exist. | -| `Then I should not see the link :text with :href in :locator` | Assert that a link with the specified href does not exist in the specified locator. | -| `Then the link with title :title exists` | Assert that a link with the specified title exists. | -| `Then the link with title :title does not exist` | Assert that a link with the specified title does not exist. | -| `Then I click the link with title :title` | Click on the link with the specified title. | -| `Then the link( with title) :text is an absolute link` | Assert that the link with the specified text is absolute. | -| `Then the link( with title) :text is not an absolute link` | Assert that the link with the specified text is not absolute. | -|   | | -| **[`MediaTrait`](src/MediaTrait.php) ([example](tests/behat/features/media.feature))** | | -| `Given no :type media type` | Remove the specified media type. | -| `Given :type media:` | Create media of the given type. | -| `Given /^no ([a-zA-z0-9_-]+) media:$/` | Remove media defined by the provided properties. | -| `Navigate to edit media with specified type and name.` | Navigate to the edit page for the specified media type and name. | -|   | | -| **[`MenuTrait`](src/MenuTrait.php) ([example](tests/behat/features/menu.feature))** | | -| `Given no menus:` | Remove the specified menus. | -| `Given menus:` | Create a menu if one does not exist. | -| `Given no :menu_name menu_links:` | Remove menu links by title. | -| `Given :menu_name menu_links:` | Create menu links. | -|   | | -| **[`MetaTagTrait`](src/MetaTagTrait.php) ([example](tests/behat/features/metatag.feature))** | | -| `Then I should see a meta tag with the following attributes:` | Assert that a meta tag with specific attributes and values exists. | -| `Then I should not see a meta tag with the following attributes:` | Assert that a meta tag with specific attributes and values does not exist. | -|   | | -| **[`ParagraphsTrait`](src/ParagraphsTrait.php) ([example](tests/behat/features/paragraphs.feature))** | | -| `When :field_name in :bundle :entity_type with :entity_field_name of :entity_field_identifer has :paragraph_type paragraph:` | Create paragraphs of the given type with fields for the specified entity. | -|   | | -| **[`PathTrait`](src/PathTrait.php) ([example](tests/behat/features/path.feature))** | | -| `Then I should be in the :path path` | Assert the current page is the specified path. | -| `Then I should not be in the :path path` | Assert the current page is not the specified path. | -| `Then I :can visit :path with HTTP credentials :user :pass` | Assert that the specified path can be visited with HTTP credentials. | -| `When I visit :path then the final URL should be :alias` | Visit the specified path and assert the final URL. | -|   | | -| **[`ResponseTrait`](src/ResponseTrait.php) ([example](tests/behat/features/response.feature))** | | -| `Then response contains header :name` | Assert that the response contains a header with the specified name. | -| `Then response does not contain header :name` | Assert that the response does not contain a header with the specified name. | -| `Then response header :name contains :value` | Assert that the response header contains the specified value. | -| `Then response header :name does not contain :value` | Assert that the response header does not contain the specified value. | -|   | | -| **[`RoleTrait`](src/RoleTrait.php) ([example](tests/behat/features/role.feature))** | | -| `Given role :name with permissions :permissions` | Create a single role with the specified permissions. | -| `Given roles:` | Create multiple roles from the specified table. | -|   | | -| **[`SelectTrait`](src/SelectTrait.php) ([example](tests/behat/features/select.feature))** | | -| `Then select :select should have an option :option` | Assert that the specified select element has the specified option. | -| `Then select :select should not have an option :option` | Assert that the specified select element does not have the specified option. | -| `Then /^the option "([^"]*)" from select "([^"]*)" is selected$/` | Assert that the specified option is selected in the specified select element. | -|   | | -| **[`SearchApiTrait`](src/SearchApiTrait.php) ([example](tests/behat/features/search.feature))** | | -| `When I index :type :title for search` | Index a node with all Search API indices. | -| `When I index :limit Search API items` | Index a specified number of items across all active Search API indices. | -|   | | -| **[`TaxonomyTrait`](src/TaxonomyTrait.php) ([example](tests/behat/features/taxonomy.feature))** | | -| `Given vocabulary :vid with name :name exists` | Assert that the specified vocabulary exists. | -| `Given taxonomy term :name from vocabulary :vocabulary_id exists` | Assert that the specified taxonomy term exists by name. | -| `Given no :vocabulary terms:` | Remove terms from the specified vocabulary. | -| `When I visit :vocabulary vocabulary term :name` | Visit the specified vocabulary term page. | -| `When I edit :vocabulary vocabulary term :name` | Visit the specified vocabulary term edit page. | -|   | | -| **[`UserTrait`](src/UserTrait.php) ([example](tests/behat/features/user.feature))** | | -| `When I visit user :name profile` | Visit the profile page of the specified user. | -| `When I go to my profile edit page` | Visit the edit page of the current user. | -| `When I edit user :name profile` | Visit the edit page of the specified user. | -| `Given no users:` | Remove users specified in the table. | -| `Then user :name has :roles role(s) assigned` | Assert that a user has the specified roles assigned. | -| `Then user :name does not have :roles role(s) assigned` | Assert that a user does not have the specified roles assigned. | -| `Then user :name has :status status` | Assert whether a user is active or not. | -| `Then I set user :user password to :password` | Set a password for a user. | -| `Then the last access time of user :name is :time` | Set last access time for user. | -|   | | -| **[`VisibilityTrait`](src/VisibilityTrait.php) ([example](tests/behat/features/visibility.feature))** | | -| `Then /^(?:\|I )should see a visible "(?P[^"]*)" element$/` | Assert that the element with the specified CSS selector is visible on the page. | -| `Then /^(?:\|I )should not see a visible "(?P[^"]*)" element$/` | Assert that the element with the specified CSS selector is not visible on the page. | -| `Then /^(?:\|I )should see a visually visible "(?P[^"]*)" element(?: with top offset of "([^"]*)" pixels)?$/` | Assert that the element with the specified CSS selector is visually visible on the page. | -| `Then /^(?:\|I )should not see a visually hidden "(?P[^"]*)" element(?: with top offset of "([^"]*)" pixels)?$/` | Assert that the element with the specified CSS selector is visually hidden on the page. | -|   | | -| **[`WaitTrait`](src/WaitTrait.php) ([example](tests/behat/features/wait.feature))** | | -| `Then /^(?:\|I )wait (\d+) second(s?)$/` | Wait for the specified number of seconds. | -| `Given I wait :timeout seconds for AJAX to finish` | Wait for AJAX to finish. | -|   | | -| **[`WysiwygTrait`](src/WysiwygTrait.php) ([example](tests/behat/features/wysiwyg.feature))** | | -| `When I fill in WYSIWYG :field with :value` | Set the value for the WYSIWYG field. | +For migration from v2 to v3, see [MIGRATION.md](MIGRATION.md). + +| Step Name | Description | +|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| +| **[`ContentTrait`](src/ContentTrait.php) ([example](tests/behat/features/content.feature))** | | +| `Given no :type content type` | Delete the content type. | +| `When I visit :type :title` | Navigate to a page with a specified type and title. | +| `When I edit :type :title` | Navigate to the edit page with a specified type and title. | +| `When I delete :type :title` | Navigate to the delete page with a specified type and title. | +| `Given no ([a-zA-z0-9_-]+) content:$/` | Remove content defined by provided properties. | +| `When the moderation state of :type :title changes from :old_state to :new_state` | Change the moderation state of content with the specified title. | +| `When I visit :type :title scheduled transitions` | Visit the scheduled transition page for a node with the specified title. | +|   | | +| **[`CookieTrait`](src/CookieTrait.php) ([example](tests/behat/features/cookie.feature))** | | +| `Then a cookie with( the) name :name should exist` | Check if a cookie with the specified name exists. | +| `Then a cookie with( the) name :name and value :value should exist` | Check if a cookie with the specified name and value exists. | +| `Then a cookie with( the) name :name and value containing :partial_value should exist` | Check if a cookie with the specified name and a partial value exists. | +| `Then a cookie with( the) name containing :partial_name should exist` | Check if a cookie with a partial name exists. | +| `Then a cookie with( the) name containing :partial_name and value :value should exist` | Check if a cookie with a partial name and value exists. | +| `Then a cookie with( the) name containing :partial_name and value containing :partial_value should exist` | Check if a cookie with a partial name and partial value exists. | +| `Then a cookie with( the) name :name should not exist` | Check if a cookie with the specified name does not exist. | +| `Then a cookie with( the) name :name and value :value should not exist` | Check if a cookie with the specified name and value does not exist. | +| `Then a cookie with( the) name :name and value containing :partial_value should not exist` | Check if a cookie with the specified name and a partial value does not exist. | +| `Then a cookie with( the) name containing :partial_name should not exist` | Check if a cookie with a partial name does not exist. | +| `Then a cookie with( the) name containing :partial_name and value :value should not exist` | Check if a cookie with a partial name and value does not exist. | +| `Then a cookie with( the) name containing :partial_name and value containing :partial_value should not exist` | Check if a cookie with a partial name and partial value does not exist. | +|   | | +| **[`DraggableViewsTrait`](src/DraggableViewsTrait.php) ([example](tests/behat/features/draggableviews.feature))** | | +| `Then I save draggable views :view_id view :views_display_id display :bundle items in the following order:` | Save the order of the draggable items. | +|   | | +| **[`EckTrait`](src/EckTrait.php) ([example](tests/behat/features/eck.feature))** | | +| `Given :bundle :entity_type entities:` | Create ECK entities. | +| `Given no :bundle :entity_type entities:` | Remove custom entities by field. | +| `When I edit :bundle :entity_type with title :label` | Navigate to the edit page for the specified ECK entity type and title. | +| `When I visit :bundle :entity_type with title :label` | Navigate to the view page for the specified ECK entity type and title. | +|   | | +| **[`ElementTrait`](src/ElementTrait.php) ([example](tests/behat/features/element.feature))** | | +| `Then I( should) see the :selector element with the :attribute attribute set to :value` | Assert that an element with the specified selector and attribute value exists. | +| `I( should) see the :selector element with a(n) :attribute attribute containing :value` | Assert that an element with the specified selector and attribute value exists, matching a wildcard pattern. | +| `Then I should see an element :selector using :type contains :text text` | Assert that an element with selector contains text. | +|   | | +| **[`EmailTrait`](src/EmailTrait.php) ([example](tests/behat/features/email.feature))** | | +| `Given I enable the test email system` | Enable the test email system. | +| `Given I disable the test email system` | Disable the test email system. | +| `When I clear the test email system queue` | Clear the test email system queue. | +| `Then an email is sent to :address` | Assert that an email was sent to the specified address. | +| `Then no emails were sent` | Assert that no email messages were sent. | +| `Then no emails were sent to :address` | Assert that no email messages were sent to the specified address. | +| `Then an email header :header contains:` | Assert that an email message header contains the specified content. | +| `Then an email header :header contains exact:` | Assert that an email message header contains the exact specified content. | +| `Then /^an email to "(?P[^"]*)" user is "(?P[^"]*)" with "(?P[^"]*)" content:$/` | Assert that an email message was sent or not sent to a user with the specified content. | +| `Then an email :field contains` | Assert that an email message field contains the specified value. | +| `Then an email :field contains exact` | Assert that an email message field contains the exact specified value. | +| `Then an email :field does not contain` | Assert that an email message field does not contain the specified value. | +| `Then an email :field does not contains exact` | Assert that an email message field does not contain the exact specified value. | +| `When I follow the link number :number in the email with the subject` | Visit a link from the email with the specified subject. | +| `Then file :name attached to the email with the subject` | Assert that a file is attached to an email message with the specified subject. | +|   | | +| **[`FieldTrait`](src/FieldTrait.php) ([example](tests/behat/features/field.feature))** | | +| `Then I see field :name` | Assert that a field exists on the page using its id, name, label, or value. | +| `Then I don't see field :name` | Assert that a field does not exist on the page using its id, name, label, or value. | +| `Then field :name :exists on the page` | Assert whether the field exists on the page using its id, name, label, or value. | +| `Then field :name is :disabled on the page` | Assert whether the field is disabled on the page. | +| `Then field :name should be :presence on the page and have state :state` | Assert whether the field exists on the page and has a specified state. | +| `Then I fill color in :field for :value` | Fills value for color field. | +| `Then color field :field value is :value` | Asserts that a color field has a value. | +|   | | +| **[`FileDownloadTrait`](src/FileDownloadTrait.php) ([example](tests/behat/features/file-download.feature))** | | +| `Then I download file from :url` | Download a file from the specified URL. | +| `Then I download file from link :link` | Download a file from the specified HTML link. | +| `Then I see download :link link :presence(on the page)` | Assert that an HTML link is present or absent on the page. | +| `Then downloaded file contains:` | Assert the contents of the downloaded file. | +| `Then downloaded file name is :name` | Assert the file name of the downloaded file. | +| `Then downloaded file is zip archive that contains files:` | Assert that the downloaded file is a ZIP archive containing specified files. | +| `Then downloaded file is zip archive that does not contain files:` | Assert that the downloaded file is a ZIP archive that does not contain specified files. | +|   | | +| **[`FileTrait`](src/FileTrait.php) ([example](tests/behat/features/file.feature))** | | +| `Given managed file:` | Create a managed file with the properties provided in the table. | +| `Given no managed files:` | Delete managed files defined by the provided properties or fields. | +| `Given unmanaged file :uri created` | Create an unmanaged file. | +| `Given unmanaged file :uri created with content :content` | Create an unmanaged file with specified content. | +| `Then unmanaged file :uri exists` | Assert that an unmanaged file with the specified URI exists. | +| `Then unmanaged file :uri does not exist` | Assert that an unmanaged file with the specified URI does not exist. | +| `Then unmanaged file :uri has content :content` | Assert that an unmanaged file exists and has the specified content. | +| `Then unmanaged file :uri does not have content :content` | Assert that an unmanaged file exists and does not have the specified content. | +|   | | +| **[`JsTrait`](src/JsTrait.php) ([example](tests/behat/features/js.feature))** | | +| `When I accept confirmation dialogs` | Accept confirmation dialogs appearing on the page. | +| `When I do not accept confirmation dialogs` | Do not accept confirmation dialogs appearing on the page. | +| `When /^(?:\|I )click (an?\|on) "(?P[^"]*)" element$/` | Click on the element defined by the selector. | +| `When I trigger JS :event event on :selector element` | Trigger an event on the specified element. | +| `Then /^I scroll to an? element with id "([^"]*)"$/` | Scroll to an element with ID. | +| `Then the element with id :id should be at the top of the page` | Assert the element with id at the top of page. | +|   | | +| **[`KeyboardTrait`](src/KeyboardTrait.php) ([example](tests/behat/features/keyboard.feature))** | | +| `Given I press the :keys keys` | Press multiple keyboard keys. | +| `Given I press the :keys keys on :selector` | Press multiple keyboard keys on the specified element. | +| `Given I press the :char key` | Press the specified keyboard key. | +| `Given I press the :char key on :selector` | Press the specified keyboard key on the specified element. | +|   | | +| **[`LinkTrait`](src/LinkTrait.php) ([example](tests/behat/features/link.feature))** | | +| `Then I should see the link :text with :href` | Assert the presence of a link with the specified href. | +| `Then I should see the link :text with :href in :locator` | Assert the presence of a link with the specified href in the specified locator. | +| `Then I should not see the link :text with :href` | Assert that a link with the specified href does not exist. | +| `Then I should not see the link :text with :href in :locator` | Assert that a link with the specified href does not exist in the specified locator. | +| `Then the link with title :title exists` | Assert that a link with the specified title exists. | +| `Then the link with title :title does not exist` | Assert that a link with the specified title does not exist. | +| `Then I click the link with title :title` | Click on the link with the specified title. | +| `Then the link( with title) :text is an absolute link` | Assert that the link with the specified text is absolute. | +| `Then the link( with title) :text is not an absolute link` | Assert that the link with the specified text is not absolute. | +|   | | +| **[`MediaTrait`](src/MediaTrait.php) ([example](tests/behat/features/media.feature))** | | +| `Given no :type media type` | Remove the specified media type. | +| `Given :type media:` | Create media of the given type. | +| `Given /^no ([a-zA-z0-9_-]+) media:$/` | Remove media defined by the provided properties. | +| `Navigate to edit media with specified type and name.` | Navigate to the edit page for the specified media type and name. | +|   | | +| **[`MenuTrait`](src/MenuTrait.php) ([example](tests/behat/features/menu.feature))** | | +| `Given no menus:` | Remove the specified menus. | +| `Given menus:` | Create a menu if one does not exist. | +| `Given no :menu_name menu_links:` | Remove menu links by title. | +| `Given :menu_name menu_links:` | Create menu links. | +|   | | +| **[`MetaTagTrait`](src/MetaTagTrait.php) ([example](tests/behat/features/metatag.feature))** | | +| `Then I should see a meta tag with the following attributes:` | Assert that a meta tag with specific attributes and values exists. | +| `Then I should not see a meta tag with the following attributes:` | Assert that a meta tag with specific attributes and values does not exist. | +|   | | +| **[`ParagraphsTrait`](src/ParagraphsTrait.php) ([example](tests/behat/features/paragraphs.feature))** | | +| `Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:` | Create a paragraph of the given type with fields within an existing entity. | +|   | | +| **[`PathTrait`](src/PathTrait.php) ([example](tests/behat/features/path.feature))** | | +| `Then I should be in the :path path` | Assert the current page is the specified path. | +| `Then I should not be in the :path path` | Assert the current page is not the specified path. | +| `Then I :can visit :path with HTTP credentials :user :pass` | Assert that the specified path can be visited with HTTP credentials. | +| `When I visit :path then the final URL should be :alias` | Visit the specified path and assert the final URL. | +|   | | +| **[`ResponseTrait`](src/ResponseTrait.php) ([example](tests/behat/features/response.feature))** | | +| `Then response contains header :name` | Assert that the response contains a header with the specified name. | +| `Then response does not contain header :name` | Assert that the response does not contain a header with the specified name. | +| `Then response header :name contains :value` | Assert that the response header contains the specified value. | +| `Then response header :name does not contain :value` | Assert that the response header does not contain the specified value. | +|   | | +| **[`RoleTrait`](src/RoleTrait.php) ([example](tests/behat/features/role.feature))** | | +| `Given role :name with permissions :permissions` | Create a single role with the specified permissions. | +| `Given roles:` | Create multiple roles from the specified table. | +|   | | +| **[`SelectTrait`](src/SelectTrait.php) ([example](tests/behat/features/select.feature))** | | +| `Then select :select should have an option :option` | Assert that the specified select element has the specified option. | +| `Then select :select should not have an option :option` | Assert that the specified select element does not have the specified option. | +| `Then /^the option "([^"]*)" from select "([^"]*)" is selected$/` | Assert that the specified option is selected in the specified select element. | +|   | | +| **[`SearchApiTrait`](src/SearchApiTrait.php) ([example](tests/behat/features/search.feature))** | | +| `When I index :type :title for search` | Index a node with all Search API indices. | +| `When I index :limit Search API items` | Index a specified number of items across all active Search API indices. | +|   | | +| **[`TaxonomyTrait`](src/TaxonomyTrait.php) ([example](tests/behat/features/taxonomy.feature))** | | +| `Given vocabulary :vid with name :name exists` | Assert that the specified vocabulary exists. | +| `Given taxonomy term :name from vocabulary :vocabulary_id exists` | Assert that the specified taxonomy term exists by name. | +| `Given no :vocabulary terms:` | Remove terms from the specified vocabulary. | +| `When I visit :vocabulary vocabulary term :name` | Visit the specified vocabulary term page. | +| `When I edit :vocabulary vocabulary term :name` | Visit the specified vocabulary term edit page. | +|   | | +| **[`UserTrait`](src/UserTrait.php) ([example](tests/behat/features/user.feature))** | | +| `When I visit user :name profile` | Visit the profile page of the specified user. | +| `When I go to my profile edit page` | Visit the edit page of the current user. | +| `When I edit user :name profile` | Visit the edit page of the specified user. | +| `Given no users:` | Remove users specified in the table. | +| `Then user :name has :roles role(s) assigned` | Assert that a user has the specified roles assigned. | +| `Then user :name does not have :roles role(s) assigned` | Assert that a user does not have the specified roles assigned. | +| `Then user :name has :status status` | Assert whether a user is active or not. | +| `Then I set user :user password to :password` | Set a password for a user. | +| `Then the last access time of user :name is :time` | Set last access time for user. | +|   | | +| **[`VisibilityTrait`](src/VisibilityTrait.php) ([example](tests/behat/features/visibility.feature))** | | +| `Then /^(?:\|I )should see a visible "(?P[^"]*)" element$/` | Assert that the element with the specified CSS selector is visible on the page. | +| `Then /^(?:\|I )should not see a visible "(?P[^"]*)" element$/` | Assert that the element with the specified CSS selector is not visible on the page. | +| `Then /^(?:\|I )should see a visually visible "(?P[^"]*)" element(?: with top offset of "([^"]*)" pixels)?$/` | Assert that the element with the specified CSS selector is visually visible on the page. | +| `Then /^(?:\|I )should not see a visually hidden "(?P[^"]*)" element(?: with top offset of "([^"]*)" pixels)?$/` | Assert that the element with the specified CSS selector is visually hidden on the page. | +|   | | +| **[`WaitTrait`](src/WaitTrait.php) ([example](tests/behat/features/wait.feature))** | | +| `Then /^(?:\|I )wait (\d+) second(s?)$/` | Wait for the specified number of seconds. | +| `Given I wait :timeout seconds for AJAX to finish` | Wait for AJAX to finish. | +|   | | +| **[`WysiwygTrait`](src/WysiwygTrait.php) ([example](tests/behat/features/wysiwyg.feature))** | | +| `When I fill in WYSIWYG :field with :value` | Set the value for the WYSIWYG field. | #### Skipping before scenario hooks @@ -251,8 +254,11 @@ For example, to skip `beforeScenario` hook from `JsTrait`, add ### Local environment setup -- Install [Docker](https://www.docker.com/), [Pygmy](https://github.com/pygmystack/pygmy), [Ahoy](https://github.com/ahoy-cli/ahoy) +- + +Install [Docker](https://www.docker.com/), [Pygmy](https://github.com/pygmystack/pygmy), [Ahoy](https://github.com/ahoy-cli/ahoy) and shut down local web services (Apache/Nginx, MAMP etc) + - Checkout project repository in one of the [supported Docker directories](https://docs.docker.com/docker-for-mac/osxfs/#access-control). - `pygmy up` @@ -264,8 +270,10 @@ Use `ahoy --help` to see the list of available commands. ### Running tests The source code of traits is tested by running Behat tests in the same way they -would be run in your project: traits are included into [FeatureContext.php](tests/behat/bootstrap/FeatureContext.php) -and then ran on the pre-configured [fixture Drupal site](tests/behat/fixtures/d10) +would be run in your project: traits are included +into [FeatureContext.php](tests/behat/bootstrap/FeatureContext.php) +and then ran on the +pre-configured [fixture Drupal site](tests/behat/fixtures/d10) using [test features](tests/behat/features). Run `ahoy build` to setup a fixture Drupal site in the `build` directory. diff --git a/src/ParagraphsTrait.php b/src/ParagraphsTrait.php index bb8ad6c..080e471 100644 --- a/src/ParagraphsTrait.php +++ b/src/ParagraphsTrait.php @@ -46,25 +46,27 @@ public function paragraphsCleanAll(AfterScenarioScope $scope): void { } /** - * Creates paragraphs of the given type with fields for existing entity. + * Create a paragraph of the given type with fields within an existing entity. * - * Paragraph fields are specified in the same way as for nodeCreate(): + * @code + * Given the following fields for the paragraph "text" exist in the field "field_component" within the "landing_page" "node" identified by the field "title" and the value "My landing page": * | field_paragraph_title | My paragraph title | * | field_paragraph_longtext:value | My paragraph message | * | field_paragraph_longtext:format | full_html | * | ... | ... | + * @endcode * - * @When :field_name in :bundle :entity_type with :entity_field_name of :entity_field_identifer has :paragraph_type paragraph: + * @Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value: */ - public function paragraphsAddToEntityWithFields(string $field_name, string $bundle, string $entity_type, string $entity_field_name, string $entity_field_identifer, string $paragraph_type, TableNode $fields): void { - $this->paragraphsValidateEntityFieldName($entity_type, $bundle, $field_name); + public function paragraphsAddWithFields(string $parent_entity_type, string $parent_bundle, string $parent_field, string $parent_lookup_field, string $parent_lookup_value, string $paragraph_type, TableNode $fields): void { + $this->paragraphsValidateEntityHasField($parent_entity_type, $parent_bundle, $parent_field); // Find previously created entity by entity_type, bundle and identifying // field value. - $parent_entity = $this->paragraphsFindEntity($entity_type, $bundle, $entity_field_name, $entity_field_identifer); + $parent_entity = $this->paragraphsFindEntity($parent_entity_type, $parent_bundle, $parent_lookup_field, $parent_lookup_value); if (!$parent_entity) { - throw new \RuntimeException(sprintf('Parent entity "%s" with field "%s" of value "%s" not found', $bundle, $entity_field_name, $entity_field_identifer)); + throw new \RuntimeException(sprintf('The parent entity of type "%s" and bundle "%s" with the field "%s" and the value "%s" was not found', $parent_entity_type, $parent_bundle, $parent_lookup_field, $parent_lookup_value)); } // Get fields from scenario, parse them and expand values according to @@ -74,7 +76,7 @@ public function paragraphsAddToEntityWithFields(string $field_name, string $bund $this->parseEntityFields('paragraph', $stub); $this->paragraphsExpandEntityFields('paragraph', $stub); - $this->paragraphsAttachFromStubToEntity($parent_entity, $field_name, $paragraph_type, $stub); + $this->paragraphsAttachFromStubToEntity($parent_entity, $parent_field, $paragraph_type, $stub); } /** @@ -82,7 +84,7 @@ public function paragraphsAddToEntityWithFields(string $field_name, string $bund * * @param \Drupal\Core\Entity\ContentEntityInterface $parent_entity * Node to attach paragraph to. - * @param string $parent_entity_field_name + * @param string $parent_field_name * Field name on the entity that refers paragraphs item. * @param string $paragraph_bundle * Paragraphs item bundle name. @@ -95,19 +97,19 @@ public function paragraphsAddToEntityWithFields(string $field_name, string $bund * @return \Drupal\paragraphs\ParagraphInterface * Created paragraphs item. */ - protected function paragraphsAttachFromStubToEntity(ContentEntityInterface $parent_entity, string $parent_entity_field_name, string $paragraph_bundle, \StdClass $stub, bool $save_entity = TRUE): ParagraphInterface { + protected function paragraphsAttachFromStubToEntity(ContentEntityInterface $parent_entity, string $parent_field_name, string $paragraph_bundle, \StdClass $stub, bool $save_entity = TRUE): ParagraphInterface { $stub->type = $paragraph_bundle; $stub = (array) $stub; $paragraph = Paragraph::create($stub); - $paragraph->setParentEntity($parent_entity, $parent_entity_field_name)->save(); + $paragraph->setParentEntity($parent_entity, $parent_field_name)->save(); - $new_value = $parent_entity->get($parent_entity_field_name)->getValue(); + $new_value = $parent_entity->get($parent_field_name)->getValue(); $new_value[] = [ 'target_id' => $paragraph->id(), 'target_revision_id' => $paragraph->getRevisionId(), ]; - $parent_entity->set($parent_entity_field_name, $new_value); + $parent_entity->set($parent_field_name, $new_value); if ($save_entity) { $parent_entity->save(); @@ -183,12 +185,12 @@ protected function paragraphsExpandEntityFields(string $entity_type, \StdClass $ * @throws \RuntimeException * If the field does not exist on the entity. */ - protected function paragraphsValidateEntityFieldName(string $entity_type, string $bundle, string $field_name): void { + protected function paragraphsValidateEntityHasField(string $entity_type, string $bundle, string $field_name): void { /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $field_info */ $field_info = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type, $bundle); if (!array_key_exists($field_name, $field_info)) { - throw new \RuntimeException(sprintf('"%s" "%s" does not have a field "%s"', $bundle, $entity_type, $field_name)); + throw new \RuntimeException(sprintf('The entity type "%s" and bundle "%s" does not have a field "%s"', $entity_type, $bundle, $field_name)); } } diff --git a/tests/behat/features/paragraphs.feature b/tests/behat/features/paragraphs.feature index 5cdd0a9..8ea8f26 100644 --- a/tests/behat/features/paragraphs.feature +++ b/tests/behat/features/paragraphs.feature @@ -1,3 +1,4 @@ +@api Feature: Check that ParagraphsTrait works Background: @@ -9,12 +10,39 @@ Feature: Check that ParagraphsTrait works | title | | [TEST] Landing page 1 | - @api - Scenario: Assert "When :field_name in :bundle :entity_type with :entity_field_name of :entity_field_identifer has :paragraph_type paragraph:" - When "field_paragraph" in landing_page node with title of "[TEST] Landing page 1" has "text" paragraph: + Scenario: Assert "Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:" + Given the following fields for the paragraph "text" exist in the field "field_paragraph" within the "landing_page" "node" identified by the field "title" and the value "[TEST] Landing page 1": | field_paragraph_title | My paragraph title | | field_paragraph_body:value | My paragraph message | | field_paragraph_body:format | full_html | And I visit landing_page "[TEST] Landing page 1" Then I should see the text "My paragraph title" And I should see the text "My paragraph message" + + @trait:ParagraphsTrait + Scenario: Assert that negative assertion for "Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:" fails with an error on non-existing parent field + Given some behat configuration + And scenario steps: + """ + Given the following fields for the paragraph "text" exist in the field "field_non_existing_paragraph" within the "landing_page" "node" identified by the field "title" and the value "[TEST] Landing page 1": + | field_paragraph_title | My paragraph title | + """ + When I run "behat --no-colors" + Then it should fail with an exception: + """ + The entity type "node" and bundle "landing_page" does not have a field "field_non_existing_paragraph" + """ + + @trait:ParagraphsTrait + Scenario: Assert that negative assertion for "Given the following fields for the paragraph :paragraph_type exist in the field :parent_field within the :parent_bundle :parent_entity_type identified by the field :parent_lookup_field and the value :parent_lookup_value:" fails with an error on non-existing parent entity + Given some behat configuration + And scenario steps: + """ + Given the following fields for the paragraph "text" exist in the field "field_paragraph" within the "landing_page" "node" identified by the field "title" and the value "[TEST] Non-existing landing page": + | field_paragraph_title | My paragraph title | + """ + When I run "behat --no-colors" + Then it should fail with an exception: + """ + The parent entity of type "node" and bundle "landing_page" with the field "title" and the value "[TEST] Non-existing landing page" was not found + """