You are here

public function PanelizerIpeTest::testAdministerPanelizer in Panelizer 8.3

Confirm the 'administer panelizer' permission works.

File

src/Tests/PanelizerIpeTest.php, line 126

Class

PanelizerIpeTest
Confirm that the IPE functionality works.

Namespace

Drupal\panelizer\Tests

Code

public function testAdministerPanelizer() {
  $this
    ->setupContentType();

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

  // Create a new user with the permissions being tested.
  $perms = [
    'administer panelizer',
  ];
  $account = $this
    ->createAdminUser($perms);
  $this
    ->drupalLogin($account);

  // Load the test node.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(200);

  // Confirm the appropriate DOM structures are present for the IPE.
  $drupalSettings = NULL;
  $matches = [];
  if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $this->content, $matches)) {
    $drupalSettings = Json::decode($matches[1]);
    $this
      ->verbose('<pre>' . print_r($drupalSettings, TRUE) . '</pre>');
  }
  $this
    ->assertNotNull($drupalSettings);
  if (!empty($drupalSettings)) {
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']));
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']['regions']));
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']['layout']));
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']['user_permission']));
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']['panels_display']));
    $this
      ->assertTrue(isset($drupalSettings['panels_ipe']['unsaved']));
    $this
      ->assertTrue(isset($drupalSettings['panelizer']));
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['entity']));
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_type_id']));
    $this
      ->assertEqual($drupalSettings['panelizer']['entity']['entity_type_id'], 'node');
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['entity']['entity_id']));
    $this
      ->assertEqual($drupalSettings['panelizer']['entity']['entity_id'], $node
      ->id());
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['user_permission']));
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['user_permission']['revert']));
    $this
      ->assertTrue(isset($drupalSettings['panelizer']['user_permission']['save_default']));
    $this
      ->assertTrue($drupalSettings['panelizer']['user_permission']['revert']);
    $this
      ->assertTrue($drupalSettings['panelizer']['user_permission']['save_default']);
  }
}