Skip to content

Commit

Permalink
Added a linter for Gherkin and updated features.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Oct 18, 2024
1 parent ebfed47 commit 47b06e7
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 70 deletions.
5 changes: 3 additions & 2 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ commands:
lint:
usage: Lint code.
cmd: |
ahoy cli "cp -Rf phpcs.xml phpstan.neon phpmd.xml build > /dev/null" \
ahoy cli "cp -Rf phpcs.xml phpstan.neon phpmd.xml gherkinlint.json build > /dev/null" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpcs" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpmd ../src text phpmd.xml" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpmd ../tests/behat/bootstrap text phpmd.xml" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpstan" \
&& ahoy cli "cd /app/build && ./vendor/bin/rector process ../src --clear-cache --dry-run || true"
&& ahoy cli "cd /app/build && ./vendor/bin/rector process ../src --clear-cache --dry-run" \
&& ahoy cli "cd /app/build && ./vendor/bin/gherkinlint lint ../tests/behat/features"
lint-fix:
usage: Fix code.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"drupal/drupal-extension": "^5"
},
"require-dev": {
"dantleech/gherkin-lint": "^0.2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^1",
"drevops/behat-screenshot": "^1.5",
"drupal/coder": "^8.3",
Expand Down
20 changes: 20 additions & 0 deletions gherkinlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"rules": {
"indentation": {
"width": 2,
"literalBlock": 3
},
"keyword-order": {
"enabled": false
},
"no-background-with-single-scenario": {
"enabled": false
},
"no-homogenous-tags": {
"enabled": false
},
"scenario-size": {
"enabled": false
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
@behatcli
Feature: Behat CLI context additional steps

@trait:PathTrait
Scenario: Test fails with exception
Given some behat configuration
And scenario steps:
"""
Given I go to the homepage
Then I throw test exception with message "Intentional error"
And I should be in the "nonexisting" path
"""
When I run "behat --no-colors"
Then it should fail with an exception:
"""
Intentional error
"""

@trait:PathTrait
Scenario: Test fails with exception
Given some behat configuration
Expand Down
10 changes: 5 additions & 5 deletions tests/behat/features/eck.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@api
Feature: Check that EckTrait works for or D9

Background:
Given I am logged in as a user with the "administrator" role

Given no test_bundle test_entity_type entities:
| title |
| [TEST] ECK Entity |
Expand All @@ -16,17 +13,19 @@ Feature: Check that EckTrait works for or D9

@api
Scenario: Assert "When I edit :bundle :entity_type with title :label"
Given I am logged in as a user with the "administrator" role
When I edit test_bundle test_entity_type with title "[TEST] ECK test1"
Then I should see "Edit test bundle [TEST] ECK test1"
And I visit test_bundle test_entity_type with title "[TEST] ECK test1"
And I should see "[TEST] ECK test1"
And I should see "T2"

@trait:EckTrait
@api @trait:EckTrait
Scenario: Assert navigate to entity type with specified bundle and title.
Given some behat configuration
And scenario steps tagged with "@api":
"""
Given I am logged in as a user with the "administrator" role
When I visit "test_bundle" "test_entity_type" with title "[Test] Entity Custom"
"""
When I run "behat --no-colors"
Expand All @@ -35,11 +34,12 @@ Feature: Check that EckTrait works for or D9
Unable to find test_entity_type page "[Test] Entity Custom"
"""

@trait:EckTrait
@api @trait:EckTrait
Scenario: Assert edit to entity type with specified bundle and title.
Given some behat configuration
And scenario steps tagged with "@api":
"""
Given I am logged in as a user with the "administrator" role
When I edit "test_bundle" "test_entity_type" with title "[Test] Entity Custom"
"""
When I run "behat --no-colors"
Expand Down
24 changes: 12 additions & 12 deletions tests/behat/features/element.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector and attribute with a value exists.
Scenario: Negative assertion for "Then I should see the :selector element with the :attribute attribute set to :value" fails as expected when the attribute is not found
Given some behat configuration
And scenario steps:
"""
Expand All @@ -37,7 +37,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector and attribute with a value exists.
Scenario: Negative assertion for "Then I should see the :selector element with the :attribute attribute set to :value" fails as expected when the attribute value does not match
Given some behat configuration
And scenario steps:
"""
Expand All @@ -51,18 +51,18 @@ Feature: Check that ElementTrait works
The "dir" attribute was found on the element "html", but does not contain a value "not-match-value".
"""

Scenario: Assert step definition "I( should) see the :selector element with a(n) :attribute attribute containing :value" works as expected
Scenario: Assert step definition "I( should) see the :selector element with a(n) :attribute attribute containing :value" works as expected with a specific value
Given I am an anonymous user
When I visit "/"
Then I should see the "html" element with a "dir" attribute containing "ltr"

Scenario: Assert step definition "I( should) see the :selector element with a(n) :attribute attribute containing :value" works as expected
Scenario: Assert step definition "I( should) see the :selector element with a(n) :attribute attribute containing :value" works as expected with a wildcard
Given I am an anonymous user
When I visit "/"
Then I should see the "html" element with a "dir" attribute containing "lt*"

@trait:ElementTrait
Scenario: Assert that an element with selector and attribute with a value exists.
Scenario: Negative assertion for "Then I should see the :selector element with a(n) :attribute attribute containing :value" fails as expected when the attribute is not found
Given some behat configuration
And scenario steps:
"""
Expand All @@ -77,7 +77,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector and attribute with a value exists.
Scenario: Negative assertion for "Then I should see the :selector element with a(n) :attribute attribute containing :value" fails as expected when the attribute value does not match
Given some behat configuration
And scenario steps:
"""
Expand All @@ -92,7 +92,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector and attribute with a value exists.
Scenario: Negative assertion for "Then I should see the :selector element with a(n) :attribute attribute containing :value" fails as expected when the attribute value does not match; alternative step definition
Given some behat configuration
And scenario steps:
"""
Expand All @@ -106,18 +106,18 @@ Feature: Check that ElementTrait works
No element with "dir" attribute matching the pattern "not-match-value" found.
"""

Scenario: Assert that an element with selector contains text.
Scenario: Assert that an element with selector contains text using css.
Given I am an anonymous user
When I visit "/"
Then I should see an element ".site-branding__name" using "css" contains "Drush Site-Install" text

Scenario: Assert that an element with selector contains text.
Scenario: Assert that an element with selector contains text using xpath.
Given I am an anonymous user
When I visit "/"
Then I should see an element "//div[@class='site-branding__name']" using "xpath" contains "Drush Site-Install" text

@trait:ElementTrait
Scenario: Assert that an element with selector contains text.
Scenario: Negative assertion for "Then I should see an element :selector using :selector_type contains :text text" fails as expected when the selector type is invalid
Given some behat configuration
And scenario steps:
"""
Expand All @@ -132,7 +132,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector contains text.
Scenario: Negative assertion for "Then I should see an element :selector using :selector_type contains :text text" fails as expected when the selector is not found
Given some behat configuration
And scenario steps:
"""
Expand All @@ -147,7 +147,7 @@ Feature: Check that ElementTrait works
"""

@trait:ElementTrait
Scenario: Assert that an element with selector contains text.
Scenario: Negative assertion for "Then I should see an element :selector using :selector_type contains :text text" fails as expected when the text is not found
Given some behat configuration
And scenario steps:
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/behat/features/email.feature
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Feature: Check that email assertions work for or D9
And an email is sent to "[email protected]"
And no emails were sent to "[email protected]"
And an email header "Content-Type" contains:
"""
text/plain
"""
"""
text/plain
"""
And an email header "X-Mailer" contains:
"""
Drupal
"""
"""
Drupal
"""

@api @email
Scenario: As a developer, I want to know that test email system is activated
Expand Down
14 changes: 7 additions & 7 deletions tests/behat/features/field.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Feature: Check that FieldTrait works
Then color field "#edit-color-input" value is "#ffffff"

@api @javascript
Scenario: Assert fills in form color field with specified id|name|label|value.
Scenario: Assert fills in form color field with specified id|name|label|value using an alternate step definition.
Given I visit "/sites/default/files/relative.html"
Then color field "#edit-color-input" value is "#000000"
And I fill color in "#ffffff" for "#edit-color-input"
Then color field "#edit-color-input" value is "#ffffff"

@trait:FieldTrait
Scenario: Assert that field exists on the page using id,name,label or value.
Scenario: Assert that negative assertion for "I see field :field" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -81,7 +81,7 @@ Feature: Check that FieldTrait works
"""

@trait:FieldTrait
Scenario: Assert that field does not exist on the page using id,name,label or value.
Scenario: Assert that negative assertion for "I don't see field :field" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -95,7 +95,7 @@ Feature: Check that FieldTrait works
"""

@trait:FieldTrait
Scenario: Assert that field does not exist on the page using id,name,label or value.
Scenario: Assert that field does not exist on the page using id, name, label or value.
Given some behat configuration
And scenario steps:
"""
Expand Down Expand Up @@ -123,7 +123,7 @@ Feature: Check that FieldTrait works
"""

@trait:FieldTrait
Scenario: Assert whether the field has a state.
Scenario: Assert that negative assertion for "field :field1 is :state on the page" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -137,7 +137,7 @@ Feature: Check that FieldTrait works
"""

@trait:FieldTrait
Scenario: Assert whether the field exists on the page and has a state.
Scenario: Assert that negative assertion for "field :field should be :presence on the page and have state :state" fails with an error for existing field
Given some behat configuration
And scenario steps:
"""
Expand All @@ -151,7 +151,7 @@ Feature: Check that FieldTrait works
"""

@trait:FieldTrait
Scenario: Assert whether the field exists on the page and has a state.
Scenario: Assert that negative assertion for "field :field should be :presence on the page and have state :state" fails with an error for non-existing field
Given some behat configuration
And scenario steps:
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/features/file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Feature: Check that FileTrait works for or D9
"""

@trait:FileTrait
Scenario: Assert that negative assertions fail with an error
Scenario: Assert that negative assertion for "Given unmanaged file :uri does not exist" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -154,7 +154,7 @@ Feature: Check that FileTrait works for or D9
"""

@trait:FileTrait
Scenario: Assert that negative assertions fail with an error
Scenario: Assert that negative assertion for "Given unmanaged file :uri has content :content" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -169,7 +169,7 @@ Feature: Check that FileTrait works for or D9
"""

@trait:FileTrait
Scenario: Assert that negative assertions fail with an error
Scenario: Assert that negative assertion for "Given unmanaged file :uri does not have content :content" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Feature: Check that FileDownloadTrait works for or D9
Then I see download "example_text.txt" link "present"
Then I download file from link "example_text.txt"
And downloaded file contains:
"""
Some Text
"""
"""
Some Text
"""

@api
Scenario: Assert "Given downloaded file is zip archive that contains files:"
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/features/homepage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Homepage
Then I save screenshot

@api @javascript
Scenario: Anonymous user visits homepage
Scenario: Anonymous user visits homepage using a real browser
Given I go to the homepage
And I should be in the "<front>" path
Then I save screenshot
12 changes: 3 additions & 9 deletions tests/behat/features/link.feature
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
Feature: Check that LinkTrait works


Scenario: Assert link with href without locator
Given I go to "/"
Then I should see the link "Drupal" with "https://www.drupal.org"


Scenario: Assert link with href with locator
Given I go to "/"
Then I should see the link "Drupal" with "https://www.drupal.org" in "#block-system-powered-by,#block-bartik-powered,.block-system-powered-by-block"


Scenario: Assert link with wildcard in href without locator
Given I go to "/"
Then I should see the link "Drupal" with "https://www.drupal*"


Scenario: Assert link with href without locator does not exist
Given I go to "/"
Then I should not see the link "RandomLinkText" with "https://www.drupal.org"
Then I should not see the link "Drupal" with "https://www.randomhref.org"


Scenario: Assert link with href with locator does not exist
Given I go to "/"
Then I should not see the link "RandomLinkText" with "https://www.randomhref.org" in "#block-system-powered-by,#block-bartik-powered"
Then I should not see the link "Drupal" with "https://www.drupal.org" in "#random-locator"


Scenario: Assert link with wildcard in href without locator does not exist
Given I go to "/"
Then I should not see the link "Drupal" with "https://www.randomhref*"
Expand All @@ -45,10 +39,10 @@ Feature: Check that LinkTrait works
Given I am logged in as a user with the "administrator" role
When I go to "/"
Then the link with title "Drupal" is an absolute link
Then the link with title "Return to site content" is not an absolute link
And the link with title "Return to site content" is not an absolute link

@trait:LinkTrait
Scenario: Assert that negative assertions fail with an error
Scenario: Assert that negative assertion for "I click the link with title :title" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand All @@ -63,7 +57,7 @@ Feature: Check that LinkTrait works
"""

@trait:LinkTrait
Scenario: Assert that negative assertions fail with an error
Scenario: Assert that negative assertion for "the link with title :title exists" fails with an error
Given some behat configuration
And scenario steps:
"""
Expand Down
Loading

0 comments on commit 47b06e7

Please sign in to comment.