comparison core/modules/path/tests/src/Functional/PathAdminTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\path\Functional;
4
5 /**
6 * Tests the Path admin UI.
7 *
8 * @group path
9 */
10 class PathAdminTest extends PathTestBase {
11
12 /**
13 * Modules to enable.
14 *
15 * @var array
16 */
17 public static $modules = ['path'];
18
19 protected function setUp() {
20 parent::setUp();
21
22 // Create test user and log in.
23 $web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer url aliases', 'create url aliases']);
24 $this->drupalLogin($web_user);
25 }
26
27 /**
28 * Tests the filtering aspect of the Path UI.
29 */
30 public function testPathFiltering() {
31 // Create test nodes.
32 $node1 = $this->drupalCreateNode();
33 $node2 = $this->drupalCreateNode();
34 $node3 = $this->drupalCreateNode();
35
36 // Create aliases.
37 $alias1 = '/' . $this->randomMachineName(8);
38 $edit = [
39 'source' => '/node/' . $node1->id(),
40 'alias' => $alias1,
41 ];
42 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
43
44 $alias2 = '/' . $this->randomMachineName(8);
45 $edit = [
46 'source' => '/node/' . $node2->id(),
47 'alias' => $alias2,
48 ];
49 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
50
51 $alias3 = '/' . $this->randomMachineName(4) . '/' . $this->randomMachineName(4);
52 $edit = [
53 'source' => '/node/' . $node3->id(),
54 'alias' => $alias3,
55 ];
56 $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));
57
58 // Filter by the first alias.
59 $edit = [
60 'filter' => $alias1,
61 ];
62 $this->drupalPostForm(NULL, $edit, t('Filter'));
63 $this->assertLinkByHref($alias1);
64 $this->assertNoLinkByHref($alias2);
65 $this->assertNoLinkByHref($alias3);
66
67 // Filter by the second alias.
68 $edit = [
69 'filter' => $alias2,
70 ];
71 $this->drupalPostForm(NULL, $edit, t('Filter'));
72 $this->assertNoLinkByHref($alias1);
73 $this->assertLinkByHref($alias2);
74 $this->assertNoLinkByHref($alias3);
75
76 // Filter by the third alias which has a slash.
77 $edit = [
78 'filter' => $alias3,
79 ];
80 $this->drupalPostForm(NULL, $edit, t('Filter'));
81 $this->assertNoLinkByHref($alias1);
82 $this->assertNoLinkByHref($alias2);
83 $this->assertLinkByHref($alias3);
84
85 // Filter by a random string with a different length.
86 $edit = [
87 'filter' => $this->randomMachineName(10),
88 ];
89 $this->drupalPostForm(NULL, $edit, t('Filter'));
90 $this->assertNoLinkByHref($alias1);
91 $this->assertNoLinkByHref($alias2);
92
93 // Reset the filter.
94 $edit = [];
95 $this->drupalPostForm(NULL, $edit, t('Reset'));
96 $this->assertLinkByHref($alias1);
97 $this->assertLinkByHref($alias2);
98 }
99
100 }