3 namespace Drupal\pathauto\Tests;
4 use Drupal\simpletest\WebTestBase;
7 * Tests pathauto taxonomy UI integration.
11 class PathautoTaxonomyWebTest extends WebTestBase {
13 use PathautoTestHelperTrait;
20 public static $modules = array('taxonomy', 'pathauto', 'views');
25 * @var \Drupal\user\UserInterface
35 // Allow other modules to add additional permissions for the admin user.
37 'administer pathauto',
38 'administer url aliases',
40 'administer taxonomy',
42 $this->adminUser = $this->drupalCreateUser($permissions);
43 $this->drupalLogin($this->adminUser);
45 $this->createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]');
49 * Basic functional testing of Pathauto with taxonomy terms.
51 function testTermEditing() {
52 $this->drupalGet('admin/structure');
53 $this->drupalGet('admin/structure/taxonomy');
55 // Add vocabulary "tags".
56 $vocabulary = $this->addVocabulary(array('name' => 'tags', 'vid' => 'tags'));
58 // Create term for testing.
59 $name = 'Testing: term name [';
60 $automatic_alias = '/tags/testing-term-name';
61 $this->drupalPostForm('admin/structure/taxonomy/manage/tags/add', array('name[0][value]' => $name), 'Save');
63 $this->assertText("Created new term $name.");
64 $term = $this->drupalGetTermByName($name);
66 // Look for alias generated in the form.
67 $this->drupalGet("taxonomy/term/{$term->id()}/edit");
68 $this->assertFieldChecked('edit-path-0-pathauto');
69 $this->assertFieldByName('path[0][alias]', $automatic_alias, 'Generated alias visible in the path alias field.');
71 // Check whether the alias actually works.
72 $this->drupalGet($automatic_alias);
73 $this->assertText($name, 'Term accessible through automatic alias.');
75 // Manually set the term's alias.
76 $manual_alias = '/tags/' . $term->id();
78 'path[0][pathauto]' => FALSE,
79 'path[0][alias]' => $manual_alias,
81 $this->drupalPostForm("taxonomy/term/{$term->id()}/edit", $edit, t('Save'));
82 $this->assertText("Updated term $name.");
84 // Check that the automatic alias checkbox is now unchecked by default.
85 $this->drupalGet("taxonomy/term/{$term->id()}/edit");
86 $this->assertNoFieldChecked('edit-path-0-pathauto');
87 $this->assertFieldByName('path[0][alias]', $manual_alias);
89 // Submit the term form with the default values.
90 $this->drupalPostForm(NULL, array('path[0][pathauto]' => FALSE), t('Save'));
91 $this->assertText("Updated term $name.");
93 // Test that the old (automatic) alias has been deleted and only accessible
94 // through the new (manual) alias.
95 $this->drupalGet($automatic_alias);
96 $this->assertResponse(404, 'Term not accessible through automatic alias.');
97 $this->drupalGet($manual_alias);
98 $this->assertText($name, 'Term accessible through manual alias.');