Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / Tests / PathautoTaxonomyWebTest.php
1 <?php
2
3 namespace Drupal\pathauto\Tests;
4 use Drupal\simpletest\WebTestBase;
5
6 /**
7  * Tests pathauto taxonomy UI integration.
8  *
9  * @group pathauto
10  */
11 class PathautoTaxonomyWebTest extends WebTestBase {
12
13   use PathautoTestHelperTrait;
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = array('taxonomy', 'pathauto', 'views');
21
22   /**
23    * Admin user.
24    *
25    * @var \Drupal\user\UserInterface
26    */
27   protected $adminUser;
28
29   /**
30    * {@inheritdoc}
31    */
32   function setUp() {
33     parent::setUp();
34
35     // Allow other modules to add additional permissions for the admin user.
36     $permissions = array(
37       'administer pathauto',
38       'administer url aliases',
39       'create url aliases',
40       'administer taxonomy',
41     );
42     $this->adminUser = $this->drupalCreateUser($permissions);
43     $this->drupalLogin($this->adminUser);
44
45     $this->createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]');
46   }
47
48   /**
49    * Basic functional testing of Pathauto with taxonomy terms.
50    */
51   function testTermEditing() {
52     $this->drupalGet('admin/structure');
53     $this->drupalGet('admin/structure/taxonomy');
54
55     // Add vocabulary "tags".
56     $vocabulary = $this->addVocabulary(array('name' => 'tags', 'vid' => 'tags'));
57
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');
62     $name = trim($name);
63     $this->assertText("Created new term $name.");
64     $term = $this->drupalGetTermByName($name);
65
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.');
70
71     // Check whether the alias actually works.
72     $this->drupalGet($automatic_alias);
73     $this->assertText($name, 'Term accessible through automatic alias.');
74
75     // Manually set the term's alias.
76     $manual_alias = '/tags/' . $term->id();
77     $edit = array(
78       'path[0][pathauto]' => FALSE,
79       'path[0][alias]' => $manual_alias,
80     );
81     $this->drupalPostForm("taxonomy/term/{$term->id()}/edit", $edit, t('Save'));
82     $this->assertText("Updated term $name.");
83
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);
88
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.");
92
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.');
99   }
100
101 }