Skip to content

[#416] Added When I visit the :vocabulary_machine_name term delete page with the name :term_name #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 31, 2025
Merged
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
24 changes: 19 additions & 5 deletions STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2486,28 +2486,42 @@ Given the following "fruits" vocabulary terms do not exist:
</details>

<details>
<summary><code>@When I visit the :vocabulary_machine_name vocabulary :term_name term page</code></summary>
<summary><code>@When I visit the :vocabulary_machine_name term page with the name :term_name</code></summary>

<br/>
Visit specified vocabulary term page
<br/><br/>

```gherkin
When I visit the "fruits" vocabulary "Apple" term page
When I visit the "fruits" term page with the name "Apple"

```

</details>

<details>
<summary><code>@When I edit the :vocabulary_machine_name vocabulary :term_name term page</code></summary>
<summary><code>@When I visit the :vocabulary_machine_name term edit page with the name :term_name</code></summary>

<br/>
Edit specified vocabulary term page
Visit specified vocabulary term edit page
<br/><br/>

```gherkin
When I edit the "fruits" vocabulary "Apple" term page
When I visit the "fruits" term edit page with the name "Apple"

```

</details>

<details>
<summary><code>@When I visit the :vocabulary_machine_name term delete page with the name :term_name</code></summary>

<br/>
Visit specified vocabulary term delete page
<br/><br/>

```gherkin
When I visit the "tags" term delete page with the name "[TEST] Remove"

```

Expand Down
61 changes: 34 additions & 27 deletions src/Drupal/TaxonomyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
60 changes: 48 additions & 12 deletions tests/behat/features/drupal_taxonomy.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down