FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Automatd SimpleTest Case for content access module
|
||||
*/
|
||||
|
||||
require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php');
|
||||
|
||||
class ContentAccessModuleTestCase extends ContentAccessTestCase {
|
||||
|
||||
/**
|
||||
* Implementation of get_info() for information
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => t('Content Access Module Tests'),
|
||||
'description' => t('Various tests to check permission settings on nodes.'),
|
||||
'group' => t('Content Access'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($module = '') {
|
||||
parent::setUp();
|
||||
|
||||
// Create test nodes
|
||||
$this->node1 = $this->drupalCreateNode(array('type' => $this->content_type->type));
|
||||
$this->node2 = $this->drupalCreateNode(array('type' => $this->content_type->type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for viewing nodes
|
||||
*/
|
||||
function testViewAccess() {
|
||||
// Restrict access to the content type (access is only allowed for the author)
|
||||
$access_permissions = array(
|
||||
'view[1]' => FALSE,
|
||||
'view[2]' => FALSE,
|
||||
);
|
||||
$this->changeAccessContentType($access_permissions);
|
||||
|
||||
// Logout admin and try to access the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
|
||||
// Login test user, view node, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
|
||||
// Login admin and grant access for viewing to the test user
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessContentTypeKeyword('view');
|
||||
|
||||
// Logout admin and try to access the node anonymously
|
||||
// access must be denied again
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
|
||||
// Login test user, view node, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node is viewable');
|
||||
|
||||
// Login admin and enable per node access
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessPerNode();
|
||||
|
||||
// Restrict access on node2 for the test user role
|
||||
$this->changeAccessNodeKeyword($this->node2, 'view', FALSE);
|
||||
|
||||
// Logout admin and try to access both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node1 is not viewable');
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertText(t('Access denied'), 'node2 is not viewable');
|
||||
|
||||
// Login test user, view node1, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node1 is viewable');
|
||||
|
||||
// View node2, access must be denied
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertText(t('Access denied'), 'node2 is not viewable');
|
||||
|
||||
// Login admin, swap permissions between content type and node2
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Restrict access to content type
|
||||
$this->changeAccessContentTypeKeyword('view', FALSE);
|
||||
|
||||
// Grant access to node2
|
||||
$this->changeAccessNodeKeyword($this->node2, 'view');
|
||||
|
||||
// Logout admin and try to access both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node1 is not viewable');
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertText(t('Access denied'), 'node2 is not viewable');
|
||||
|
||||
// Login test user, view node1, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node1 is not viewable');
|
||||
|
||||
// View node2, access must be granted
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node2 is viewable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for editing nodes
|
||||
*/
|
||||
function testEditAccess() {
|
||||
// Logout admin and try to edit the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'edit access denied for anonymous');
|
||||
|
||||
// Login test user, edit node, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'edit access denied for test user');
|
||||
|
||||
// Login admin and grant access for editing to the test user
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessContentTypeKeyword('update');
|
||||
|
||||
// Logout admin and try to edit the node anonymously
|
||||
// access must be denied again
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'edit access denied for anonymous');
|
||||
|
||||
// Login test user, edit node, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertNoText(t('Access denied'), 'node1 is editable');
|
||||
|
||||
// Login admin and enable per node access
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessPerNode();
|
||||
|
||||
// Restrict access for this content type for the test user
|
||||
$this->changeAccessContentTypeKeyword('update', FALSE);
|
||||
|
||||
// Allow acces for node1 only
|
||||
$this->changeAccessNodeKeyword($this->node1, 'update');
|
||||
|
||||
// Logout admin and try to edit both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node1 is not editable');
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node2 is not editable');
|
||||
|
||||
// Login test user, edit node1, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertNoText(t('Access denied'), 'node1 is editable');
|
||||
|
||||
// Edit node2, access must be denied
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node2 is not editable');
|
||||
|
||||
// Login admin, swap permissions between node1 and node2
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Grant edit access to node2
|
||||
$this->changeAccessNodeKeyword($this->node2, 'update');
|
||||
// Restrict edit acces to node1
|
||||
$this->changeAccessNodeKeyword($this->node1, 'update', FALSE);
|
||||
|
||||
// Logout admin and try to edit both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node1 is not editable');
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node2 is not editable');
|
||||
|
||||
// Login test user, edit node1, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node1 is not editable');
|
||||
|
||||
// Edit node2, access must be granted
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
||||
$this->assertNoText(t('Access denied'), 'node2 is editable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for deleting nodes
|
||||
*/
|
||||
function testDeleteAccess() {
|
||||
// Logout admin and try to delete the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'delete access denied for anonymous');
|
||||
|
||||
// Login test user, delete node, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'delete access denied for test user');
|
||||
|
||||
// Login admin and grant access for deleting to the test user
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
$this->changeAccessContentTypeKeyword('delete');
|
||||
|
||||
// Logout admin and try to edit the node anonymously
|
||||
// access must be denied again
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'delete access denied for anonymous');
|
||||
|
||||
// Login test user, delete node, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalPost('node/'. $this->node1->nid .'/delete', array(), 'Delete');
|
||||
$this->assertRaw(t('%node has been deleted', array('%node' => $this->node1->title)), 'Test node was deleted successfully by test user');
|
||||
|
||||
// Login admin and recreate test node1
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->node1 = $this->drupalCreateNode(array('type' => $this->content_type->type));
|
||||
|
||||
// Enable per node access
|
||||
$this->changeAccessPerNode();
|
||||
|
||||
// Restrict access for this content type for the test user
|
||||
$this->changeAccessContentTypeKeyword('delete', FALSE);
|
||||
|
||||
// Allow acces for node1 only
|
||||
$this->changeAccessNodeKeyword($this->node1, 'delete');
|
||||
|
||||
// Logout admin and try to delete both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node1 is not deletable');
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node2 is not deletable');
|
||||
|
||||
// Login test user, delete node1, access must be granted
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertNoText(t('Access denied'), 'node1 is deletable');
|
||||
|
||||
// Delete node2, access must be denied
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node2 is not deletable');
|
||||
|
||||
// Login admin, swap permissions between node1 and node2
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Grant delete access to node2
|
||||
$this->changeAccessNodeKeyword($this->node2, 'delete');
|
||||
// Restrict delete acces to node1
|
||||
$this->changeAccessNodeKeyword($this->node1, 'delete', FALSE);
|
||||
|
||||
// Logout admin and try to delete both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node1 is not deletable');
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node2 is not deletable');
|
||||
|
||||
// Login test user, delete node1, access must be denied
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node1 is not deletable');
|
||||
|
||||
// Delete node2, access must be granted
|
||||
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
||||
$this->assertNoText(t('Access denied'), 'node2 is deletable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test own view access
|
||||
*/
|
||||
function testOwnViewAccess() {
|
||||
// Setup 2 test users
|
||||
$test_user1 = $this->test_user;
|
||||
$test_user2 = $this->drupalCreateUser();
|
||||
|
||||
// Change ownership of test nodes to test users
|
||||
$this->node1->uid = $test_user1->uid;
|
||||
node_save($this->node1);
|
||||
$this->node2->uid = $test_user2->uid;
|
||||
node_save($this->node2);
|
||||
|
||||
// Remove all view permissions for this content type
|
||||
$access_permissions = array(
|
||||
'view[1]' => FALSE,
|
||||
'view[2]' => FALSE,
|
||||
'view_own[1]' => FALSE,
|
||||
'view_own[2]' => FALSE,
|
||||
);
|
||||
$this->changeAccessContentType($access_permissions);
|
||||
|
||||
// Allow view own content for test user 1 and 2 roles
|
||||
$this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user1);
|
||||
$this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user2);
|
||||
|
||||
// Logout admin and try to access both nodes anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node1 is not viewable');
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertText(t('Access denied'), 'node2 is not viewable');
|
||||
|
||||
// Login test user 1, view node1, access must be granted
|
||||
$this->drupalLogin($test_user1);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node1 is viewable');
|
||||
|
||||
// View node2, access must be denied
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertText(t('Access denied'), 'node2 is not viewable');
|
||||
|
||||
// Login test user 2, view node1, access must be denied
|
||||
$this->drupalLogin($test_user2);
|
||||
$this->drupalGet('node/'. $this->node1->nid);
|
||||
$this->assertText(t('Access denied'), 'node1 is not viewable');
|
||||
|
||||
// View node2, access must be granted
|
||||
$this->drupalGet('node/'. $this->node2->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node2 is viewable');
|
||||
}
|
||||
}
|
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Automatd SimpleTest Case for using content access module with acl module
|
||||
*/
|
||||
|
||||
require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php');
|
||||
|
||||
class ContentAccessACLTestCase extends ContentAccessTestCase {
|
||||
|
||||
var $node;
|
||||
|
||||
/**
|
||||
* Implementation of get_info() for information
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => t('Content Access Module with ACL Module Tests'),
|
||||
'description' => t('Various tests to check the combination of content access and ACL module.'),
|
||||
'group' => 'Content Access',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup configuration before each test
|
||||
*/
|
||||
function setUp($module = '') {
|
||||
parent::setUp('acl');
|
||||
|
||||
if (!module_exists('acl')) {
|
||||
$this->pass('No ACL module present, skipping test');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create test nodes
|
||||
$this->node = $this->drupalCreateNode(array('type' => $this->content_type->type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Viewing accessibility with permissions for single users
|
||||
*/
|
||||
function testViewAccess() {
|
||||
// Exit test if ACL module could not be enabled
|
||||
if (!module_exists('acl')) {
|
||||
$this->pass('No ACL module present, skipping test');
|
||||
return;
|
||||
}
|
||||
|
||||
// Restrict access to this content type (access is only allowed for the author)
|
||||
// Enable per node access control
|
||||
$access_permissions = array(
|
||||
'view[1]' => FALSE,
|
||||
'view[2]' => FALSE,
|
||||
'per_node' => TRUE,
|
||||
);
|
||||
$this->changeAccessContentType($access_permissions);
|
||||
|
||||
// Allow access for test user
|
||||
$edit = array(
|
||||
'acl[view][add]' => $this->test_user->name,
|
||||
);
|
||||
$this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
|
||||
$this->drupalPost(NULL, array(), t('Submit'));
|
||||
|
||||
// Logout admin, try to access the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
|
||||
// Login test user, view access should be allowed now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid);
|
||||
$this->assertNoText(t('Access denied'), 'node is viewable');
|
||||
|
||||
// Login admin and disable per node access
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessPerNode(FALSE);
|
||||
|
||||
// Logout admin, try to access the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
|
||||
// Login test user, view access should be denied now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid);
|
||||
$this->assertText(t('Access denied'), 'node is not viewable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Editing accessibility with permissions for single users
|
||||
*/
|
||||
function testEditAccess() {
|
||||
// Exit test if ACL module could not be enabled
|
||||
if (!module_exists('acl')) {
|
||||
$this->pass('No ACL module present, skipping test');
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable per node access control
|
||||
$this->changeAccessPerNode();
|
||||
|
||||
// Allow edit access for test user
|
||||
$edit = array(
|
||||
'acl[update][add]' => $this->test_user->name,
|
||||
);
|
||||
$this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
|
||||
$this->drupalPost(NULL, array(), t('Submit'));
|
||||
|
||||
// Logout admin, try to edit the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node is not editable');
|
||||
|
||||
// Login test user, edit access should be allowed now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid .'/edit');
|
||||
$this->assertNoText(t('Access denied'), 'node is editable');
|
||||
|
||||
// Login admin and disable per node access
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessPerNode(FALSE);
|
||||
|
||||
// Logout admin, try to edit the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node is not editable');
|
||||
|
||||
// Login test user, edit access should be denied now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid .'/edit');
|
||||
$this->assertText(t('Access denied'), 'node is not editable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Deleting accessibility with permissions for single users
|
||||
*/
|
||||
function testDeleteAccess() {
|
||||
// Exit test if ACL module could not be enabled
|
||||
if (!module_exists('acl')) {
|
||||
$this->pass('No ACL module present, skipping test');
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable per node access control
|
||||
$this->changeAccessPerNode();
|
||||
|
||||
// Allow delete access for test user
|
||||
$edit = array(
|
||||
'acl[delete][add]' => $this->test_user->name,
|
||||
);
|
||||
$this->drupalPost('node/'. $this->node->nid .'/access', $edit, t('Add User'));
|
||||
$this->drupalPost(NULL, array(), t('Submit'));
|
||||
|
||||
// Logout admin, try to delete the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node is not deletable');
|
||||
|
||||
// Login test user, delete access should be allowed now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid .'/delete');
|
||||
$this->assertNoText(t('Access denied'), 'node is deletable');
|
||||
|
||||
// Login admin and disable per node access
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->changeAccessPerNode(FALSE);
|
||||
|
||||
// Logout admin, try to delete the node anonymously
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/'. $this->node->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node is not deletable');
|
||||
|
||||
// Login test user, delete access should be denied now
|
||||
$this->drupalLogin($this->test_user);
|
||||
$this->drupalGet('node/'. $this->node->nid .'/delete');
|
||||
$this->assertText(t('Access denied'), 'node is not deletable');
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helper class with auxiliary functions for content access module tests
|
||||
*/
|
||||
|
||||
class ContentAccessTestCase extends DrupalWebTestCase {
|
||||
|
||||
var $test_user;
|
||||
var $rid;
|
||||
var $admin_user;
|
||||
var $content_type;
|
||||
var $url_content_type_name;
|
||||
var $node1;
|
||||
var $node2;
|
||||
|
||||
/**
|
||||
* Preparation work that is done before each test.
|
||||
* Test users, content types, nodes etc. are created.
|
||||
*/
|
||||
function setUp($module = '') {
|
||||
if (empty($module)) {
|
||||
// Enable content access module
|
||||
parent::setUp('content_access');
|
||||
}
|
||||
else {
|
||||
// Enable content access module plus another module
|
||||
parent::setUp('content_access', $module);
|
||||
// Stop setup when module could not be enabled
|
||||
if (!module_exists($module)) {
|
||||
$this->pass('No ' . $module . ' module present, skipping test');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create test user with seperate role
|
||||
$this->test_user = $this->drupalCreateUser();
|
||||
|
||||
// Get the value of the new role
|
||||
// Needed in D7 because it's by default create two roles for new users
|
||||
// one role is Authenticated and the second is new default one
|
||||
// @see drupalCreateUser()
|
||||
foreach ($this->test_user->roles as $rid => $role) {
|
||||
if (!in_array($rid, array(DRUPAL_AUTHENTICATED_RID))) {
|
||||
$this->rid = $rid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Create admin user
|
||||
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'administer nodes', 'access administration pages'));
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Rebuild content access permissions
|
||||
node_access_rebuild();
|
||||
|
||||
// Create test content type
|
||||
$this->content_type = $this->drupalCreateContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access permissions for a content type
|
||||
*/
|
||||
function changeAccessContentType($access_settings) {
|
||||
$this->drupalPost('admin/structure/types/manage/'. $this->content_type->type .'/access', $access_settings, t('Submit'));
|
||||
$this->assertText(t('Your changes have been saved.'), 'access rules of content type were updated successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access permissions for a content type by a given keyword (view, update or delete)
|
||||
* for the role of the user
|
||||
*/
|
||||
function changeAccessContentTypeKeyword($keyword, $access = TRUE, $user = NULL) {
|
||||
if ($user === NULL) {
|
||||
$user = $this->test_user;
|
||||
$roles[$this->rid] = $user->roles[$this->rid];
|
||||
} else {
|
||||
foreach ($user->roles as $rid => $role) {
|
||||
if (!in_array($rid, array(DRUPAL_AUTHENTICATED_RID))) {
|
||||
$roles[$rid] = $user->roles[$rid];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$access_settings = array(
|
||||
$keyword .'['. key($roles) .']' => $access,
|
||||
);
|
||||
|
||||
$this->changeAccessContentType($access_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the per node access setting for a content type
|
||||
*/
|
||||
function changeAccessPerNode($access = TRUE) {
|
||||
$access_permissions = array(
|
||||
'per_node' => $access,
|
||||
);
|
||||
$this->changeAccessContentType($access_permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access permissions for a node by a given keyword (view, update or delete)
|
||||
*/
|
||||
function changeAccessNodeKeyword($node, $keyword, $access = TRUE) {
|
||||
$user = $this->test_user;
|
||||
$roles[$this->rid] = $user->roles[$this->rid];
|
||||
|
||||
$access_settings = array(
|
||||
$keyword .'['. key($roles) .']' => $access,
|
||||
);
|
||||
|
||||
$this->changeAccessNode($node, $access_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change access permission for a node
|
||||
*/
|
||||
function changeAccessNode($node, $access_settings) {
|
||||
$this->drupalPost('node/'. $node->nid .'/access', $access_settings, t('Submit'));
|
||||
$this->assertText(t('Your changes have been saved.'), 'access rules of node were updated successfully');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user