class ContentAccessACLTestCase in Content Access 5
Same name and namespace in other branches
- 6 tests/content_access_acl.test \ContentAccessACLTestCase
- 7 tests/content_access_acl.test \ContentAccessACLTestCase
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ContentAccessTestCase
- class \ContentAccessACLTestCase
- class \ContentAccessTestCase
Expanded class hierarchy of ContentAccessACLTestCase
File
- tests/
content_access_acl.test, line 10
View source
class ContentAccessACLTestCase extends ContentAccessTestCase {
var $node;
/**
* Implementation of get_info() for information
*/
function get_info() {
return array(
'name' => t('Content Access Module with ACL Module Tests'),
'desc' => t('Various tests to check the combination of content access and ACL module.'),
'group' => 'Content Access',
);
}
/**
* Setup configuration before each test
*/
function setUp() {
parent::setUp();
// Create test nodes
$this->node = $this
->createNode();
}
/**
* Test Viewing accessibility with permissions for single users
*/
function testViewAccess() {
// Enable ACL module
// Exit test if module could not be enabled
if (!$this
->aclModuleEnable()) {
$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[author]' => TRUE,
'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
->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'Add User');
$this
->postToCurrentPage(array(), 'Submit');
// Logout admin, try to access the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
// Login test user, view access should be allowed now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertNoText(t('Access denied'), 'node is viewable');
// Login admin and disable per node access
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
// Logout admin, try to access the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
// Login test user, view access should be denied now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
}
/**
* Test Editing accessibility with permissions for single users
*/
function testEditAccess() {
// Enable ACL module
// Exit test if module could not be enabled
if (!$this
->aclModuleEnable()) {
$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
->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'acl[update][add_button]');
$this
->postToCurrentPage(array(), 'Submit');
// Logout admin, try to edit the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
// Login test user, edit access should be allowed now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertNoText(t('Access denied'), 'node is editable');
// Login admin and disable per node access
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
// Logout admin, try to edit the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
// Login test user, edit access should be denied now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
}
/**
* Test Deleting accessibility with permissions for single users
*/
function testDeleteAccess() {
// Enable ACL module
// Exit test if module could not be enabled
if (!$this
->aclModuleEnable()) {
$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
->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'acl[delete][add_button]');
$this
->postToCurrentPage(array(), 'Submit');
// Logout admin, try to delete the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
// Login test user, delete access should be allowed now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertNoText(t('Access denied'), 'node is deletable');
// Login admin and disable per node access
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
// Logout admin, try to delete the node anonymously
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
// Login test user, delete access should be denied now
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
}
/**
* Enables the ACL module and returns TRUE on success
*/
function aclModuleEnable() {
if (module_exists('acl')) {
return TRUE;
}
module_enable(array(
'acl',
));
if (module_exists('acl')) {
module_disable(array(
'acl',
));
// Make sure we use drupalModuleEnable(), so the module is disabled again afterwards.
$this
->drupalModuleEnable('acl');
return TRUE;
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentAccessACLTestCase:: |
property | |||
ContentAccessACLTestCase:: |
function | Enables the ACL module and returns TRUE on success | ||
ContentAccessACLTestCase:: |
function | Implementation of get_info() for information | ||
ContentAccessACLTestCase:: |
function |
Setup configuration before each test Overrides ContentAccessTestCase:: |
||
ContentAccessACLTestCase:: |
function | Test Deleting accessibility with permissions for single users | ||
ContentAccessACLTestCase:: |
function | Test Editing accessibility with permissions for single users | ||
ContentAccessACLTestCase:: |
function | Test Viewing accessibility with permissions for single users | ||
ContentAccessTestCase:: |
property | |||
ContentAccessTestCase:: |
property | |||
ContentAccessTestCase:: |
property | 1 | ||
ContentAccessTestCase:: |
property | 1 | ||
ContentAccessTestCase:: |
property | |||
ContentAccessTestCase:: |
property | |||
ContentAccessTestCase:: |
function | Change access permissions for a content type | ||
ContentAccessTestCase:: |
function | Change access permissions for a content type by a given keyword (view, update or delete) for the role of the user | ||
ContentAccessTestCase:: |
function | Change access permission for a node | ||
ContentAccessTestCase:: |
function | Change access permissions for a node by a given keyword (view, update or delete) | ||
ContentAccessTestCase:: |
function | Change the per node access setting for a content type | ||
ContentAccessTestCase:: |
function | Creates a node for testing purposes | ||
ContentAccessTestCase:: |
function | Stores the current page in the files directory, so it can be viewed by the developer. Useful for debugging code. | ||
ContentAccessTestCase:: |
function | Replacement for drupalPostRequest() if we don't want to reload a path | ||
ContentAccessTestCase:: |
function |
Clear up work that is done after each test.
Users get deleted automatically, so we just have to delete the content type.
(nodes get deleted automatically, too) Overrides DrupalTestCase:: |
||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter |