1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?php
// $Id$
class PathTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Path alias functionality'),
'description' => t('Add, edit, delete, and change alias and verify its consistency in the database.'),
'group' => t('Path'),
);
}
/**
* Create user, setup permissions, log user in, and create a node.
*/
function setUp() {
parent::setUp('path');
// create and login user
$web_user = $this->drupalCreateUser(array('edit own page content', 'create page content', 'administer url aliases', 'create url aliases'));
$this->drupalLogin($web_user);
}
/**
* Test alias functionality through the admin interfaces.
*/
function testAdminAlias() {
// create test node
$node1 = $this->createNode();
// Create alias.
$edit = array();
$edit['src'] = 'node/' . $node1->nid;
$edit['dst'] = $this->randomName(8);
$this->drupalPost('admin/build/path/add', $edit, t('Create new alias'));
// Confirm that the alias works.
$this->drupalGet($edit['dst']);
$this->assertText($node1->title, 'Alias works.');
// Change alias.
$pid = $this->getPID($edit['dst']);
$previous = $edit['dst'];
$edit['dst'] = $this->randomName(8);
$this->drupalPost('admin/build/path/edit/' . $pid, $edit, t('Update alias'));
// Confirm that the alias works.
$this->drupalGet($edit['dst']);
$this->assertText($node1->title, 'Changed alias works.');
// Confirm that previous alias no longer works.
$this->drupalGet($previous);
$this->assertNoText($node1->title, 'Previous alias no longer works.');
$this->assertResponse(404);
// Create second test node.
$node2 = $this->createNode();
// Set alias to second test node.
$edit['src'] = 'node/' . $node2->nid;
// leave $edit['dst'] the same
$this->drupalPost('admin/build/path/add', $edit, t('Create new alias'));
// Confirm no duplicate was created.
$this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['dst'])), 'Attempt to move alias was rejected.');
// Delete alias.
$this->drupalPost('admin/build/path/delete/' . $pid, array(), t('Confirm'));
// Confirm that the alias no longer works.
$this->drupalGet($edit['dst']);
$this->assertNoText($node1->title, 'Alias was successfully deleted.');
}
/**
* Test alias functionality through the node interfaces.
*/
function testNodeAlias() {
// Create test node.
$node1 = $this->createNode();
// Create alias.
$edit = array();
$edit['path'] = $this->randomName(8);
$this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
// Confirm that the alias works.
$this->drupalGet($edit['path']);
$this->assertText($node1->title, 'Alias works.');
// Change alias.
$previous = $edit['path'];
$edit['path'] = $this->randomName(8);
$this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
// Confirm that the alias works.
$this->drupalGet($edit['path']);
$this->assertText($node1->title, 'Changed alias works.');
// Make sure that previous alias no longer works.
$this->drupalGet($previous);
$this->assertNoText($node1->title, 'Previous alias no longer works.');
$this->assertResponse(404);
// Create second test node.
$node2 = $this->createNode();
// Set alias to second test node.
// Leave $edit['path'] the same.
$this->drupalPost('node/' . $node2->nid . '/edit', $edit, t('Save'));
// Confirm that the alias didn't make a duplicate.
$this->assertText(t('The path is already in use.'), 'Attempt to moved alias was rejected.');
// Delete alias.
$this->drupalPost('node/' . $node1->nid . '/edit', array('path' => ''), t('Save'));
// Confirm that the alias no longer works.
$this->drupalGet($edit['path']);
$this->assertNoText($node1->title, 'Alias was successfully deleted.');
}
function getPID($dst) {
return db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $dst));
}
function createNode() {
$edit = array();
$edit['title'] = '!SimpleTest test node! ' . $this->randomName(10);
$edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check to make sure the node was created.
$node = node_load(array('title' => $edit['title']));
$this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database. %s');
return $node;
}
}
|