function ForumAccessBaseTestCase::setUp2 in Forum Access 7
3 calls to ForumAccessBaseTestCase::setUp2()
File
- tests/
forum_access_test_base.php, line 80 - Base class with auxiliary functions for forum access module tests.
Class
- ForumAccessBaseTestCase
- Base test class for the Forum Access module.
Code
function setUp2() {
$this->user1 = user_load(1);
// Update uid 1's name and password so we know it.
$password = user_password();
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$account = array(
'name' => 'user1',
'pass' => user_hash_password(trim($password)),
);
// We cannot use user_save() here or the password would be hashed again.
db_update('users')
->fields($account)
->condition('uid', 1)
->execute();
// Reload and log in uid 1.
$this->user1 = user_load(1, TRUE);
$this->user1->pass_raw = $password;
// Rebuild content access permissions
$this
->drupalLogin($this->user1);
$this
->drupalPost('admin/reports/status/rebuild', array(), t('Rebuild permissions'));
if (module_exists('devel_node_access')) {
// Enable Devel Node Access.
$this
->drupalGet('admin/config/development/devel');
$this
->assertResponse(200);
$this
->drupalPost('admin/config/development/devel', array(
'devel_node_access_debug_mode' => '1',
), t('Save configuration'));
$this
->assertResponse(200, 'Devel Node Access configuration saved.');
// Enable the second DNA block, too.
$this
->drupalPost('admin/structure/block/list', array(
'blocks[devel_node_access_dna_user][region]' => 'footer',
), t('Save blocks'));
}
if (module_exists('devel')) {
$this
->drupalPost('admin/config/development/devel', array(
'devel_error_handlers[]' => array(
1,
2,
4,
),
), t('Save configuration'));
$this
->assertResponse(200, 'Devel configuration saved.');
$this
->drupalPost('admin/people/permissions/list', array(
'1[access devel information]' => 'access devel information',
'2[access devel information]' => 'access devel information',
), t('Save permissions'));
$this
->assertResponse(200, 'Devel permissions saved.');
}
/*
The base class creates the following users:
$this->user1 = user 1
$this->admin_user = array('administer blocks', 'administer forums', 'administer menu', 'administer taxonomy', 'create forum content')); // 'access administration pages')
$this->edit_any_topics_user = array('create forum content', 'edit any forum content', 'delete any forum content', 'access administration pages')
$this->edit_own_topics_user = array('create forum content', 'edit own forum content', 'delete own forum content')
$this->web_user = array()
Remove these users and roles and create the ones we need.
*/
user_role_delete((int) reset($this->admin_user->roles));
user_role_delete((int) reset($this->edit_any_topics_user->roles));
user_role_delete((int) reset($this->edit_own_topics_user->roles));
user_delete($this->admin_user->uid);
user_delete($this->edit_any_topics_user->uid);
user_delete($this->edit_own_topics_user->uid);
user_delete($this->web_user->uid);
unset($this->web_user);
// Get rids and uids up to 10/9.
for ($i = 0; $i < 3; ++$i) {
$dummy_rid = (int) $this
->drupalCreateRole(array(), 'dummy');
$dummy_user = $this
->drupalCreateNamedUser('Dummy', array(
$dummy_rid,
));
user_role_delete($dummy_rid);
user_delete($dummy_user->uid);
}
// Create our roles.
$this->admin_rid = 3;
$this->webmaster_rid = (int) $this
->drupalCreateRole(array(
'administer blocks',
'administer forums',
'administer nodes',
'administer comments',
'administer menu',
'administer taxonomy',
'create forum content',
'access content overview',
'access administration pages',
'view revisions',
'revert revisions',
'delete revisions',
), '11 webmaster');
$this->forum_admin_rid = (int) $this
->drupalCreateRole(array(
'administer forums',
'create forum content',
'edit any forum content',
'delete any forum content',
), '12 forum admin');
$this->edndel_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit any forum content',
'delete any forum content',
'view own unpublished content',
), '13 edndel any content');
$this->edndel_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit own forum content',
'delete own forum content',
), '14 edndel own content');
$this->edit_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit any forum content',
'view own unpublished content',
), '15 edit any content');
$this->edit_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit own forum content',
'edit own comments',
), '16 edit own content');
$this->delete_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'delete any forum content',
'view own unpublished content',
), '17 delete any content');
$this->delete_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'delete own forum content',
'edit own comments',
), '18 delete own content');
// EOC should not make any difference!
$this->create_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
), '19 create content');
$this->anon_rid = DRUPAL_ANONYMOUS_RID;
$this->auth_rid = DRUPAL_AUTHENTICATED_RID;
// Create our users.
$this->admin_user = $this
->drupalCreateNamedUser('10_Administrator', array(
$this->admin_rid,
));
$this->webmaster_user = $this
->drupalCreateNamedUser('11_Webmaster', array(
$this->webmaster_rid,
));
$this->forum_admin_user = $this
->drupalCreateNamedUser('12_Forum_admin', array(
$this->forum_admin_rid,
));
$this->edndel_any_content_user = $this
->drupalCreateNamedUser('13_EdNDel_any_content', array(
$this->edndel_any_content_rid,
));
$this->edndel_own_content_user = $this
->drupalCreateNamedUser('14_EdNDel_own_content', array(
$this->edndel_own_content_rid,
));
$this->edit_any_content_user = $this
->drupalCreateNamedUser('15_Edit_any_content', array(
$this->edit_any_content_rid,
));
$this->edit_own_content_user = $this
->drupalCreateNamedUser('16_Edit_own_content', array(
$this->edit_own_content_rid,
));
$this->delete_any_content_user = $this
->drupalCreateNamedUser('17_Delete_any_content', array(
$this->delete_any_content_rid,
));
$this->delete_own_content_user = $this
->drupalCreateNamedUser('18_Delete_own_content', array(
$this->delete_own_content_rid,
));
$this->create_content_user = $this
->drupalCreateNamedUser('19_Create_content', array(
$this->create_content_rid,
));
$this->auth_user = $this
->drupalCreateNamedUser('20_Auth_only', array());
$this->moderator = $this
->drupalCreateNamedUser('21_Moderator', array(
$this->create_content_rid,
));
$anon = drupal_anonymous_user();
$anon->name = check_plain(format_username($anon));
$this->accounts = array(
$this->user1,
$this->admin_user,
$this->webmaster_user,
$this->forum_admin_user,
$this->edndel_any_content_user,
$this->edndel_own_content_user,
$this->edit_any_content_user,
$this->edit_own_content_user,
$this->delete_any_content_user,
$this->delete_own_content_user,
$this->create_content_user,
$this->auth_user,
$this->moderator,
);
$this->rids = array(
$this->anon_rid,
$this->auth_rid,
$this->admin_rid,
$this->webmaster_rid,
$this->forum_admin_rid,
$this->edndel_any_content_rid,
$this->edndel_own_content_rid,
$this->edit_any_content_rid,
$this->edit_own_content_rid,
$this->delete_any_content_rid,
$this->delete_own_content_rid,
$this->create_content_rid,
);
// Show settings for reference.
$this
->drupalGet('admin/people/permissions/list');
$this
->assertResponse(200, '^^^ Permissions');
$this
->drupalGet('admin/people', array(
'query' => array(
'sort' => 'asc',
'order' => drupal_encode_path(t('Username')),
),
));
$this
->assertResponse(200, '^^^ Users');
}