You are here

public function InternalNodesNodeCase::testNodeSettings in Internal Nodes 7

File

tests/internal_nodes_node.test, line 49
SimpleTest for Internal nodes

Class

InternalNodesNodeCase
@file SimpleTest for Internal nodes

Code

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