You are here

function ContentAccessModuleTestCase::testOwnViewAccess in Content Access 7

Same name and namespace in other branches
  1. 6 tests/content_access.test \ContentAccessModuleTestCase::testOwnViewAccess()

Test own view access.

File

tests/content_access.test, line 284

Class

ContentAccessModuleTestCase

Code

function testOwnViewAccess() {

  // Setup 2 test users.
  $test_user1 = $this->test_user;
  $test_user2 = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Change ownership of test nodes to test users.
  $this->node1->uid = $test_user1->uid;
  node_save($this->node1);
  $this->node2->uid = $test_user2->uid;
  node_save($this->node2);

  // Remove all view permissions for this content type.
  $access_permissions = array(
    'view[1]' => FALSE,
    'view[2]' => FALSE,
    'view_own[1]' => FALSE,
    'view_own[2]' => FALSE,
  );
  $this
    ->changeAccessContentType($access_permissions);

  // Allow view own content for test user 1 and 2 roles.
  $this
    ->changeAccessContentTypeKeyword('view_own', TRUE, $test_user1);
  $this
    ->changeAccessContentTypeKeyword('view_own', TRUE, $test_user2);

  // Logout admin and try to access both nodes anonymously.
  $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');

  // Login test user 1, view node1, access must be granted.
  $this
    ->drupalLogin($test_user1);
  $this
    ->drupalGet('node/' . $this->node1->nid);
  $this
    ->assertNoText(t('Access denied'), 'node1 is viewable');

  // View node2, access must be denied.
  $this
    ->drupalGet('node/' . $this->node2->nid);
  $this
    ->assertText(t('Access denied'), 'node2 is not viewable');

  // Login test user 2, view node1, access must be denied.
  $this
    ->drupalLogin($test_user2);
  $this
    ->drupalGet('node/' . $this->node1->nid);
  $this
    ->assertText(t('Access denied'), 'node1 is not viewable');

  // View node2, access must be granted.
  $this
    ->drupalGet('node/' . $this->node2->nid);
  $this
    ->assertNoText(t('Access denied'), 'node2 is viewable');
}