You are here

function PanelizerNodeTest::testCloningDefaults in Panelizer 7.3

Make sure that cloning a default display works correctly.

File

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

Class

PanelizerNodeTest
Verifies Panelizer configuration options for nodes.

Code

function testCloningDefaults() {
  $content_type = 'page';
  $view_mode = 'page_manager';
  $original = "node:{$content_type}:default";
  $clone = "node:{$content_type}:clone_of_default";

  // Enable the node_view display in Page Manager.
  $this
    ->simpleEnablePage('node_view');

  // Check the Page Manager admin page.
  $this
    ->drupalGet('admin/structure/pages');
  $this
    ->assertResponse(200);
  $this
    ->assertLink(t('Disable'));

  // Panelize the content type and the view mode, give it a default display
  // and allow multiple displays.
  $edit = array();
  $edit['panelizer[status]'] = TRUE;
  $edit["panelizer[view modes][{$view_mode}][status]"] = TRUE;
  $edit["panelizer[view modes][{$view_mode}][default]"] = TRUE;
  $edit["panelizer[view modes][{$view_mode}][choice]"] = TRUE;
  $this
    ->drupalPost('admin/structure/types/manage/' . $content_type, $edit, t('Save content type'));
  $this
    ->assertResponse(200);

  // Add a custom class to the default display. Without making this change the
  // display won't be available via the CTools exports system.
  $this
    ->drupalGet("admin/structure/types/manage/{$content_type}/panelizer/{$view_mode}/{$original}/settings");
  $edit = array(
    'css_class' => 'panelizer-default',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Clone the default display.
  $this
    ->drupalGet("admin/structure/types/manage/{$content_type}/panelizer/{$view_mode}/{$original}/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);

  // Confirm the status message.
  $this
    ->assertText(t('!item has been created.', array(
    '!item' => $clone,
  )));

  // Load the two default displays.
  $default_names = array(
    $original => $original,
    $clone => $clone,
  );
  $defaults = ctools_export_load_object('panelizer_defaults', 'names', $default_names);
  $this
    ->verbose('<pre>' . print_r($defaults, TRUE) . '</pre>');

  // Compare the displays.
  $this
    ->compareDisplayPanes($defaults[$original], $defaults[$clone]);
}