You are here

internal_nodes_node.test in Internal Nodes 7

SimpleTest for Internal nodes

File

tests/internal_nodes_node.test
View source
<?php

/**
 * @file
 * SimpleTest for Internal nodes
 */
class InternalNodesNodeCase extends DrupalWebTestCase {
  protected $admin_user;
  protected $node;

  // Untouched.
  protected $node_404;

  // Set to 404.
  protected $node_403;

  // Set to 403.
  protected $node_301;

  // Set to 301.
  public static function getInfo() {
    return array(
      'name' => 'Internal nodes - Node Tests',
      'description' => 'Check Internal nodes Node functionality.',
      'group' => 'Internal nodes',
    );
  }
  public function setUp() {

    // Enable any modules required for the test
    parent::setUp('internal_nodes');

    // Create test nodes (normal, 403, 404, and 301)
    $this->node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->node_404 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->node_403 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->node_301 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));

    // Create admin user
    $admin_perms = array(
      'access content',
      'administer content types',
      'administer nodes',
      'edit any page content',
      'access administration pages',
      'administer internal nodes',
      'access page node view',
    );
    $this->admin_user = $this
      ->drupalCreateUser($admin_perms);
  }
  public function testNodeSettings() {

    // Login as admin
    $this
      ->drupalLogin($this->admin_user);

    // Set enable per-node on page content type, leave default action as allow
    $edit = array(
      'internal_nodes_nodes' => TRUE,
    );
    $this
      ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
    $this
      ->assertText(t('has been updated.'), 'Per-node enabled.');

    // Set set 404 on node_404
    $edit = array(
      'internal_nodes_action' => 404,
    );
    $this
      ->drupalPost('node/' . $this->node_404->nid . '/edit', $edit, t('Save'));
    $this
      ->assertText(t('has been updated.'), 'Node 404 set to access denied.');

    // Set set 403 on node_403
    $edit = array(
      'internal_nodes_action' => 403,
    );
    $this
      ->drupalPost('node/' . $this->node_403->nid . '/edit', $edit, t('Save'));
    $this
      ->assertText(t('has been updated.'), 'Node 403 set to access denied.');

    // Set set 403 on node_301
    $edit = array(
      'internal_nodes_action' => 301,
      'internal_nodes_url' => 'node/1',
    );

    // Set redirect to node1.
    $this
      ->drupalPost('node/' . $this->node_301->nid . '/edit', $edit, t('Save'));
    $this
      ->assertText(t('has been updated.'), 'Node 301 set to redirect.');

    // Check access to untouched node
    $this
      ->drupalGet('node/' . $this->node->nid);
    $this
      ->assertText($this->node->title, 'Unmodified node accessible to role with permission.');

    // Check access to node 404
    $this
      ->drupalGet('node/' . $this->node_404->nid);
    $this
      ->assertText($this->node_404->title, 'Node 404 accessible to role with permission.');

    // Check access to node 403
    $this
      ->drupalGet('node/' . $this->node_403->nid);
    $this
      ->assertText($this->node_403->title, 'Node 403 accessible to role with permission.');

    // Check access to node 301
    $this
      ->drupalGet('node/' . $this->node_301->nid);
    $this
      ->assertText($this->node_301->title, 'Node 301 accessible to role with permission.');

    // Switch user to regular user
    $this
      ->drupalLogout();

    // Check access to untouched node
    $this
      ->drupalGet('node/' . $this->node->nid);
    $this
      ->assertText($this->node->title, 'Unmodified node accessible to role.');

    // Check access to node 404
    $this
      ->drupalGet('node/' . $this->node_404->nid);
    $this
      ->assertText(t('Page not found'), 'Node 404 not accessible to role without permission.');

    // Check access to node 403
    $this
      ->drupalGet('node/' . $this->node_403->nid);
    $this
      ->assertText(t('Access denied'), 'Node 403 not accessible to role without permission.');

    // Check access to node 301
    $this
      ->drupalGet('node/' . $this->node_301->nid);
    $this
      ->assertText($this->node->title, 'Node 301 redirects to node #1 for role without permission.');

    // Login as admin.
    $this
      ->drupalLogin($this->admin_user);

    // Enable outbound URL alter globally.
    $edit = array(
      'internal_nodes_outbound_alter' => TRUE,
    );
    $this
      ->drupalPost('admin/config/search/internal-nodes', $edit, t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved.'), 'Outbound URL config saved.');

    // Enable outbound URL alter for page content type
    $edit = array(
      'internal_nodes_outbound_alter' => TRUE,
    );
    $this
      ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));

    // Go to home page where node_301 has been promoted
    $this
      ->drupalGet('');

    // With outbound URL alter enabled, and permission enabled, the link
    // should NOT point to node/1 instead of node/4.
    $this
      ->assertLinkByHref('node/4', 0, 'Link to node/4 continues pointing to node/4.');

    // Switch user to regular user
    $this
      ->drupalLogout();

    // Go to home page where node_301 has been promoted
    $this
      ->drupalGet('');

    // With outbound URL alter enabled, and permission disabled, the link
    // should point to node/1 instead of node/4
    $this
      ->assertLinkByHref('node/1', 0, 'Link to node/4 has been changed to node/1.');

    // Login as admin.
    $this
      ->drupalLogin($this->admin_user);

    // Set disable per-node on page content type, leave default action as allow
    $edit = array(
      'internal_nodes_nodes' => FALSE,
    );
    $this
      ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
    $this
      ->assertText(t('has been updated.'), 'Per-node disabled.');

    // Switch user to regular user
    $this
      ->drupalLogout();

    // Check access to node 403 - Only testing one.
    $this
      ->drupalGet('node/' . $this->node_403->nid);
    $this
      ->assertText($this->node_403->title, 'Node 403 accessible to role when per-node disabled.');
  }

}

Classes

Namesort descending Description
InternalNodesNodeCase @file SimpleTest for Internal nodes