class ContentAccessTestCase in Content Access 5
Same name and namespace in other branches
- 6 tests/content_access_test_help.php \ContentAccessTestCase
- 7 tests/content_access_test_help.php \ContentAccessTestCase
@file Helper class with auxiliary functions for content access module tests
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ContentAccessTestCase
Expanded class hierarchy of ContentAccessTestCase
File
- tests/
content_access_test_help.php, line 8 - Helper class with auxiliary functions for content access module tests
View source
class ContentAccessTestCase extends DrupalTestCase {
var $test_user;
var $admin_user;
var $content_type_name;
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() {
parent::setUp();
// Create test user with seperate role
$this->test_user = $this
->drupalCreateUserRolePerm();
// Create admin user
$this->admin_user = $this
->drupalCreateUserRolePerm(array(
'administer content types',
'grant content access',
'grant own content access',
'administer nodes',
));
$this
->drupalLoginUser($this->admin_user);
// Create test content type
$this->content_type_name = strtolower($this
->randomName(5));
$edit = array(
'name' => $this->content_type_name,
'type' => $this->content_type_name,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, 'op');
$this
->assertWantedRaw(t('The content type %type has been added.', array(
'%type' => $this->content_type_name,
)), 'Test content type was added successfully');
$this->url_content_type_name = str_replace('_', '-', $this->content_type_name);
}
/**
* 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)
*/
function tearDown() {
// Login admin and delete test content type
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->drupalPostRequest('admin/content/types/' . $this->url_content_type_name . '/delete', array(), 'op');
parent::tearDown();
}
/**
* Creates a node for testing purposes
* @return the node object
*/
function createNode() {
$title = $this
->randomName(10);
$edit = array(
'title' => $title,
'body' => $this
->randomName(20),
);
$this
->drupalPostRequest('node/add/' . $this->url_content_type_name, $edit, 'Submit');
$this
->assertWantedRaw(t('Your %content has been created.', array(
'%content' => $this->content_type_name,
)), 'Test node was added successfully');
return node_load(array(
'title' => $title,
'type' => $this->content_type_name,
));
}
/**
* Change access permissions for a content type
*/
function changeAccessContentType($access_settings) {
$this
->drupalPostRequest('admin/content/types/' . $this->url_content_type_name . '/access', $access_settings, '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 = $this->test_user;
$roles = $user->roles;
end($roles);
$access_settings = array(
$keyword . '[' . key($roles) . ']' => $access,
);
$this
->changeAccessContentType($access_settings);
}
/**
* Change access permission for a node
*/
function changeAccessNode($node, $access_settings) {
$this
->drupalPostRequest('node/' . $node->nid . '/access', $access_settings, 'Submit');
$this
->assertText(t('Your changes have been saved.'), 'access rules of node were updated successfully');
}
/**
* 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 = $user->roles;
end($roles);
$access_settings = array(
$keyword . '[' . key($roles) . ']' => $access,
);
$this
->changeAccessNode($node, $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);
}
/**
* Replacement for drupalPostRequest() if we don't want to reload a path
*/
function postToCurrentPage($edit = array(), $submit) {
foreach ($edit as $field_name => $field_value) {
$ret = $this->_browser
->setFieldByName($field_name, $field_value) || $this->_browser
->setFieldById("edit-{$field_name}", $field_value);
$this
->assertTrue($ret, " [browser] Setting {$field_name}=\"{$field_value}\"");
}
$ret = $this->_browser
->clickSubmit(t($submit)) || $this->_browser
->clickSubmitById($submit) || $this->_browser
->clickSubmitByName($submit) || $this->_browser
->clickImageByName($submit);
$this
->assertTrue($ret, ' [browser] POST by click on ' . t($submit));
$this->_content = $this->_browser
->getContent();
}
/**
* Stores the current page in the files directory, so it can be viewed by the developer.
* Useful for debugging code.
*/
function debugCurrentPage() {
static $count = 0;
$count++;
$path = 'tests';
if (!file_check_directory($path, FILE_CREATE_DIRECTORY)) {
return FALSE;
//unable to create directory
}
$filepath = file_create_filename("page-{$count}.htm", $path);
file_put_contents($filepath, $this
->drupalGetContent());
echo '<a href="' . $filepath . '">created debug file ' . $count . '</a><br/>';
//echo l("created debug file $count", $filepath);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | Preparation work that is done before each test. Test users, content types, nodes etc. are created. | 2 | |
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 |