| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: content_access.test,v 1.1.4.2 2009/01/02 15:01:01 fago Exp $ 3 4 /** 5 * @file 6 * Automatd SimpleTest Case for content access module 7 */ 8 9 require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php'); 10 11 class ContentAccessModuleTestCase extends ContentAccessTestCase { 12 13 /** 14 * Implementation of get_info() for information 15 */ 16 function getInfo() { 17 return array( 18 'name' => t('Content Access Module Tests'), 19 'description' => t('Various tests to check permission settings on nodes.'), 20 'group' => t('Content Access'), 21 ); 22 } 23 24 function setUp() { 25 parent::setUp(); 26 27 // Create test nodes 28 $this->node1 = $this->drupalCreateNode(array('type' => $this->content_type_name)); 29 $this->node2 = $this->drupalCreateNode(array('type' => $this->content_type_name)); 30 } 31 32 /** 33 * Test for viewing nodes 34 */ 35 function testViewAccess() { 36 37 // Restrict access to the content type (access is only allowed for the author) 38 $access_permissions = array( 39 'view[1]' => FALSE, 40 'view[2]' => FALSE, 41 ); 42 $this->changeAccessContentType($access_permissions); 43 44 // Logout admin and try to access the node anonymously 45 $this->drupalLogout(); 46 $this->drupalGet('node/'. $this->node1->nid); 47 $this->assertText(t('Access denied'), 'node is not viewable'); 48 49 // Login test user, view node, access must be denied 50 $this->drupalLogin($this->test_user); 51 $this->drupalGet('node/'. $this->node1->nid); 52 $this->assertText(t('Access denied'), 'node is not viewable'); 53 54 // Login admin and grant access for viewing to the test user 55 $this->drupalLogin($this->admin_user); 56 $this->changeAccessContentTypeKeyword('view'); 57 58 // Logout admin and try to access the node anonymously 59 // access must be denied again 60 $this->drupalLogout(); 61 $this->drupalGet('node/'. $this->node1->nid); 62 $this->assertText(t('Access denied'), 'node is not viewable'); 63 64 // Login test user, view node, access must be granted 65 $this->drupalLogin($this->test_user); 66 $this->drupalGet('node/'. $this->node1->nid); 67 $this->assertNoText(t('Access denied'), 'node is viewable'); 68 69 // Login admin and enable per node access 70 $this->drupalLogin($this->admin_user); 71 $this->changeAccessPerNode(); 72 73 // Restrict access on node2 for the test user role 74 $this->changeAccessNodeKeyword($this->node2, 'view', FALSE); 75 76 // Logout admin and try to access both nodes anonymously 77 $this->drupalLogout(); 78 $this->drupalGet('node/'. $this->node1->nid); 79 $this->assertText(t('Access denied'), 'node1 is not viewable'); 80 $this->drupalGet('node/'. $this->node2->nid); 81 $this->assertText(t('Access denied'), 'node2 is not viewable'); 82 83 // Login test user, view node1, access must be granted 84 $this->drupalLogin($this->test_user); 85 $this->drupalGet('node/'. $this->node1->nid); 86 $this->assertNoText(t('Access denied'), 'node1 is viewable'); 87 88 // View node2, access must be denied 89 $this->drupalGet('node/'. $this->node2->nid); 90 $this->assertText(t('Access denied'), 'node2 is not viewable'); 91 92 // Login admin, swap permissions between content type and node2 93 $this->drupalLogin($this->admin_user); 94 95 // Restrict access to content type 96 $this->changeAccessContentTypeKeyword('view', FALSE); 97 98 // Grant access to node2 99 $this->changeAccessNodeKeyword($this->node2, 'view'); 100 101 // Logout admin and try to access both nodes anonymously 102 $this->drupalLogout(); 103 $this->drupalGet('node/'. $this->node1->nid); 104 $this->assertText(t('Access denied'), 'node1 is not viewable'); 105 $this->drupalGet('node/'. $this->node2->nid); 106 $this->assertText(t('Access denied'), 'node2 is not viewable'); 107 108 // Login test user, view node1, access must be denied 109 $this->drupalLogin($this->test_user); 110 $this->drupalGet('node/'. $this->node1->nid); 111 $this->assertText(t('Access denied'), 'node1 is not viewable'); 112 113 // View node2, access must be granted 114 $this->drupalGet('node/'. $this->node2->nid); 115 $this->assertNoText(t('Access denied'), 'node2 is viewable'); 116 } 117 118 /** 119 * Test for editing nodes 120 */ 121 function testEditAccess() { 122 123 // Logout admin and try to edit the node anonymously 124 $this->drupalLogout(); 125 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 126 $this->assertText(t('Access denied'), 'edit access denied for anonymous'); 127 128 // Login test user, edit node, access must be denied 129 $this->drupalLogin($this->test_user); 130 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 131 $this->assertText(t('Access denied'), 'edit access denied for test user'); 132 133 // Login admin and grant access for editing to the test user 134 $this->drupalLogin($this->admin_user); 135 $this->changeAccessContentTypeKeyword('update'); 136 137 // Logout admin and try to edit the node anonymously 138 // access must be denied again 139 $this->drupalLogout(); 140 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 141 $this->assertText(t('Access denied'), 'edit access denied for anonymous'); 142 143 // Login test user, edit node, access must be granted 144 $this->drupalLogin($this->test_user); 145 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 146 $this->assertNoText(t('Access denied'), 'node1 is editable'); 147 148 // Login admin and enable per node access 149 $this->drupalLogin($this->admin_user); 150 $this->changeAccessPerNode(); 151 152 // Restrict access for this content type for the test user 153 $this->changeAccessContentTypeKeyword('update', FALSE); 154 155 // Allow acces for node1 only 156 $this->changeAccessNodeKeyword($this->node1, 'update'); 157 158 // Logout admin and try to edit both nodes anonymously 159 $this->drupalLogout(); 160 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 161 $this->assertText(t('Access denied'), 'node1 is not editable'); 162 $this->drupalGet('node/'. $this->node2->nid .'/edit'); 163 $this->assertText(t('Access denied'), 'node2 is not editable'); 164 165 // Login test user, edit node1, access must be granted 166 $this->drupalLogin($this->test_user); 167 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 168 $this->assertNoText(t('Access denied'), 'node1 is editable'); 169 170 // Edit node2, access must be denied 171 $this->drupalGet('node/'. $this->node2->nid .'/edit'); 172 $this->assertText(t('Access denied'), 'node2 is not editable'); 173 174 // Login admin, swap permissions between node1 and node2 175 $this->drupalLogin($this->admin_user); 176 177 // Grant edit access to node2 178 $this->changeAccessNodeKeyword($this->node2, 'update'); 179 // Restrict edit acces to node1 180 $this->changeAccessNodeKeyword($this->node1, 'update', FALSE); 181 182 // Logout admin and try to edit both nodes anonymously 183 $this->drupalLogout(); 184 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 185 $this->assertText(t('Access denied'), 'node1 is not editable'); 186 $this->drupalGet('node/'. $this->node2->nid .'/edit'); 187 $this->assertText(t('Access denied'), 'node2 is not editable'); 188 189 // Login test user, edit node1, access must be denied 190 $this->drupalLogin($this->test_user); 191 $this->drupalGet('node/'. $this->node1->nid .'/edit'); 192 $this->assertText(t('Access denied'), 'node1 is not editable'); 193 194 // Edit node2, access must be granted 195 $this->drupalGet('node/'. $this->node2->nid .'/edit'); 196 $this->assertNoText(t('Access denied'), 'node2 is editable'); 197 } 198 199 /** 200 * Test for deleting nodes 201 */ 202 function testDeleteAccess() { 203 204 // Logout admin and try to delete the node anonymously 205 $this->drupalLogout(); 206 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 207 $this->assertText(t('Access denied'), 'delete access denied for anonymous'); 208 209 // Login test user, delete node, access must be denied 210 $this->drupalLogin($this->test_user); 211 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 212 $this->assertText(t('Access denied'), 'delete access denied for test user'); 213 214 // Login admin and grant access for deleting to the test user 215 $this->drupalLogin($this->admin_user); 216 217 $this->changeAccessContentTypeKeyword('delete'); 218 219 // Logout admin and try to edit the node anonymously 220 // access must be denied again 221 $this->drupalLogout(); 222 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 223 $this->assertText(t('Access denied'), 'delete access denied for anonymous'); 224 225 // Login test user, delete node, access must be granted 226 $this->drupalLogin($this->test_user); 227 $this->drupalPost('node/'. $this->node1->nid .'/delete', array(), 'Delete'); 228 $this->assertRaw(t('%node has been deleted', array('%node' => $this->node1->title)), 'Test node was deleted successfully by test user'); 229 230 // Login admin and recreate test node1 231 $this->drupalLogin($this->admin_user); 232 $this->node1 = $this->drupalCreateNode(array('type' => $this->content_type_name)); 233 234 // Enable per node access 235 $this->changeAccessPerNode(); 236 237 // Restrict access for this content type for the test user 238 $this->changeAccessContentTypeKeyword('delete', FALSE); 239 240 // Allow acces for node1 only 241 $this->changeAccessNodeKeyword($this->node1, 'delete'); 242 243 // Logout admin and try to delete both nodes anonymously 244 $this->drupalLogout(); 245 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 246 $this->assertText(t('Access denied'), 'node1 is not deletable'); 247 $this->drupalGet('node/'. $this->node2->nid .'/delete'); 248 $this->assertText(t('Access denied'), 'node2 is not deletable'); 249 250 // Login test user, delete node1, access must be granted 251 $this->drupalLogin($this->test_user); 252 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 253 $this->assertNoText(t('Access denied'), 'node1 is deletable'); 254 255 // Delete node2, access must be denied 256 $this->drupalGet('node/'. $this->node2->nid .'/delete'); 257 $this->assertText(t('Access denied'), 'node2 is not deletable'); 258 259 // Login admin, swap permissions between node1 and node2 260 $this->drupalLogin($this->admin_user); 261 262 // Grant delete access to node2 263 $this->changeAccessNodeKeyword($this->node2, 'delete'); 264 // Restrict delete acces to node1 265 $this->changeAccessNodeKeyword($this->node1, 'delete', FALSE); 266 267 // Logout admin and try to delete both nodes anonymously 268 $this->drupalLogout(); 269 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 270 $this->assertText(t('Access denied'), 'node1 is not deletable'); 271 $this->drupalGet('node/'. $this->node2->nid .'/delete'); 272 $this->assertText(t('Access denied'), 'node2 is not deletable'); 273 274 // Login test user, delete node1, access must be denied 275 $this->drupalLogin($this->test_user); 276 $this->drupalGet('node/'. $this->node1->nid .'/delete'); 277 $this->assertText(t('Access denied'), 'node1 is not deletable'); 278 279 // Delete node2, access must be granted 280 $this->drupalGet('node/'. $this->node2->nid .'/delete'); 281 $this->assertNoText(t('Access denied'), 'node2 is deletable'); 282 } 283 284 /** 285 * Test own view access 286 */ 287 function testOwnViewAccess() { 288 289 // Setup 2 test users 290 $test_user1 = $this->test_user; 291 $test_user2 = $this->drupalCreateUser(); 292 293 // Change ownership of test nodes to test users 294 $this->node1->uid = $test_user1->uid; 295 node_save($this->node1); 296 $this->node2->uid = $test_user2->uid; 297 node_save($this->node2); 298 299 // Remove all view permissions for this content type 300 $access_permissions = array( 301 'view[1]' => FALSE, 302 'view[2]' => FALSE, 303 'view_own[1]' => FALSE, 304 'view_own[2]' => FALSE, 305 ); 306 $this->changeAccessContentType($access_permissions); 307 308 // Allow view own content for test user 1 and 2 roles 309 $this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user1); 310 $this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user2); 311 312 // Logout admin and try to access both nodes anonymously 313 $this->drupalLogout(); 314 $this->drupalGet('node/'. $this->node1->nid); 315 $this->assertText(t('Access denied'), 'node1 is not viewable'); 316 $this->drupalGet('node/'. $this->node2->nid); 317 $this->assertText(t('Access denied'), 'node2 is not viewable'); 318 319 // Login test user 1, view node1, access must be granted 320 $this->drupalLogin($test_user1); 321 $this->drupalGet('node/'. $this->node1->nid); 322 $this->assertNoText(t('Access denied'), 'node1 is viewable'); 323 324 // View node2, access must be denied 325 $this->drupalGet('node/'. $this->node2->nid); 326 $this->assertText(t('Access denied'), 'node2 is not viewable'); 327 328 // Login test user 2, view node1, access must be denied 329 $this->drupalLogin($test_user2); 330 $this->drupalGet('node/'. $this->node1->nid); 331 $this->assertText(t('Access denied'), 'node1 is not viewable'); 332 333 // View node2, access must be granted 334 $this->drupalGet('node/'. $this->node2->nid); 335 $this->assertNoText(t('Access denied'), 'node2 is viewable'); 336 } 337 338 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |