protected function ForumAccessTestCase::testForumAccessRun in Forum Access 6
The main function which is used to start testing a specific forum configuration.
You can add new users with specific permissions. You can also remove users with permissions who are not important to you, please do NOT remove the admin_user!
7 calls to ForumAccessTestCase::testForumAccessRun()
- ForumAccessTestCase1::testForumAccess in ./
forum_access.test - Implements the Forum Access testing.
- ForumAccessTestCase2::testForumAccess in ./
forum_access.test - Implements the Forum Access testing.
- ForumAccessTestCase3::testForumAccess in ./
forum_access.test - Implements the Forum Access testing.
- ForumAccessTestCase4::testForumAccess in ./
forum_access.test - Implements the Forum Access testing.
- ForumAccessTestCase5::testForumAccess in ./
forum_access.test - Implements the Forum Access testing.
File
- ./
forum_access.test, line 99 - Test file for forum_access.module.
Class
- ForumAccessTestCase
- This is the base class for forum access testing.
Code
protected function testForumAccessRun($grants = array()) {
if (is_array($grants) && isset($grants['anonymous_view']) && isset($grants['anonymous_create']) && isset($grants['anonymous_update']) && isset($grants['anonymous_delete']) && isset($grants['authenticated_view']) && isset($grants['authenticated_create']) && isset($grants['authenticated_update']) && isset($grants['authenticated_delete'])) {
// permissions for default roles
$this
->testForumAccessSetPermissionsAnonymousRole();
$this
->testForumAccessSetPermissionsAuthenticatedRole();
$this
->testForumAccessCreateUser('admin_user', array(
'administer site configuration',
'access administration pages',
'administer nodes',
'administer blocks',
'administer comments',
'administer forums',
'create forum topics',
'post comments',
'post comments without approval',
'access content',
'access comments',
));
// view
$this
->testForumAccessCreateUser('normal_user_1');
// no permissions
//$this->testForumAccessCreateUser('normal_user_2', array('access content'));
//$this->testForumAccessCreateUser('normal_user_3', array('access comments'));
$this
->testForumAccessCreateUser('normal_user_4', array(
'access content',
'access comments',
));
// create
$this
->testForumAccessCreateUser('normal_user_5', array(
'access content',
'access comments',
'post comments',
'post comments without approval',
));
$this
->testForumAccessCreateUser('normal_user_6', array(
'access content',
'access comments',
'post comments',
'post comments without approval',
'create forum topics',
));
// edit & delete
$this
->testForumAccessCreateUser('normal_user_7', array(
'access content',
'access comments',
'post comments',
'post comments without approval',
'create forum topics',
'edit own forum topics',
'delete own forum topics',
));
$this
->testForumAccessCreateUser('normal_user_8', array(
'access content',
'access comments',
'post comments',
'post comments without approval',
'create forum topics',
'edit any forum topic',
'delete any forum topic',
));
$this
->testForumAccessCreateUser('normal_user_9', array(
'access content',
'access comments',
'post comments',
'post comments without approval',
'create forum topics',
'delete own forum topics',
'delete any forum topic',
));
// You can create extra users here.
//$this->testForumAccessCreateUser('unique_name', array('permissions'));
$this
->testForumAccessLogin('admin_user');
// Disable clean URLs (on qa.d.o they are disabled!).
//$this->drupalPost('admin/settings/clean-urls', array('clean_url' => 0), t('Save configuration'));
if ($this->testForumAccessUseDNA) {
// Enable Devel Node Access verbose mode.
$this
->drupalPost('admin/settings/devel', array(
'devel_node_access_debug_mode' => 1,
), t('Save configuration'));
$this
->drupalPost('admin/build/block/list/garland', array(
'devel_node_access_1[region]' => 'footer',
), t('Save blocks'));
}
// Rebuild permissions.
$this
->drupalPost('admin/content/node-settings/rebuild', array(), t('Rebuild permissions'));
// Delete all cached permissions.
user_access(NULL, NULL, TRUE);
// Create the forum with the appropriate grants.
$this->testForumAccessCurrentForumId = $this
->testForumAccessCreateForum($grants);
if ($this->testForumAccessCurrentForumId == 0) {
$this
->pass(t('There was a problem creating a forum for this test.'), 'Debug');
return;
}
// Save the grants.
$this->testForumAccessGrants = $grants;
// for every user except the admin_user
foreach ($this->testForumAccessUsers as $forumAccessUser) {
// Do the loop 3 times, once as an anonymous user and once as an
// authenticated user and once as moderator, all with the same permissions.
for ($i = 0; $i < 3; $i++) {
// admin makes default content to start.
if ($this->testForumAccessCurrentUsername != 'admin_user') {
$this
->testForumAccessLogin('admin_user');
}
$admin_topic_id = $this
->testForumAccessCreateTopic();
$admin_comment_id = $this
->testForumAccessCreateComment($admin_topic_id);
$this
->testForumAccessLogout();
switch ($i) {
case 0:
// anonymous user with the same permissions
$this
->testForumAccessSetPermissionsAnonymousRole($this->testForumAccessPermissions[$this->testForumAccessUidToName[$forumAccessUser->uid]]);
break;
case 1:
// authenticated user
$this
->testForumAccessLogin($this->testForumAccessUidToName[$forumAccessUser->uid]);
break;
case 2:
// upgrade authenticated user to moderator
$this
->testForumAccessLogin('admin_user');
$this
->testForumAccessAddModerator($forumAccessUser->uid);
$this
->testForumAccessLogin($this->testForumAccessUidToName[$forumAccessUser->uid]);
break;
}
// view
$this
->testForumAccessViewForum();
$this
->testForumAccessViewTopic($admin_topic_id);
$this
->testForumAccessViewComment($admin_topic_id, $admin_comment_id);
// create
$user_topic_id = $this
->testForumAccessCreateTopic();
if (intval($user_topic_id) == 0) {
$user_topic_id = $admin_topic_id;
}
$user_comment_id = $this
->testForumAccessCreateComment($user_topic_id);
if (intval($user_comment_id) == 0) {
$user_comment_id = $admin_comment_id;
}
$user_reply_id = 0;
if ($this
->testForumAccessCreateReply($user_topic_id, $user_comment_id)) {
$user_reply_id = $user_comment_id + 1;
}
// edit
if ($user_topic_id != $admin_topic_id) {
$this
->testForumAccessUpdateTopic($user_topic_id);
}
if ($user_comment_id != $admin_comment_id) {
$this
->testForumAccessUpdateComment($user_topic_id, $user_comment_id);
}
if ($user_reply_id) {
$this
->testForumAccessUpdateComment($user_topic_id, $user_reply_id);
}
$this
->testForumAccessUpdateTopic($admin_topic_id);
$this
->testForumAccessUpdateComment($admin_topic_id, $admin_comment_id);
// delete
if ($user_comment_id != $admin_comment_id) {
$this
->testForumAccessDeleteComment($user_topic_id, $user_comment_id);
}
if ($user_topic_id != $admin_topic_id) {
$this
->testForumAccessDeleteTopic($user_topic_id);
}
$this
->testForumAccessDeleteComment($admin_topic_id, $admin_comment_id);
$this
->testForumAccessDeleteTopic($admin_topic_id);
}
}
}
}