You are here

public function PanelizerIpeTest::testAdministerEntityLayout in Panelizer 8.3

@todo Confirm the 'administer panelizer $entity_type_id $bundle layout' permission works.

File

src/Tests/PanelizerIpeTest.php, line 226

Class

PanelizerIpeTest
Confirm that the IPE functionality works.

Namespace

Drupal\panelizer\Tests

Code

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

  // Need the node for the tests below, so create it now.
  $node = $this
    ->createTestNode();

  // Test with just the 'layout' permission
  $perms = [
    'administer panelizer node page layout',
  ];
  $drupalSettings = $this
    ->setupPermissionTests($perms, $node);
  $this
    ->assertNotNull($drupalSettings);
  if (!empty($drupalSettings)) {
    $this
      ->assertFalse(isset($drupalSettings['panels_ipe']));
    $this
      ->assertFalse(isset($drupalSettings['panelizer']));
  }

  // Make sure the user is logged out before doing another pass.
  $this
    ->drupalLogout();

  // Test with the 'revert' and the 'content' permission.
  $perms = [
    // The permission to be tested.
    'administer panelizer node page layout',
    // This permission has to be enabled for the 'revert' permission to work.
    'administer panelizer node page content',
  ];
  $drupalSettings = $this
    ->setupPermissionTests($perms, $node);
  $this
    ->assertNotNull($drupalSettings);

  // @todo How to tell if the user can change the layout vs other tasks?
  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
      ->assertFalse($drupalSettings['panelizer']['user_permission']['revert']);
    $this
      ->assertFalse($drupalSettings['panelizer']['user_permission']['save_default']);
  }
}