View source
<?php
require_once drupal_get_path('module', 'content_access') . '/tests/content_access_test_help.php';
class ContentAccessACLTestCase extends ContentAccessTestCase {
var $node;
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',
'dependencies' => array(
'acl',
),
);
}
function setUp($addedmodules = array()) {
$modules = array(
'acl',
);
$addedmodules = array_merge($modules, $addedmodules);
parent::setUp($addedmodules);
if (!module_exists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
$this->node = $this
->drupalCreateNode(array(
'type' => $this->content_type->type,
));
}
function testViewAccess() {
if (!module_exists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
$access_permissions = array(
'view[1]' => FALSE,
'view[2]' => FALSE,
'per_node' => TRUE,
);
$this
->changeAccessContentType($access_permissions);
$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'));
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid);
$this
->assertNoText(t('Access denied'), 'node is viewable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
}
function testEditAccess() {
if (!module_exists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
$this
->changeAccessPerNode();
$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'));
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid . '/edit');
$this
->assertText(t('Access denied'), 'node is not editable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid . '/edit');
$this
->assertNoText(t('Access denied'), 'node is editable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid . '/edit');
$this
->assertText(t('Access denied'), 'node is not editable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid . '/edit');
$this
->assertText(t('Access denied'), 'node is not editable');
}
function testDeleteAccess() {
if (!module_exists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
$this
->changeAccessPerNode();
$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'));
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid . '/delete');
$this
->assertText(t('Access denied'), 'node is not deletable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid . '/delete');
$this
->assertNoText(t('Access denied'), 'node is deletable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node->nid . '/delete');
$this
->assertText(t('Access denied'), 'node is not deletable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node->nid . '/delete');
$this
->assertText(t('Access denied'), 'node is not deletable');
}
}