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]');
50 * Basic functional testing of Pathauto with taxonomy terms.
52 function testTermEditing() {
53 $this->drupalGet('admin/structure');
54 $this->drupalGet('admin/structure/taxonomy');
56 // Add vocabulary "tags".
57 $vocabulary = $this->addVocabulary(array('name' => 'tags', 'vid' => 'tags'));
59 // Create term for testing.
60 $name = 'Testing: term name [';
61 $automatic_alias = '/tags/testing-term-name';
62 $this->drupalPostForm('admin/structure/taxonomy/manage/tags/add', array('name[0][value]' => $name), 'Save');
64 $this->assertText("Created new term $name.");
65 $term = $this->drupalGetTermByName($name);
67 // Look for alias generated in the form.
68 $this->drupalGet("taxonomy/term/{$term->id()}/edit");
69 $this->assertFieldChecked('edit-path-0-pathauto');
70 $this->assertFieldByName('path[0][alias]', $automatic_alias, 'Generated alias visible in the path alias field.');
72 // Check whether the alias actually works.
73 $this->drupalGet($automatic_alias);
74 $this->assertText($name, 'Term accessible through automatic alias.');
76 // Manually set the term's alias.
77 $manual_alias = '/tags/' . $term->id();
79 'path[0][pathauto]' => FALSE,
80 'path[0][alias]' => $manual_alias,
82 $this->drupalPostForm("taxonomy/term/{$term->id()}/edit", $edit, t('Save'));
83 $this->assertText("Updated term $name.");
85 // Check that the automatic alias checkbox is now unchecked by default.
86 $this->drupalGet("taxonomy/term/{$term->id()}/edit");
87 $this->assertNoFieldChecked('edit-path-0-pathauto');
88 $this->assertFieldByName('path[0][alias]', $manual_alias);
90 // Submit the term form with the default values.
91 $this->drupalPostForm(NULL, array('path[0][pathauto]' => FALSE), t('Save'));
92 $this->assertText("Updated term $name.");
94 // Test that the old (automatic) alias has been deleted and only accessible
95 // through the new (manual) alias.
96 $this->drupalGet($automatic_alias);
97 $this->assertResponse(404, 'Term not accessible through automatic alias.');
98 $this->drupalGet($manual_alias);
99 $this->assertText($name, 'Term accessible through manual alias.');