You are here

internal_nodes_ct.test in Internal Nodes 7

SimpleTest for Internal nodes

File

tests/internal_nodes_ct.test
View source
<?php

/**
 * @file
 * SimpleTest for Internal nodes
 */
class InternalNodesTypeCase extends DrupalWebTestCase {
  protected $admin_user;
  protected $regular_user;
  protected $ctype_404;
  protected $ctype_403;
  protected $ctype_301;
  protected $ctype_301_out;
  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 - Content Type Tests',
      'description' => 'Check Internal nodes Content Type functionality.',
      'group' => 'Internal nodes',
    );
  }
  public function setUp() {

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

    // Create test content type - 404
    $this->ctype_404 = $this
      ->drupalCreateContentType();

    // Create test content type - 403
    $this->ctype_403 = $this
      ->drupalCreateContentType();

    // Create test content type - 301
    $this->ctype_301 = $this
      ->drupalCreateContentType();

    // Create test nodes
    $this->node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->node_404 = $this
      ->drupalCreateNode(array(
      'type' => $this->ctype_404->type,
    ));
    $this->node_403 = $this
      ->drupalCreateNode(array(
      'type' => $this->ctype_403->type,
    ));
    $this->node_301 = $this
      ->drupalCreateNode(array(
      'type' => $this->ctype_301->type,
      'promote' => 1,
    ));

    // Create admin user
    $admin_perms = array(
      'access content',
      'administer content types',
      'administer nodes',
      'access administration pages',
      'administer internal nodes',
      'access ' . $this->ctype_404->type . ' node view',
      'access ' . $this->ctype_403->type . ' node view',
      'access ' . $this->ctype_301->type . ' node view',
    );
    $this->admin_user = $this
      ->drupalCreateUser($admin_perms);

    // Create regular user - tests edit/delete of 403 content type
    $regular_perms = array(
      'access content',
      'edit any ' . $this->ctype_403->type . ' content',
      'delete any ' . $this->ctype_403->type . ' content',
    );
    $this->regular_user = $this
      ->drupalCreateUser($regular_perms);
  }
  public function testContentTypeSettings() {

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

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

    // Set content type 404 to Not Found
    $edit = array(
      'internal_nodes_action' => 404,
    );
    $this
      ->drupalPost('admin/structure/types/manage/' . $this->ctype_404->type, $edit, t('Save content type'));
    $this
      ->assertText(t('has been updated.'), '404 not found set.');

    // 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.');

    // Set content type 403 to access denied.
    $edit = array(
      'internal_nodes_action' => 403,
    );
    $this
      ->drupalPost('admin/structure/types/manage/' . $this->ctype_403->type, $edit, t('Save content type'));
    $this
      ->assertText(t('has been updated.'), '403 access denied set.');

    // 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.');

    // Set content type 301 to redirect.
    $edit = array(
      'internal_nodes_action' => 301,
    );
    $this
      ->drupalPost('admin/structure/types/manage/' . $this->ctype_301->type, $edit, t('Save content type'));
    $edit = array(
      'internal_nodes_url' => 'node/1',
    );

    // Set redirect to node1/
    $this
      ->drupalPost('admin/structure/types/manage/' . $this->ctype_301->type, $edit, t('Save content type'));
    $this
      ->assertText(t('has been updated.'), '301 redirect URL set.');

    // 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 anonymous user
    $this
      ->drupalLogout();

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

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

    // Check access to node 403
    $this
      ->drupalGet('node/' . $this->node_403->nid);
    $this
      ->assertText(t('Access denied'), 'Node 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 301 content type
    $edit = array(
      'internal_nodes_outbound_alter' => TRUE,
    );
    $this
      ->drupalPost('admin/structure/types/manage/' . $this->ctype_301->type, $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/3.
    $this
      ->assertLinkByHref('node/4', 0, 'Link to node/4 continues pointing to node/4.');

    // Switch user to anonymous 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 regular user.
    $this
      ->drupalLogin($this->regular_user);

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

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

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

}

Classes

Namesort descending Description
InternalNodesTypeCase @file SimpleTest for Internal nodes