Spike PHPCoverage Details: path.test

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