You are here

function PanelizerExportablesTest::testExportablesChangeablePreEntity in Panelizer 7.3

Verify that the exported configuration can be edited when applied to an individual entity.

File

tests/panelizer.exportables.test, line 136
Test the exportables functionality for Panelizer.

Class

PanelizerExportablesTest
@file Test the exportables functionality for Panelizer.

Code

function testExportablesChangeablePreEntity() {
  $perms = array(
    // Standard node permissions.
    'create page content',
    'edit own page content',
    // Allow access to the 'panelizer' tab.
    'administer panelizer node page overview',
    // Permission to manage the 'content', i.e. the display.
    'administer panelizer node page content',
    // Allow choosing the display that is used.
    'administer panelizer node page choice',
  );
  $web_user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($web_user);

  // Create a node.
  $edit = array(
    'panelizer[page_manager][name]' => 'node:page:without_storage',
  );
  $node = $this
    ->createNode($edit);
  $this
    ->assertNotEqual($node->nid, 0);

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

  // Confirm there's a link to the 'content' page, and load it.
  $path = 'node/' . $node->nid . '/panelizer/page_manager/content';
  $this
    ->assertLinkByHref(url($path));
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200);

  // Confirm the 'Add content' link is on the page.
  $this
    ->assertLink(t('Add content'));
  $ajax_path = 'panels/ajax/editor/select-content/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid . '/center';

  // Need to pass the path through url() to get the correct syntax for the
  // actual link.
  $this
    ->assertLinkByHref(url($ajax_path));

  // Load the AJAX path to see what it contains.
  $json = $this
    ->drupalGetAJAX($ajax_path);
  $this
    ->assertResponse(200);

  // Examine the JSON response from the AJAX API.
  $this
    ->verbose('<pre>' . print_r($json, TRUE) . '</pre>');

  // $this->assertEqual(count($json), 2);
  $this
    ->assertTrue(isset($json[0]['command']));
  $this
    ->assertEqual($json[0]['command'], 'settings');
  $this
    ->assertTrue(isset($json[0]['settings']));
  $this
    ->assertTrue(isset($json[0]['merge']));
  $this
    ->assertEqual($json[0]['merge'], 'TRUE');
  $this
    ->assertTrue(isset($json[1]['command']));

  // This is what should happen.
  $this
    ->assertEqual($json[1]['command'], 'modal_display');
  $this
    ->assertTrue(isset($json[1]['title']));
  if (isset($json[1]['title'])) {
    $this
      ->assertEqual($json[1]['title'], t('Add content to Center'));
  }
  $this
    ->assertTrue(isset($json[1]['output']));

  // This is what should not happen.
  $this
    ->assertNotEqual($json[1]['command'], 'alert');
  $this
    ->assertFalse(isset($json[1]['text']));
  if (isset($json[1]['text'])) {
    $this
      ->assertNotEqual($json[1]['text'], t('You are not authorized to access this page.'), 'Access Denied error in the AJAX response.');
  }
}