Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / pathauto / src / Tests / PathautoUiTest.php
1 <?php
2
3 namespace Drupal\pathauto\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\pathauto\Entity\PathautoPattern;
7
8 /**
9  * Test basic pathauto functionality.
10  *
11  * @group pathauto
12  */
13 class PathautoUiTest extends WebTestBase {
14
15   use PathautoTestHelperTrait;
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = array('pathauto', 'node');
23
24   /**
25    * Admin user.
26    *
27    * @var \Drupal\user\UserInterface
28    */
29   protected $adminUser;
30
31   /**
32    * {inheritdoc}
33    */
34   function setUp() {
35     parent::setUp();
36
37     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
38     $this->drupalCreateContentType(array('type' => 'article'));
39
40     // Allow other modules to add additional permissions for the admin user.
41     $permissions = array(
42       'administer pathauto',
43       'administer url aliases',
44       'create url aliases',
45       'administer nodes',
46       'bypass node access',
47       'access content overview',
48     );
49     $this->adminUser = $this->drupalCreateUser($permissions);
50     $this->drupalLogin($this->adminUser);
51   }
52
53   function testSettingsValidation() {
54     $edit = array();
55     $edit['max_length'] = 'abc';
56     $edit['max_component_length'] = 'abc';
57     $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration');
58     /*$this->assertText('The field Maximum alias length is not a valid number.');
59     $this->assertText('The field Maximum component length is not a valid number.');*/
60     $this->assertNoText('The configuration options have been saved.');
61
62     $edit['max_length'] = '0';
63     $edit['max_component_length'] = '0';
64     $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration');
65     /*$this->assertText('The field Maximum alias length cannot be less than 1.');
66     $this->assertText('The field Maximum component length cannot be less than 1.');*/
67     $this->assertNoText('The configuration options have been saved.');
68
69     $edit['max_length'] = '999';
70     $edit['max_component_length'] = '999';
71     $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration');
72     /*$this->assertText('The field Maximum alias length cannot be greater than 255.');
73     $this->assertText('The field Maximum component length cannot be greater than 255.');*/
74     $this->assertNoText('The configuration options have been saved.');
75
76     $edit['max_length'] = '50';
77     $edit['max_component_length'] = '50';
78     $this->drupalPostForm('admin/config/search/path/settings', $edit, 'Save configuration');
79     $this->assertText('The configuration options have been saved.');
80   }
81
82   function testPatternsWorkflow() {
83     // Try to save an empty pattern, should not be allowed.
84     $this->drupalGet('admin/config/search/path/patterns/add');
85     $edit = array(
86       'type' => 'canonical_entities:node',
87     );
88     $this->drupalPostAjaxForm(NULL, $edit, 'type');
89     $edit += array(
90       'bundles[page]' => TRUE,
91       'label' => 'Page pattern',
92       'id' => 'page_pattern',
93     );
94     $this->drupalPostForm(NULL, $edit, 'Save');
95     $this->assertText('Path pattern field is required.');
96     $this->assertNoText('The configuration options have been saved.');
97
98     // Try to save an invalid pattern.
99     $edit += array(
100       'pattern' => '[node:title]/[user:name]/[term:name]',
101     );
102     $this->drupalPostForm(NULL, $edit, 'Save');
103     $this->assertText('Path pattern is using the following invalid tokens: [user:name], [term:name].');
104     $this->assertNoText('The configuration options have been saved.');
105
106     $edit['pattern'] = '#[node:title]';
107     $this->drupalPostForm(NULL, $edit, 'Save');
108     $this->assertText('The Path pattern is using the following invalid characters: #.');
109     $this->assertNoText('The configuration options have been saved.');
110
111     // Checking whitespace ending of the string.
112     $edit['pattern'] = '[node:title] ';
113     $this->drupalPostForm(NULL, $edit, 'Save');
114     $this->assertText('The Path pattern doesn\'t allow the patterns ending with whitespace.');
115     $this->assertNoText('The configuration options have been saved.');
116
117     // Fix the pattern, then check that it gets saved successfully.
118     $edit['pattern'] = '[node:title]';
119     $this->drupalPostForm(NULL, $edit, 'Save');
120     $this->assertText('Pattern Page pattern saved.');
121
122     \Drupal::service('pathauto.generator')->resetCaches();
123
124     // Create a node with pattern enabled and check if the pattern applies.
125     $title = 'Page Pattern enabled';
126     $alias = '/page-pattern-enabled';
127     $node = $this->createNode(['title' => $title, 'type' => 'page']);
128     $this->drupalGet($alias);
129     $this->assertResponse(200);
130     $this->assertEntityAlias($node, $alias);
131
132     // Edit workflow, set a new label and weight for the pattern.
133     $this->drupalPostForm('/admin/config/search/path/patterns', ['entities[page_pattern][weight]' => '4'], t('Save'));
134     $this->clickLink(t('Edit'));
135     $this->assertUrl('/admin/config/search/path/patterns/page_pattern');
136     $this->assertFieldByName('pattern', '[node:title]');
137     $this->assertFieldByName('label', 'Page pattern');
138     $this->assertFieldChecked('edit-status');
139     $this->assertLink(t('Delete'));
140
141     $edit = array('label' => 'Test');
142     $this->drupalPostForm('/admin/config/search/path/patterns/page_pattern', $edit, t('Save'));
143     $this->assertText('Pattern Test saved.');
144     // Check that the pattern weight did not change.
145     $this->assertOptionSelected('edit-entities-page-pattern-weight', '4');
146
147     // Disable workflow.
148     $this->drupalGet('/admin/config/search/path/patterns');
149     $this->assertNoLink(t('Enable'));
150     $this->clickLink(t('Disable'));
151     $this->assertUrl('/admin/config/search/path/patterns/page_pattern/disable');
152     $this->drupalPostForm(NULL, [], t('Disable'));
153     $this->assertText('Disabled pattern Test.');
154
155     // Load the pattern from storage and check if its disabled.
156     $pattern = PathautoPattern::load('page_pattern');
157     $this->assertFalse($pattern->status());
158
159     \Drupal::service('pathauto.generator')->resetCaches();
160
161     // Create a node with pattern disabled and check that we have no new alias.
162     $title = 'Page Pattern disabled';
163     $node = $this->createNode(['title' => $title, 'type' => 'page']);
164     $this->assertNoEntityAlias($node);
165
166     // Enable workflow.
167     $this->drupalGet('/admin/config/search/path/patterns');
168     $this->assertNoLink(t('Disable'));
169     $this->clickLink(t('Enable'));
170     $this->assertUrl('/admin/config/search/path/patterns/page_pattern/enable');
171     $this->drupalPostForm(NULL, [], t('Enable'));
172     $this->assertText('Enabled pattern Test.');
173
174     // Reload pattern from storage and check if its enabled.
175     $pattern = PathautoPattern::load('page_pattern');
176     $this->assertTrue($pattern->status());
177
178     // Delete workflow.
179     $this->drupalGet('/admin/config/search/path/patterns');
180     $this->clickLink(t('Delete'));
181     $this->assertUrl('/admin/config/search/path/patterns/page_pattern/delete');
182     $this->assertText(t('This action cannot be undone.'));
183     $this->drupalPostForm(NULL, [], t('Delete'));
184     $this->assertText('The pathauto pattern Test has been deleted.');
185
186     $this->assertFalse(PathautoPattern::load('page_pattern'));
187   }
188
189 }