You are here

function PanelizerNodeTest::testPageMultipleDisplays in Panelizer 7.3

Verify that multiple displays work.

File

tests/panelizer.node.test, line 110
Test the node functionality for Panelizer.

Class

PanelizerNodeTest
Verifies Panelizer configuration options for nodes.

Code

function testPageMultipleDisplays() {

  // Panelize "Basic page" content type.
  $content_type = 'page';
  $view_mode = 'page_manager';

  // Ensure node_view panel page is enabled for full page override to work.
  $this
    ->simpleEnablePage('node_view');
  $edit = array(
    'panelizer[status]' => TRUE,
    // Enable the 'Full page override' view mode, which is managed by Page
    // Manager.
    'panelizer[view modes][' . $view_mode . '][status]' => TRUE,
    // Provide a default display.
    'panelizer[view modes][' . $view_mode . '][default]' => TRUE,
    // Allow a specific display to be selected per node.
    'panelizer[view modes][' . $view_mode . '][choice]' => TRUE,
  );
  $this
    ->drupalPost('admin/structure/types/manage/' . $content_type, $edit, t('Save content type'));
  $this
    ->assertResponse(200);

  // Verify the admin UI works.
  $this
    ->drupalGet('admin/structure/types/manage/' . $content_type . '/panelizer/' . $view_mode);
  $this
    ->assertResponse(200);

  // Confirm the default display was added.
  $this
    ->assertText('node:page:default');

  // Clone the display.
  $this
    ->drupalGet('admin/structure/types/manage/' . $content_type . '/panelizer/' . $view_mode . '/node:' . $content_type . ':default/clone');
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('Name'));
  $this
    ->assertFieldById('edit-title', "Clone of Default", "Administrative Title");

  // Manually set the machine name here as it's normally set by
  // machine-name.js, which doesn't work via SimpleTest.
  $this
    ->drupalPost(NULL, array(
    'name' => 'clone_of_default',
  ), t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('!item has been created.', array(
    '!item' => 'node:' . $content_type . ':clone_of_default',
  )));

  // Verity the tabs are present on the form.
  $this
    ->assertLink('Settings');
  $this
    ->assertLink('Context');
  $this
    ->assertLink('Access');
  $this
    ->assertLink('Layout');
  $this
    ->assertLink('Content');
  $this
    ->assertLink('Export');

  // Confirm the options show up on the node form.
  $this
    ->drupalGet('node/add/' . $content_type);
  $this
    ->assertField('panelizer[' . $view_mode . '][name]');

  // Create a node with cloned display mode.
  $args = array(
    'panelizer[' . $view_mode . '][name]' => 'node:' . $content_type . ':clone_of_default',
  );
  $node = $this
    ->createNode($args);

  // Check that the post has been panelized.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertLink('Customize display', 0, 'The customize display link appears on the page');
  $this
    ->assertLinkByHref('node/' . $node->nid . '/panelizer', 0, 'A link to customize the node appears on the page');

  // Check that the view mode can be panelized.
  $this
    ->drupalGet('node/' . $node->nid . '/panelizer');
  $this
    ->assertResponse(200);
  $this
    ->assertLink(t('Full page override'), 0, 'The panelize link for the "Full page override" view mode appears on the page');
  $this
    ->assertLinkByHref('node/' . $node->nid . '/panelizer/' . $view_mode, 0, 'A link to panelize the "Full page override" view mode appears on the page');
  $this
    ->assertNoLink(t('reset'), 0, 'The current display cannot be reset, it is default');
  $this
    ->assertText(t('Clone of Default'), 0, 'The current selected display is "Clone of Default"');

  // Verify that the view mode is not currently panelized.
  $this
    ->drupalGet('node/' . $node->nid . '/panelizer/' . $view_mode);
  $this
    ->assertResponse(200);

  // Panelize this view mode.
  $this
    ->drupalPost(NULL, array(), t('Save'));
  $this
    ->assertResponse(200);

  // Check that the view mode has been panelized.
  $this
    ->drupalGet('node/' . $node->nid . '/panelizer');
  $this
    ->assertResponse(200);
  $this
    ->assertLink(t('reset'), 0, 'The current panelizer state can be reset');
  $this
    ->assertText(t('Custom'), 0, 'The current panelizer state of this node is "Custom"');

  // Add a custom class to the original display.
  $panelizer_name = 'node:' . $content_type . ':default';
  $this
    ->drupalGet("admin/structure/types/manage/{$content_type}/panelizer/{$view_mode}/{$panelizer_name}/settings");
  $edit = array(
    'css_class' => 'panelizer-original',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Add a custom class to the cloned display.
  $panelizer_name = 'node:' . $content_type . ':clone_of_default';
  $this
    ->drupalGet("admin/structure/types/manage/{$content_type}/panelizer/{$view_mode}/{$panelizer_name}/settings");
  $edit = array(
    'css_class' => 'panelizer-clone',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

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

  // Load the node page.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);
  $elements = $this
    ->xpath('//body[contains(@class,:class)]', array(
    ':class' => 'panelizer-original',
  ));
  $this
    ->assertEqual(count($elements), 1, "The node is using the original display.");

  // Update the node to use the cloned display.
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertResponse(200);
  $edit = array(
    'panelizer[' . $view_mode . '][name]' => 'node:' . $content_type . ':clone_of_default',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $elements = $this
    ->xpath('//body[contains(@class,:class)]', array(
    ':class' => 'panelizer-clone',
  ));
  $this
    ->assertEqual(count($elements), 1, "The node is using the cloned display.");

  // Update the node again to use the original display.
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertResponse(200);
  $edit = array(
    'panelizer[' . $view_mode . '][name]' => 'node:' . $content_type . ':default',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $elements = $this
    ->xpath('//body[contains(@class,:class)]', array(
    ':class' => 'panelizer-original',
  ));
  $this
    ->assertEqual(count($elements), 1, "The node is using the original display again.");
}