e1a7e88a1540bae65d5a094df36d8d0f62cb1785
[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   /**
50    * Basic functional testing of Pathauto with taxonomy terms.
51    */
52   function testTermEditing() {
53     $this->drupalGet('admin/structure');
54     $this->drupalGet('admin/structure/taxonomy');
55
56     // Add vocabulary "tags".
57     $vocabulary = $this->addVocabulary(array('name' => 'tags', 'vid' => 'tags'));
58
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');
63     $name = trim($name);
64     $this->assertText("Created new term $name.");
65     $term = $this->drupalGetTermByName($name);
66
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.');
71
72     // Check whether the alias actually works.
73     $this->drupalGet($automatic_alias);
74     $this->assertText($name, 'Term accessible through automatic alias.');
75
76     // Manually set the term's alias.
77     $manual_alias = '/tags/' . $term->id();
78     $edit = array(
79       'path[0][pathauto]' => FALSE,
80       'path[0][alias]' => $manual_alias,
81     );
82     $this->drupalPostForm("taxonomy/term/{$term->id()}/edit", $edit, t('Save'));
83     $this->assertText("Updated term $name.");
84
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);
89
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.");
93
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.');
100   }
101
102 }