View source
<?php
require_once drupal_get_path('module', 'content_access') . '/tests/content_access_test_help.php';
class ContentAccessACLTestCase extends ContentAccessTestCase {
var $node;
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',
);
}
function setUp() {
parent::setUp();
$this->node = $this
->createNode();
}
function testViewAccess() {
if (!$this
->aclModuleEnable()) {
$this
->pass('No ACL module present, skipping test');
return;
}
$access_permissions = array(
'view[author]' => TRUE,
'view[1]' => FALSE,
'view[2]' => FALSE,
'per_node' => TRUE,
);
$this
->changeAccessContentType($access_permissions);
$edit = array(
'acl[view][add]' => $this->test_user->name,
);
$this
->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'Add User');
$this
->postToCurrentPage(array(), 'Submit');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertNoText(t('Access denied'), 'node is viewable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
}
function testEditAccess() {
if (!$this
->aclModuleEnable()) {
$this
->pass('No ACL module present, skipping test');
return;
}
$this
->changeAccessPerNode();
$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');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertNoText(t('Access denied'), 'node is editable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node is not editable');
}
function testDeleteAccess() {
if (!$this
->aclModuleEnable()) {
$this
->pass('No ACL module present, skipping test');
return;
}
$this
->changeAccessPerNode();
$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');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertNoText(t('Access denied'), 'node is deletable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode(FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node is not deletable');
}
function aclModuleEnable() {
if (module_exists('acl')) {
return TRUE;
}
module_enable(array(
'acl',
));
if (module_exists('acl')) {
module_disable(array(
'acl',
));
$this
->drupalModuleEnable('acl');
return TRUE;
}
return FALSE;
}
}