Skip to content

Commit 6eb3123

Browse files
nsineokdf-nikitaAlexSkrypnyk
authored
[#416] Added When I visit the :vocabulary_machine_name term delete page with the name :term_name (#420)
Co-authored-by: Nikita Sineok <nikita@drupfan.com> Co-authored-by: Alex Skrypnyk <alex@drevops.com>
1 parent b930fd5 commit 6eb3123

File tree

3 files changed

+101
-44
lines changed

3 files changed

+101
-44
lines changed

STEPS.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,28 +2486,42 @@ Given the following "fruits" vocabulary terms do not exist:
24862486
</details>
24872487

24882488
<details>
2489-
<summary><code>@When I visit the :vocabulary_machine_name vocabulary :term_name term page</code></summary>
2489+
<summary><code>@When I visit the :vocabulary_machine_name term page with the name :term_name</code></summary>
24902490

24912491
<br/>
24922492
Visit specified vocabulary term page
24932493
<br/><br/>
24942494

24952495
```gherkin
2496-
When I visit the "fruits" vocabulary "Apple" term page
2496+
When I visit the "fruits" term page with the name "Apple"
24972497
24982498
```
24992499

25002500
</details>
25012501

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

25052505
<br/>
2506-
Edit specified vocabulary term page
2506+
Visit specified vocabulary term edit page
25072507
<br/><br/>
25082508

25092509
```gherkin
2510-
When I edit the "fruits" vocabulary "Apple" term page
2510+
When I visit the "fruits" term edit page with the name "Apple"
2511+
2512+
```
2513+
2514+
</details>
2515+
2516+
<details>
2517+
<summary><code>@When I visit the :vocabulary_machine_name term delete page with the name :term_name</code></summary>
2518+
2519+
<br/>
2520+
Visit specified vocabulary term delete page
2521+
<br/><br/>
2522+
2523+
```gherkin
2524+
When I visit the "tags" term delete page with the name "[TEST] Remove"
25112525
25122526
```
25132527

src/Drupal/TaxonomyTrait.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,45 +156,52 @@ public function taxonomyAssertTermNotExistsByName(string $term_name, string $voc
156156
* Visit specified vocabulary term page.
157157
*
158158
* @code
159-
* When I visit the "fruits" vocabulary "Apple" term page
159+
* When I visit the "fruits" term page with the name "Apple"
160160
* @endcode
161161
*
162-
* @When I visit the :vocabulary_machine_name vocabulary :term_name term page
162+
* @When I visit the :vocabulary_machine_name term page with the name :term_name
163163
*/
164164
public function taxonomyVisitTermPageWithName(string $vocabulary_machine_name, string $term_name): void {
165-
$vocab = Vocabulary::load($vocabulary_machine_name);
166-
167-
if (!$vocab) {
168-
throw new \RuntimeException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name));
169-
}
170-
171-
$tids = $this->taxonomyLoadMultiple($vocabulary_machine_name, [
172-
'name' => $term_name,
173-
]);
174-
175-
if (empty($tids)) {
176-
throw new \RuntimeException(sprintf('Unable to find the term "%s" in the vocabulary "%s".', $term_name, $vocabulary_machine_name));
177-
}
178-
179-
// Use the term created last.
180-
ksort($tids);
181-
$tid = end($tids);
182-
183-
$path = $this->locatePath('/taxonomy/term/' . $tid);
165+
$this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name);
166+
}
184167

185-
$this->getSession()->visit($path);
168+
/**
169+
* Visit specified vocabulary term edit page.
170+
*
171+
* @code
172+
* When I visit the "fruits" term edit page with the name "Apple"
173+
* @endcode
174+
*
175+
* @When I visit the :vocabulary_machine_name term edit page with the name :term_name
176+
*/
177+
public function taxonomyVisitTermEditPageWithName(string $vocabulary_machine_name, string $term_name): void {
178+
$this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name, '/edit');
186179
}
187180

188181
/**
189-
* Edit specified vocabulary term page.
182+
* Visit specified vocabulary term delete page.
190183
*
191184
* @code
192-
* When I edit the "fruits" vocabulary "Apple" term page
185+
* When I visit the "tags" term delete page with the name "[TEST] Remove"
193186
* @endcode
194187
*
195-
* @When I edit the :vocabulary_machine_name vocabulary :term_name term page
188+
* @When I visit the :vocabulary_machine_name term delete page with the name :term_name
189+
*/
190+
public function taxonomyVisitTermDeletePageWithName(string $vocabulary_machine_name, string $term_name): void {
191+
$this->taxonomyVisitActionPageWithName($vocabulary_machine_name, $term_name, '/delete');
192+
}
193+
194+
/**
195+
* Visit the action page of the term with a specified name.
196+
*
197+
* @param string $vocabulary_machine_name
198+
* The term vocabulary machine name.
199+
* @param string $term_name
200+
* The name of the term.
201+
* @param string $action_subpath
202+
* The operation to perform, e.g., '/delete', '/edit', etc.
196203
*/
197-
public function taxonomyEditTermPageWithName(string $vocabulary_machine_name, string $term_name): void {
204+
protected function taxonomyVisitActionPageWithName(string $vocabulary_machine_name, string $term_name, string $action_subpath = ''): void {
198205
$vocab = Vocabulary::load($vocabulary_machine_name);
199206

200207
if (!$vocab) {
@@ -212,7 +219,7 @@ public function taxonomyEditTermPageWithName(string $vocabulary_machine_name, st
212219
ksort($tids);
213220
$tid = end($tids);
214221

215-
$path = $this->locatePath('/taxonomy/term/' . $tid . '/edit');
222+
$path = $this->locatePath('/taxonomy/term/' . $tid . $action_subpath);
216223

217224
$this->getSession()->visit($path);
218225
}

tests/behat/features/drupal_taxonomy.feature

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@taxonomy
12
Feature: Check that TaxonomyTrait works
23
As Behat Steps library developer
34
I want to provide tools to manage taxonomy terms programmatically
@@ -154,19 +155,19 @@ Feature: Check that TaxonomyTrait works
154155
"""
155156

156157
@api
157-
Scenario: Assert "When I visit the :vocabulary_machine_name vocabulary :term_name term page" works
158+
Scenario: Assert "When I visit the :vocabulary_machine_name term page with the name :term_name" works
158159
Given I am logged in as a user with the "administrator" role
159-
When I visit the "tags" vocabulary "Tag1" term page
160+
When I visit the "tags" term page with the name "Tag1"
160161
Then the response should contain "200"
161162
And I should see "Tag1"
162163

163164
@api @trait:Drupal\TaxonomyTrait
164-
Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing vocabulary
165+
Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term page with the name :term_name" fails with non-existing vocabulary
165166
Given some behat configuration
166167
And scenario steps:
167168
"""
168169
Given I am logged in as a user with the "administrator" role
169-
When I visit the "nonexisting" vocabulary "Tag1" term page
170+
When I visit the "nonexisting" term page with the name "Tag1"
170171
"""
171172
When I run "behat --no-colors"
172173
Then it should fail with an exception:
@@ -175,12 +176,12 @@ Feature: Check that TaxonomyTrait works
175176
"""
176177

177178
@api @trait:Drupal\TaxonomyTrait
178-
Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing term
179+
Scenario: Assert negative assertion for "When I visit the :vocabulary_machine_name term page with the name :term_name" fails with non-existing term
179180
Given some behat configuration
180181
And scenario steps:
181182
"""
182183
Given I am logged in as a user with the "administrator" role
183-
When I visit the "tags" vocabulary "Nonexisting" term page
184+
When I visit the "tags" term page with the name "Nonexisting"
184185
"""
185186
When I run "behat --no-colors"
186187
Then it should fail with an exception:
@@ -189,19 +190,19 @@ Feature: Check that TaxonomyTrait works
189190
"""
190191

191192
@api
192-
Scenario: Assert "When I edit the :vocabulary_machine_name vocabulary :term_name term page" works
193+
Scenario: Assert "When I visit the :vocabulary_machine_name term edit page with the name :term_name" works
193194
Given I am logged in as a user with the "administrator" role
194-
When I edit the "tags" vocabulary "Tag1" term page
195+
When I visit the "tags" term edit page with the name "Tag1"
195196
Then the response should contain "200"
196197
And I should see "Tag1"
197198

198199
@api @trait:Drupal\TaxonomyTrait
199-
Scenario: Assert negative assertion for "When I edit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing vocabulary
200+
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
200201
Given some behat configuration
201202
And scenario steps:
202203
"""
203204
Given I am logged in as a user with the "administrator" role
204-
When I edit the "nonexisting" vocabulary "Tag1" term page
205+
When I visit the "nonexisting" term edit page with the name "Tag1"
205206
"""
206207
When I run "behat --no-colors"
207208
Then it should fail with an exception:
@@ -210,12 +211,47 @@ Feature: Check that TaxonomyTrait works
210211
"""
211212

212213
@api @trait:Drupal\TaxonomyTrait
213-
Scenario: Assert negative assertion for "When I edit the :vocabulary_machine_name vocabulary :term_name term page" fails with non-existing term
214+
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
214215
Given some behat configuration
215216
And scenario steps:
216217
"""
217218
Given I am logged in as a user with the "administrator" role
218-
When I edit the "tags" vocabulary "Nonexisting" term page
219+
When I visit the "tags" term edit page with the name "Nonexisting"
220+
"""
221+
When I run "behat --no-colors"
222+
Then it should fail with an exception:
223+
"""
224+
Unable to find the term "Nonexisting" in the vocabulary "tags".
225+
"""
226+
227+
@api
228+
Scenario: Assert "When I visit the :vocabulary_machine_name term delete page with the name :term_name" works
229+
Given I am logged in as a user with the "administrator" role
230+
When I visit the "tags" term delete page with the name "Tag1"
231+
Then the response should contain "200"
232+
And I should see "Tag1"
233+
234+
@api @trait:Drupal\TaxonomyTrait
235+
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
236+
Given some behat configuration
237+
And scenario steps:
238+
"""
239+
Given I am logged in as a user with the "administrator" role
240+
When I visit the "nonexisting" term delete page with the name "Tag1"
241+
"""
242+
When I run "behat --no-colors"
243+
Then it should fail with an exception:
244+
"""
245+
The vocabulary "nonexisting" does not exist.
246+
"""
247+
248+
@api @trait:Drupal\TaxonomyTrait
249+
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
250+
Given some behat configuration
251+
And scenario steps:
252+
"""
253+
Given I am logged in as a user with the "administrator" role
254+
When I visit the "tags" term delete page with the name "Nonexisting"
219255
"""
220256
When I run "behat --no-colors"
221257
Then it should fail with an exception:

0 commit comments

Comments
 (0)