diff --git a/STEPS.md b/STEPS.md
index 0be59ef..4203449 100644
--- a/STEPS.md
+++ b/STEPS.md
@@ -2486,28 +2486,42 @@ Given the following "fruits" vocabulary terms do not exist:
- @When I visit the :vocabulary_machine_name vocabulary :term_name term page
+ @When I visit the :vocabulary_machine_name term page with the name :term_name
Visit specified vocabulary term page
```gherkin
-When I visit the "fruits" vocabulary "Apple" term page
+When I visit the "fruits" term page with the name "Apple"
```
- @When I edit the :vocabulary_machine_name vocabulary :term_name term page
+ @When I visit the :vocabulary_machine_name term edit page with the name :term_name
-Edit specified vocabulary term page
+Visit specified vocabulary term edit page
```gherkin
-When I edit the "fruits" vocabulary "Apple" term page
+When I visit the "fruits" term edit page with the name "Apple"
+
+```
+
+
+
+
+ @When I visit the :vocabulary_machine_name term delete page with the name :term_name
+
+
+Visit specified vocabulary term delete page
+
+
+```gherkin
+When I visit the "tags" term delete page with the name "[TEST] Remove"
```
diff --git a/src/Drupal/TaxonomyTrait.php b/src/Drupal/TaxonomyTrait.php
index 88513ac..0dc4c6a 100644
--- a/src/Drupal/TaxonomyTrait.php
+++ b/src/Drupal/TaxonomyTrait.php
@@ -156,45 +156,52 @@ public function taxonomyAssertTermNotExistsByName(string $term_name, string $voc
* Visit specified vocabulary term page.
*
* @code
- * When I visit the "fruits" vocabulary "Apple" term page
+ * When I visit the "fruits" term page with the name "Apple"
* @endcode
*
- * @When I visit the :vocabulary_machine_name vocabulary :term_name term page
+ * @When I visit the :vocabulary_machine_name term page with the name :term_name
*/
public function taxonomyVisitTermPageWithName(string $vocabulary_machine_name, string $term_name): void {
- $vocab = Vocabulary::load($vocabulary_machine_name);
-
- if (!$vocab) {
- throw new \RuntimeException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name));
- }
-
- $tids = $this->taxonomyLoadMultiple($vocabulary_machine_name, [
- 'name' => $term_name,
- ]);
-
- if (empty($tids)) {
- throw new \RuntimeException(sprintf('Unable to find the term "%s" in the vocabulary "%s".', $term_name, $vocabulary_machine_name));
- }
-
- // Use the term created last.
- ksort($tids);
- $tid = end($tids);
-
- $path = $this->locatePath('/taxonomy/term/' . $tid);
+ $this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name);
+ }
- $this->getSession()->visit($path);
+ /**
+ * Visit specified vocabulary term edit page.
+ *
+ * @code
+ * When I visit the "fruits" term edit page with the name "Apple"
+ * @endcode
+ *
+ * @When I visit the :vocabulary_machine_name term edit page with the name :term_name
+ */
+ public function taxonomyVisitTermEditPageWithName(string $vocabulary_machine_name, string $term_name): void {
+ $this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name, '/edit');
}
/**
- * Edit specified vocabulary term page.
+ * Visit specified vocabulary term delete page.
*
* @code
- * When I edit the "fruits" vocabulary "Apple" term page
+ * When I visit the "tags" term delete page with the name "[TEST] Remove"
* @endcode
*
- * @When I edit the :vocabulary_machine_name vocabulary :term_name term page
+ * @When I visit the :vocabulary_machine_name term delete page with the name :term_name
+ */
+ public function taxonomyVisitTermDeletePageWithName(string $vocabulary_machine_name, string $term_name): void {
+ $this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name, '/delete');
+ }
+
+ /**
+ * Visit the action page of the term with a specified name.
+ *
+ * @param string $vocabulary_machine_name
+ * The term vocabulary machine name.
+ * @param string $term_name
+ * The name of the term.
+ * @param string $action_subpath
+ * The operation to perform, e.g., '/delete', '/edit', etc.
*/
- public function taxonomyEditTermPageWithName(string $vocabulary_machine_name, string $term_name): void {
+ protected function taxonomyVisitActionPageWithName(string $vocabulary_machine_name, string $term_name, string $action_subpath = ''): void {
$vocab = Vocabulary::load($vocabulary_machine_name);
if (!$vocab) {
@@ -212,7 +219,7 @@ public function taxonomyEditTermPageWithName(string $vocabulary_machine_name, st
ksort($tids);
$tid = end($tids);
- $path = $this->locatePath('/taxonomy/term/' . $tid . '/edit');
+ $path = $this->locatePath('/taxonomy/term/' . $tid . $action_subpath);
$this->getSession()->visit($path);
}
diff --git a/tests/behat/features/drupal_taxonomy.feature b/tests/behat/features/drupal_taxonomy.feature
index f8f2fbc..0eddb19 100644
--- a/tests/behat/features/drupal_taxonomy.feature
+++ b/tests/behat/features/drupal_taxonomy.feature
@@ -1,3 +1,4 @@
+@taxonomy
Feature: Check that TaxonomyTrait works
As Behat Steps library developer
I want to provide tools to manage taxonomy terms programmatically
@@ -154,19 +155,19 @@ Feature: Check that TaxonomyTrait works
"""
@api
- Scenario: Assert "When I visit the :vocabulary_machine_name vocabulary :term_name term page" works
+ Scenario: Assert "When I visit the :vocabulary_machine_name term page with the name :term_name" works
Given I am logged in as a user with the "administrator" role
- When I visit the "tags" vocabulary "Tag1" term page
+ When I visit the "tags" term page with the name "Tag1"
Then the response should contain "200"
And I should see "Tag1"
@api @trait:Drupal\TaxonomyTrait
- Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing vocabulary
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term page with the name :term_name" fails with non-existing vocabulary
Given some behat configuration
And scenario steps:
"""
Given I am logged in as a user with the "administrator" role
- When I visit the "nonexisting" vocabulary "Tag1" term page
+ When I visit the "nonexisting" term page with the name "Tag1"
"""
When I run "behat --no-colors"
Then it should fail with an exception:
@@ -175,12 +176,12 @@ Feature: Check that TaxonomyTrait works
"""
@api @trait:Drupal\TaxonomyTrait
- Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing term
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term page with the name :term_name" fails with non-existing term
Given some behat configuration
And scenario steps:
"""
Given I am logged in as a user with the "administrator" role
- When I visit the "tags" vocabulary "Nonexisting" term page
+ When I visit the "tags" term page with the name "Nonexisting"
"""
When I run "behat --no-colors"
Then it should fail with an exception:
@@ -189,19 +190,19 @@ Feature: Check that TaxonomyTrait works
"""
@api
- Scenario: Assert "When I edit the :vocabulary_machine_name vocabulary :term_name term page" works
+ Scenario: Assert "When I visit the :vocabulary_machine_name term edit page with the name :term_name" works
Given I am logged in as a user with the "administrator" role
- When I edit the "tags" vocabulary "Tag1" term page
+ When I visit the "tags" term edit page with the name "Tag1"
Then the response should contain "200"
And I should see "Tag1"
@api @trait:Drupal\TaxonomyTrait
- Scenario: Assert negative assertion for "When I edit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing vocabulary
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term edit page with the name :term_name" fails with non-existing vocabulary
Given some behat configuration
And scenario steps:
"""
Given I am logged in as a user with the "administrator" role
- When I edit the "nonexisting" vocabulary "Tag1" term page
+ When I visit the "nonexisting" term edit page with the name "Tag1"
"""
When I run "behat --no-colors"
Then it should fail with an exception:
@@ -210,12 +211,47 @@ Feature: Check that TaxonomyTrait works
"""
@api @trait:Drupal\TaxonomyTrait
- Scenario: Assert negative assertion for "When I edit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing term
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term edit page with the name :term_name" fails with non-existing term
Given some behat configuration
And scenario steps:
"""
Given I am logged in as a user with the "administrator" role
- When I edit the "tags" vocabulary "Nonexisting" term page
+ When I visit the "tags" term edit page with the name "Nonexisting"
+ """
+ When I run "behat --no-colors"
+ Then it should fail with an exception:
+ """
+ Unable to find the term "Nonexisting" in the vocabulary "tags".
+ """
+
+ @api
+ Scenario: Assert "When I visit the :vocabulary_machine_name term delete page with the name :term_name" works
+ Given I am logged in as a user with the "administrator" role
+ When I visit the "tags" term delete page with the name "Tag1"
+ Then the response should contain "200"
+ And I should see "Tag1"
+
+ @api @trait:Drupal\TaxonomyTrait
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term delete page with the name :term_name" fails with non-existing vocabulary
+ Given some behat configuration
+ And scenario steps:
+ """
+ Given I am logged in as a user with the "administrator" role
+ When I visit the "nonexisting" term delete page with the name "Tag1"
+ """
+ When I run "behat --no-colors"
+ Then it should fail with an exception:
+ """
+ The vocabulary "nonexisting" does not exist.
+ """
+
+ @api @trait:Drupal\TaxonomyTrait
+ Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term delete page with the name :term_name" fails with non-existing term
+ Given some behat configuration
+ And scenario steps:
+ """
+ Given I am logged in as a user with the "administrator" role
+ When I visit the "tags" term delete page with the name "Nonexisting"
"""
When I run "behat --no-colors"
Then it should fail with an exception: