View source
<?php
namespace Drupal\Tests\panelizer\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
class PanelizerIpeTest extends BrowserTestBase {
use PanelizerTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'node',
'field',
'field_ui',
'user',
'layout_discovery',
'ctools',
'panels',
'panels_ipe',
'panelizer',
];
protected function setUp() {
parent::setUp();
$this
->rebuildAll();
}
protected $content_type = 'page';
protected function createAdminUser(array $perms = array()) {
$perms += [
'access administration pages',
'access content',
'administer content types',
'administer nodes',
'create page content',
'edit any page content',
'edit own page content',
'administer node display',
'access panels in-place editing',
];
$this
->verbose('<pre>' . print_r($perms, TRUE) . '</pre>');
return $this
->drupalCreateUser($perms);
}
public function testAdminUser() {
$this
->setupContentType($this->content_type);
$node = $this
->createTestNode();
$this
->loginUser1();
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$drupalSettings = NULL;
$matches = [];
if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $this
->getRawContent(), $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']));
}
}
public function testAdministerPanelizerPermission() {
$this
->setupContentType($this->content_type);
$node = $this
->createTestNode();
$perms = [
'administer panelizer',
];
$account = $this
->createAdminUser($perms);
$this
->drupalLogin($account);
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$drupalSettings = NULL;
$matches = [];
if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $this
->getRawContent(), $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']);
}
}
public function testAdministerEntityContentPermission() {
$this
->setupContentType($this->content_type);
$node = $this
->createTestNode();
$perms = [
'administer panelizer node page content',
];
$drupalSettings = $this
->setupPermissionTests($perms, $node);
$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']));
}
}
public function testAdministerEntityLayoutPermission() {
$this
->setupContentType($this->content_type);
$node = $this
->createTestNode();
$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']));
}
$this
->drupalLogout();
$perms = [
'administer panelizer node page layout',
'administer panelizer node page content',
];
$drupalSettings = $this
->setupPermissionTests($perms, $node);
$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
->assertFalse($drupalSettings['panelizer']['user_permission']['revert']);
$this
->assertFalse($drupalSettings['panelizer']['user_permission']['save_default']);
}
}
public function testAdministerEntityRevertPermission() {
$this
->setupContentType($this->content_type);
$node = $this
->createTestNode();
$perms = [
'administer panelizer node page revert',
];
$drupalSettings = $this
->setupPermissionTests($perms, $node);
$this
->assertNotNull($drupalSettings);
if (!empty($drupalSettings)) {
$this
->assertFalse(isset($drupalSettings['panels_ipe']));
$this
->assertFalse(isset($drupalSettings['panelizer']));
}
$this
->drupalLogout();
$perms = [
'administer panelizer node page revert',
'administer panelizer node page content',
];
$drupalSettings = $this
->setupPermissionTests($perms, $node);
$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
->assertFalse($drupalSettings['panelizer']['user_permission']['save_default']);
}
}
protected function setupPermissionTests(array $perms, $node = NULL) {
$account = $this
->createAdminUser($perms);
$this
->drupalLogin($account);
if (empty($node)) {
$node = $this
->createTestNode();
}
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$drupalSettings = NULL;
$matches = [];
if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $this
->getRawContent(), $matches)) {
$drupalSettings = Json::decode($matches[1]);
$this
->verbose('<pre>' . print_r($drupalSettings, TRUE) . '</pre>');
}
return $drupalSettings;
}
}