| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: content_access_acl.test,v 1.1.4.2 2009/01/02 15:01:01 fago Exp $ 3 4 /** 5 * @file 6 * Automatd SimpleTest Case for using content access module with acl module 7 */ 8 9 require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php'); 10 11 class ContentAccessACLTestCase extends ContentAccessTestCase { 12 13 var $node; 14 15 /** 16 * Implementation of get_info() for information 17 */ 18 function getInfo() { 19 return array( 20 'name' => t('Content Access Module with ACL Module Tests'), 21 'description' => t('Various tests to check the combination of content access and ACL module.'), 22 'group' => 'Content Access', 23 ); 24 } 25 26 /** 27 * Setup configuration before each test 28 */ 29 function setUp() { 30 31 parent::setUp('acl'); 32 33 // Create test nodes 34 $this->node = $this->drupalCreateNode(array('type' => $this->content_type_name)); 35 } 36 37 /** 38 * Test Viewing accessibility with permissions for single users 39 */ 40 function testViewAccess() { 41 42 // Exit test if ACL module could not be enabled 43 if (!module_exists('acl')) { 44 $this->pass('No ACL module present, skipping test'); 45 return; 46 } 47 48 // Restrict access to this content type (access is only allowed for the author) 49 // Enable per node access control 50 $access_permissions = array( 51 'view[1]' => FALSE, 52 'view[2]' => FALSE, 53 'per_node' => TRUE, 54 ); 55 $this->changeAccessContentType($access_permissions); 56 57 // Allow access for test user 58 $edit = array( 59 'acl[view][add]' => $this->test_user->name, 60 ); 61 $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User')); 62 $this->drupalPost(NULL, array(), t('Submit')); 63 64 // Logout admin, try to access the node anonymously 65 $this->drupalLogout(); 66 $this->drupalGet('node/'. $this->node->nid); 67 $this->assertText(t('Access denied'), 'node is not viewable'); 68 69 // Login test user, view access should be allowed now 70 $this->drupalLogin($this->test_user); 71 $this->drupalGet('node/'. $this->node->nid); 72 $this->assertNoText(t('Access denied'), 'node is viewable'); 73 74 // Login admin and disable per node access 75 $this->drupalLogin($this->admin_user); 76 $this->changeAccessPerNode(FALSE); 77 78 // Logout admin, try to access the node anonymously 79 $this->drupalLogout(); 80 $this->drupalGet('node/'. $this->node->nid); 81 $this->assertText(t('Access denied'), 'node is not viewable'); 82 83 // Login test user, view access should be denied now 84 $this->drupalLogin($this->test_user); 85 $this->drupalGet('node/'. $this->node->nid); 86 $this->assertText(t('Access denied'), 'node is not viewable'); 87 } 88 89 /** 90 * Test Editing accessibility with permissions for single users 91 */ 92 function testEditAccess() { 93 94 // Exit test if ACL module could not be enabled 95 if (!module_exists('acl')) { 96 $this->pass('No ACL module present, skipping test'); 97 return; 98 } 99 100 // Enable per node access control 101 $this->changeAccessPerNode(); 102 103 // Allow edit access for test user 104 $edit = array( 105 'acl[update][add]' => $this->test_user->name, 106 ); 107 $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User')); 108 $this->drupalPost(NULL, array(), t('Submit')); 109 110 // Logout admin, try to edit the node anonymously 111 $this->drupalLogout(); 112 $this->drupalGet('node/'. $this->node->nid .'/edit'); 113 $this->assertText(t('Access denied'), 'node is not editable'); 114 115 // Login test user, edit access should be allowed now 116 $this->drupalLogin($this->test_user); 117 $this->drupalGet('node/'. $this->node->nid .'/edit'); 118 $this->assertNoText(t('Access denied'), 'node is editable'); 119 120 // Login admin and disable per node access 121 $this->drupalLogin($this->admin_user); 122 $this->changeAccessPerNode(FALSE); 123 124 // Logout admin, try to edit the node anonymously 125 $this->drupalLogout(); 126 $this->drupalGet('node/'. $this->node->nid .'/edit'); 127 $this->assertText(t('Access denied'), 'node is not editable'); 128 129 // Login test user, edit access should be denied now 130 $this->drupalLogin($this->test_user); 131 $this->drupalGet('node/'. $this->node->nid .'/edit'); 132 $this->assertText(t('Access denied'), 'node is not editable'); 133 } 134 135 /** 136 * Test Deleting accessibility with permissions for single users 137 */ 138 function testDeleteAccess() { 139 140 // Exit test if ACL module could not be enabled 141 if (!module_exists('acl')) { 142 $this->pass('No ACL module present, skipping test'); 143 return; 144 } 145 146 // Enable per node access control 147 $this->changeAccessPerNode(); 148 149 // Allow delete access for test user 150 $edit = array( 151 'acl[delete][add]' => $this->test_user->name, 152 ); 153 $this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User')); 154 $this->drupalPost(NULL, array(), t('Submit')); 155 156 // Logout admin, try to delete the node anonymously 157 $this->drupalLogout(); 158 $this->drupalGet('node/'. $this->node->nid .'/delete'); 159 $this->assertText(t('Access denied'), 'node is not deletable'); 160 161 // Login test user, delete access should be allowed now 162 $this->drupalLogin($this->test_user); 163 $this->drupalGet('node/'. $this->node->nid .'/delete'); 164 $this->assertNoText(t('Access denied'), 'node is deletable'); 165 166 // Login admin and disable per node access 167 $this->drupalLogin($this->admin_user); 168 $this->changeAccessPerNode(FALSE); 169 170 // Logout admin, try to delete the node anonymously 171 $this->drupalLogout(); 172 $this->drupalGet('node/'. $this->node->nid .'/delete'); 173 $this->assertText(t('Access denied'), 'node is not deletable'); 174 175 // Login test user, delete access should be denied now 176 $this->drupalLogin($this->test_user); 177 $this->drupalGet('node/'. $this->node->nid .'/delete'); 178 $this->assertText(t('Access denied'), 'node is not deletable'); 179 } 180 181 }
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 |