You are here

nodeaccess_grant.test in Nodeaccess 7

Tests for the nodeaccess module.

File

tests/nodeaccess_grant.test
View source
<?php

/**
 * @file
 * Tests for the nodeaccess module.
 */

/**
 * Tests the functionality of the nodeaccess module.
 */
class NodeaccesssGrantTabTestCase extends DrupalWebTestCase {

  /**
   * Enable the nodeaccess module.
   */
  public function setUp() {
    parent::setUp('nodeaccess');
  }

  /**
   * Provide some information about this test case.
   */
  public static function getInfo() {
    return array(
      'name' => 'Nodeaccess Grant Tab visibility',
      'description' => 'Tests whether the Grant tab appears correctly..',
      'group' => 'Nodeaccess',
    );
  }

  /**
   * Make sure the 'Grant' tab is available from the node view when appropriate.
   * @test
   */
  public function testGrantTabVisbility() {

    // Create a test user, and a node with nodeaccess enabled for its type.
    $user = $this
      ->drupalCreateUser(array(
      'grant node permissions',
    ));
    $node = $this
      ->drupalCreateNode();
    nodeaccess_add_type_grant($node->type);

    // First, before logging in, we shouldn't see a link.
    $this
      ->drupalGet("node/{$node->nid}");
    $this
      ->assertNoLinkByHref("node/{$node->nid}/grant");

    // Log in and the grant tab should appear.
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet("node/{$node->nid}");
    $this
      ->assertLinkByHref("node/{$node->nid}/grant");

    // Disable nodeaccess for this content type, and the tab should be gone.
    nodeaccess_delete_type_grant($node->type);
    $this
      ->drupalGet("node/{$node->nid}");
    $this
      ->assertNoLinkByHref("node/{$node->nid}/grant");

    // Confirm that the anonymous user still doesn't see the grant tab.
    $this
      ->drupalLogout();
    $this
      ->drupalGet("node/{$node->nid}");
    $this
      ->assertNoLinkByHref("node/{$node->nid}/grant");
  }

}

Classes

Namesort descending Description
NodeaccesssGrantTabTestCase Tests the functionality of the nodeaccess module.