You are here

function PanelizerWithPanelsIPE::testIpeContentEntityAccess in Panelizer 7.3

Test whether the IPE 'content' permissions work correctly w entity perms.

File

tests/panelizer.with_panels_ipe.test, line 260
Tests for Panels IPE.

Class

PanelizerWithPanelsIPE
@file Tests for Panels IPE.

Code

function testIpeContentEntityAccess() {
  $perms = array(
    // Standard node permissions.
    'create page content',
    'administer content types',
    'administer nodes',
    'bypass node access',
    // Panelizer.
    'administer panelizer',
  );
  $web_user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($web_user);

  // Just 'cause.
  drupal_flush_all_caches();

  // Create a test node.
  $node = $this
    ->createNode();

  // Enable IPE for this node.
  $this
    ->drupalGet('node/' . $node->nid . '/panelizer/page_manager/settings');
  $this
    ->assertResponse(200);
  $this
    ->assertFieldByName('pipeline');
  $edit = array(
    'pipeline' => 'ipe',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertText(t('The settings have been updated.'));

  // Log out the user so a new user can log in.
  $this
    ->drupalLogout();

  // Create a new user with the new permissions.
  $perms = array(
    // Standard node permissions.
    'create page content',
    'administer content types',
    'administer nodes',
    'bypass node access',
    // Panels IPE.
    'use panels in place editing',
    // Permission to manage the 'content', i.e. the display.
    'administer panelizer node page content',
  );
  $web_user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($web_user);

  // Load the node view page.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);

  // Confirm the IPE link is on the form.
  $this
    ->assertLink(t('Customize this page'));
  $path = 'panels/ajax/ipe/save_form/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
  $query_string = array(
    'destination' => 'node/' . $node->nid,
  );
  $full_path = url($path, array(
    'query' => array(
      'destination' => $query_string['destination'],
    ),
  ));
  $this
    ->assertLinkByHref($full_path);

  // Confirm the link via xpath.
  $xpath = $this
    ->xpath("//a[@id='panels-ipe-customize-page']");
  $this
    ->assertEqual(count($xpath), 1, 'Found the "Customize this page" link.');
  $this
    ->assertEqual($xpath[0]['href'], $full_path);

  //, 'The "Customize this Page" link is what was expected.');

  // Log out.
  $this
    ->drupalLogout();
  $perms = array(
    // Need to be able to access the node.
    'access content',
    // Panels IPE.
    'use panels in place editing',
    // Adds the "Change layout" functionality to IPE.
    'change layouts in place editing',
    // Panelizer.
    'administer panelizer',
    // Permission to manage the 'content', i.e. the display.
    'administer panelizer node page content',
    'administer panelizer node page layout',
  );
  $web_user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($web_user);

  // Load the node view page.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);

  // Confirm the IPE link is not on the form.
  $this
    ->assertNoLink(t('Customize this page'));
  $path = 'panels/ajax/ipe/save_form/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
  $query_string = array(
    'destination' => 'node/' . $node->nid,
  );
  $full_path = url($path, array(
    'query' => array(
      'destination' => $query_string['destination'],
    ),
  ));
  $this
    ->assertNoLinkByHref($full_path);

  // Confirm the IPE link is not on the form.
  $this
    ->assertNoLink(t('Change layout'));
  $path = 'panels/ajax/ipe/change_layout/panelizer:node:' . $node->nid . ':Apage_manager:' . $node->vid;
  $query_string = array(
    'destination' => 'node/' . $node->nid,
  );
  $full_path = url($path, array(
    'query' => array(
      'destination' => $query_string['destination'],
    ),
  ));
  $this
    ->assertNoLinkByHref($full_path);
}