View source
<?php
require_once drupal_get_path('module', 'content_access') . '/tests/content_access_test_help.php';
class ContentAccessModuleTestCase extends ContentAccessTestCase {
var $node1;
var $node2;
function get_info() {
return array(
'name' => t('Content Access Module Tests'),
'desc' => t('Various tests to check permission settings on nodes.'),
'group' => 'Content Access',
);
}
function setUp() {
parent::setUp();
$this->node1 = $this
->createNode();
$this->node2 = $this
->createNode();
}
function testViewAccess() {
$access_permissions = array(
'view[author]' => TRUE,
'view[1]' => FALSE,
'view[2]' => FALSE,
);
$this
->changeAccessContentType($access_permissions);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('view');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertNoText(t('Access denied'), 'node is viewable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode();
$this
->changeAccessNodeKeyword($this->node2, 'view', FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet(url('node/' . $this->node2->nid));
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertNoText(t('Access denied'), 'node1 is viewable');
$this
->drupalGet(url('node/' . $this->node2->nid));
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('view', FALSE);
$this
->changeAccessNodeKeyword($this->node2, 'view');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet(url('node/' . $this->node2->nid));
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid));
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet(url('node/' . $this->node2->nid));
$this
->assertNoText(t('Access denied'), 'node2 is viewable');
}
function testEditAccess() {
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'edit access denied for anonymous');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'edit access denied for test user');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('update');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'edit access denied for anonymous');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertNoText(t('Access denied'), 'node1 is editable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessPerNode();
$this
->changeAccessNodeKeyword($this->node2, 'update', FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertNoText(t('Access denied'), 'node1 is editable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('update', FALSE);
$this
->changeAccessNodeKeyword($this->node2, 'update');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/edit'));
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/edit'));
$this
->assertNoText(t('Access denied'), 'node2 is editable');
}
function testDeleteAccess() {
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'delete access denied for anonymous');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'delete access denied for test user');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('delete');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'delete access denied for anonymous');
$this
->drupalLoginUser($this->test_user);
$this
->drupalPostRequest('node/' . $this->node1->nid . '/delete', array(), 'Delete');
$this
->assertWantedRaw(t('%node has been deleted', array(
'%node' => $this->node1->title,
)), 'Test node was deleted successfully by test user');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this->node1 = $this
->createNode();
$this
->changeAccessPerNode();
$this
->changeAccessNodeKeyword($this->node2, 'delete', FALSE);
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertNoText(t('Access denied'), 'node1 is deletable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalGet(url('logout'));
$this
->drupalLoginUser($this->admin_user);
$this
->changeAccessContentTypeKeyword('delete', FALSE);
$this
->changeAccessNodeKeyword($this->node2, 'delete');
$this
->drupalGet(url('logout'));
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalLoginUser($this->test_user);
$this
->drupalGet(url('node/' . $this->node1->nid . '/delete'));
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet(url('node/' . $this->node2->nid . '/delete'));
$this
->assertNoText(t('Access denied'), 'node2 is deletable');
}
}