content_access_acl.test 5.8 KB

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