View source
<?php
require_once drupal_get_path('module', 'content_access') . '/tests/content_access_test_help.php';
class ContentAccessModuleTestCase extends ContentAccessTestCase {
function getInfo() {
return array(
'name' => t('Content Access Module Tests'),
'description' => t('Various tests to check permission settings on nodes.'),
'group' => t('Content Access'),
);
}
function setUp() {
parent::setUp();
$this->node1 = $this
->drupalCreateNode(array(
'type' => $this->content_type_name,
));
$this->node2 = $this
->drupalCreateNode(array(
'type' => $this->content_type_name,
));
}
function testViewAccess() {
$access_permissions = array(
'view[1]' => FALSE,
'view[2]' => FALSE,
);
$this
->changeAccessContentType($access_permissions);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessContentTypeKeyword('view');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertNoText(t('Access denied'), 'node is viewable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode();
$this
->changeAccessNodeKeyword($this->node2, 'view', FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertNoText(t('Access denied'), 'node1 is viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessContentTypeKeyword('view', FALSE);
$this
->changeAccessNodeKeyword($this->node2, 'view');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertNoText(t('Access denied'), 'node2 is viewable');
}
function testEditAccess() {
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'edit access denied for anonymous');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'edit access denied for test user');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessContentTypeKeyword('update');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'edit access denied for anonymous');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertNoText(t('Access denied'), 'node1 is editable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode();
$this
->changeAccessContentTypeKeyword('update', FALSE);
$this
->changeAccessNodeKeyword($this->node1, 'update');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet('node/' . $this->node2->nid . '/edit');
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertNoText(t('Access denied'), 'node1 is editable');
$this
->drupalGet('node/' . $this->node2->nid . '/edit');
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessNodeKeyword($this->node2, 'update');
$this
->changeAccessNodeKeyword($this->node1, 'update', FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet('node/' . $this->node2->nid . '/edit');
$this
->assertText(t('Access denied'), 'node2 is not editable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/edit');
$this
->assertText(t('Access denied'), 'node1 is not editable');
$this
->drupalGet('node/' . $this->node2->nid . '/edit');
$this
->assertNoText(t('Access denied'), 'node2 is editable');
}
function testDeleteAccess() {
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'delete access denied for anonymous');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'delete access denied for test user');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessContentTypeKeyword('delete');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'delete access denied for anonymous');
$this
->drupalLogin($this->test_user);
$this
->drupalPost('node/' . $this->node1->nid . '/delete', array(), 'Delete');
$this
->assertRaw(t('%node has been deleted', array(
'%node' => $this->node1->title,
)), 'Test node was deleted successfully by test user');
$this
->drupalLogin($this->admin_user);
$this->node1 = $this
->drupalCreateNode(array(
'type' => $this->content_type_name,
));
$this
->changeAccessPerNode();
$this
->changeAccessContentTypeKeyword('delete', FALSE);
$this
->changeAccessNodeKeyword($this->node1, 'delete');
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet('node/' . $this->node2->nid . '/delete');
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertNoText(t('Access denied'), 'node1 is deletable');
$this
->drupalGet('node/' . $this->node2->nid . '/delete');
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalLogin($this->admin_user);
$this
->changeAccessNodeKeyword($this->node2, 'delete');
$this
->changeAccessNodeKeyword($this->node1, 'delete', FALSE);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet('node/' . $this->node2->nid . '/delete');
$this
->assertText(t('Access denied'), 'node2 is not deletable');
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid . '/delete');
$this
->assertText(t('Access denied'), 'node1 is not deletable');
$this
->drupalGet('node/' . $this->node2->nid . '/delete');
$this
->assertNoText(t('Access denied'), 'node2 is deletable');
}
function testOwnViewAccess() {
$test_user1 = $this->test_user;
$test_user2 = $this
->drupalCreateUser();
$this->node1->uid = $test_user1->uid;
node_save($this->node1);
$this->node2->uid = $test_user2->uid;
node_save($this->node2);
$access_permissions = array(
'view[1]' => FALSE,
'view[2]' => FALSE,
'view_own[1]' => FALSE,
'view_own[2]' => FALSE,
);
$this
->changeAccessContentType($access_permissions);
$this
->changeAccessContentTypeKeyword('view_own', TRUE, $test_user1);
$this
->changeAccessContentTypeKeyword('view_own', TRUE, $test_user2);
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLogin($test_user1);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertNoText(t('Access denied'), 'node1 is viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
$this
->drupalLogin($test_user2);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertNoText(t('Access denied'), 'node2 is viewable');
}
}