diff --git a/MIGRATION.md b/MIGRATION.md index 20302a31..4cddb349 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -124,6 +124,12 @@ A migration map of the step definitions available in v2 to v3. | `Given /^no ([a-zA-z0-9_-]+) media:$/` | `Given the following media :media_type do not exist:` | | `Navigate to edit media with specified type and name.` | `When I edit the media :media_type with the name :name` | |   +| **[`MenuTrait`](src/MenuTrait.php) ([example](tests/behat/features/menu.feature))** | | +| `Given no menus:` | `Given the menu :menu_name does not exist` | +| `Given menus:` | `Given the following menus:` | +| `Given no :menu_name menu_links:` | `Given the following menu links do not exist in the menu :menu_name:` | +| `Given :menu_name menu_links:` | `Given the following menu links exist in the menu :menu_name:` | +|   | **[`MetatagTrait`](src/MetatagTrait.php) ([example](tests/behat/features/metatag.feature))** | | | `Then I should see a meta tag with the following attributes:` | `Then the meta tag should exist with the following attributes:` | | `Then I should not see a meta tag with the following attributes:` | `Then the meta tag should not exist with the following attributes:` | diff --git a/src/MenuTrait.php b/src/MenuTrait.php index 9694367c..a6a98e09 100644 --- a/src/MenuTrait.php +++ b/src/MenuTrait.php @@ -34,20 +34,17 @@ trait MenuTrait { protected $menuLinks = []; /** - * Remove menu by menu name. + * Remove a single menu by its label if it exists. * - * Provide menu labels in the following format: - * | Fish Menu | - * | ... | + * @param string $menu_name + * The label of the menu to remove. * - * @Given no menus: + * @Given the menu :menu_name does not exist */ - public function menuDelete(TableNode $table): void { - foreach ($table->getColumn(0) as $label) { - $menu = $this->loadMenuByLabel($label); - if ($menu instanceof MenuInterface) { - $menu->delete(); - } + public function menuDeleteSingle(string $menu_name): void { + $menu = $this->loadMenuByLabel($menu_name); + if ($menu instanceof MenuInterface) { + $menu->delete(); } } @@ -60,7 +57,7 @@ public function menuDelete(TableNode $table): void { * | Fish Menu | Menu of fish | * | ... | ... | * - * @Given menus: + * @Given the following menus: */ public function menuCreate(TableNode $table): void { foreach ($table->getHash() as $menu_hash) { @@ -86,7 +83,7 @@ public function menuCreate(TableNode $table): void { * | Test Menu | * | ... | * - * @Given no :menu_name menu_links: + * @Given the following menu links do not exist in the menu :menu_name: */ public function menuLinksDelete(string $menu_name, TableNode $table): void { foreach ($table->getColumn(0) as $title) { @@ -107,7 +104,7 @@ public function menuLinksDelete(string $menu_name, TableNode $table): void { * | Child Link | 1 | https://www.example.com | Parent Link | * | ... | ... | ... | ... | * - * @Given :menu_name menu_links: + * @Given the following menu links exist in the menu :menu_name : */ public function menuLinksCreate(string $menu_name, TableNode $table): void { $menu = $this->loadMenuByLabel($menu_name); diff --git a/steps.md b/steps.md index d8252768..d6454d06 100644 --- a/steps.md +++ b/steps.md @@ -751,28 +751,28 @@ When I edit "document" media "Test document" [Source](src/MenuTrait.php), [Example](tests/behat/features/menu.feature) -#### Remove menu by menu name +#### Remove a single menu by its label if it exists ```gherkin -@Given no menus: +@Given the menu :menu_name does not exist ``` #### Create a menu if one does not exist ```gherkin -@Given menus: +@Given the following menus: ``` #### Remove menu links by title ```gherkin -@Given no :menu_name menu_links: +@Given the following menu links do not exist in the menu :menu_name: ``` #### Create menu links ```gherkin -@Given :menu_name menu_links: +@Given the following menu links exist in the menu :menu_name : ``` ### ParagraphsTrait diff --git a/tests/behat/features/menu.feature b/tests/behat/features/menu.feature index 5b3ae458..88c6965a 100644 --- a/tests/behat/features/menu.feature +++ b/tests/behat/features/menu.feature @@ -1,8 +1,8 @@ Feature: Check that MenuTrait works @api - Scenario: Assert "Given menus:" - Given menus: + Scenario: Assert "Given the following menus:" + Given the following menus: | label | description | | [TEST] menu 1 title | Test menu 1 description | | [TEST] menu 2 title | Test menu 2 description | @@ -14,15 +14,14 @@ Feature: Check that MenuTrait works And I should see the text "Test menu 2 description" @api - Scenario: Assert "Given no menus:" - Given menus: + Scenario: Assert "Given the menu :menu_name does not exist" + Given the following menus: | label | description | | [TEST] menu 1 title | Test menu 1 description | | [TEST] menu 2 title | Test menu 2 description | - Given no menus: - | [TEST] menu 1 title | - | [TEST] menu 2 title | - | [TEST] non-existent menu | + Given the menu "[TEST] menu 1 title" does not exist + Given the menu "[TEST] menu 2 title" does not exist + Given the menu "[TEST] non-existent menu" does not exist And I am logged in as a user with the "administrator" role When I visit "/admin/structure/menu" Then I should not see the text "[TEST] menu 1 title" @@ -31,11 +30,11 @@ Feature: Check that MenuTrait works And I should not see the text "Test menu 2 description" @api - Scenario: Assert "Given menu_links:" and "no menu_links" - Given menus: + Scenario: Assert "Given the following menu links do not exist in the menu menu_name:" and "Given the following menu links exist in the menu :menu_name" + Given the following menus: | label | description | | [TEST] menu 1 title | Test menu 1 description | - Given "[TEST] menu 1 title" menu_links: + Given the following menu links exist in the menu "[TEST] menu 1 title" : | title | enabled | uri | parent | | Parent Link Title | 1 | https://www.example.com | | | Child Link Title | 1 | https://www.example.com | Parent Link Title | @@ -43,7 +42,7 @@ Feature: Check that MenuTrait works When I visit "/admin/structure/menu/manage/_test_menu_1_title" And I should see "Parent Link Title" And I should see "Child Link Title" - Then no "[TEST] menu 1 title" menu_links: + Then the following menu links do not exist in the menu "[TEST] menu 1 title": | Child Link Title | Then I visit "/admin/config/development/performance" # We should not need clear cache at here. Re-check later.