View source
<?php
namespace Drupal\Tests\panels_everywhere\Functional;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\page_manager\Entity\PageVariant;
use Drupal\Tests\BrowserTestBase;
class DisplayVariantOverrideTest extends PanelsEverywhereBrowserTestBase {
protected $node;
protected function setUp() {
parent::setUp();
$block_ids = \Drupal::entityQuery('block')
->condition('theme', 'bartik')
->execute();
$blocks = \Drupal::entityTypeManager()
->getStorage('block')
->loadMultiple($block_ids);
foreach ($blocks as $block) {
if ($block
->getPluginId() == 'system_main_block') {
continue;
}
$block
->delete();
}
$this->node = Node::create([
'type' => 'article',
]);
$this->node
->setTitle('This is a node');
$this->node->body->value = 'This is some text.';
$this->node
->save();
}
public function testDisabledRouteOverrideForSiteTemplateCausesNodeToNotBeRendered() {
$site_template = $this->pageStorage
->load('site_template');
$site_template
->setStatus(TRUE);
$site_template
->save();
$defaultVariant = $site_template
->getVariant('panels_everywhere');
$this
->placeBlockOnVariant($defaultVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($defaultVariant, 'system_powered_by_block', 'content');
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextContains($this->node->body->value);
}
public function testEnabledRouteOverrideForSiteTemplateCausesNodeToNotBeRendered() {
$site_template = $this->pageStorage
->load('site_template');
$site_template
->setStatus(TRUE);
$site_template
->save();
$defaultVariant = $site_template
->getVariant('panels_everywhere');
$defaultVariant
->set('route_override_enabled', TRUE);
$this
->placeBlockOnVariant($defaultVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($defaultVariant, 'system_powered_by_block', 'content');
$defaultVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextContains($this->node->body->value);
}
public function testSiteTemplateAndPanelsCanBeRenderedOnTheSamePage() {
$site_template = $this->pageStorage
->load('site_template');
$site_template
->setStatus(TRUE);
$site_template
->save();
$panelsEverywhereVariant = $site_template
->getVariant('panels_everywhere');
$this
->placeBlockOnVariant($panelsEverywhereVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($panelsEverywhereVariant, 'system_powered_by_block', 'content');
$panelsEverywhereVariant
->save();
$node_view = $this->pageStorage
->load('node_view');
$panelsVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-panels-variant',
'variant' => 'panels_variant',
'variant_settings' => [
'id' => 'panels_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
],
]);
$panelsVariant
->setPageEntity($node_view);
$this
->placeBlockOnVariant($panelsVariant, 'entity_view:node', 'content', [
'view_mode' => 'full',
'context_mapping' => [
'entity' => 'node',
],
]);
$this
->placeBlockOnVariant($panelsVariant, 'views_block:who_s_new-block_1', 'content', [
'label_display' => 'visible',
'items_per_page' => 'none',
]);
$panelsVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextContains($this->node->body->value);
$this
->assertSession()
->pageTextContains("Who's new");
}
public function testDisabledRouteOverrideForNodeViewCausesNodeToBeRenderedNormally() {
$page = $this->pageStorage
->load('node_view');
$customVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-custom-variant',
'variant' => 'panels_everywhere_variant',
'variant_settings' => [
'id' => 'panels_everywhere_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
'route_override_enabled' => FALSE,
],
]);
$customVariant
->setPageEntity($page);
$this
->placeBlockOnVariant($customVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($customVariant, 'system_powered_by_block', 'content');
$customVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextContains($this->node->body->value);
}
public function testEnabledRouteOverrideForNodeViewWithoutOtherVariantPresentWillCausesNodeToNotBeRendered() {
$page = $this->pageStorage
->load('node_view');
$customVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-custom-variant',
'variant' => 'panels_everywhere_variant',
'variant_settings' => [
'id' => 'panels_everywhere_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
'route_override_enabled' => TRUE,
],
]);
$customVariant
->setPageEntity($page);
$this
->placeBlockOnVariant($customVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($customVariant, 'system_powered_by_block', 'content');
$customVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextNotContains($this->node->body->value);
}
public function testDisabledRouteOverrideForNodeViewWithPanelsVariantPresentWillCausesNodeToBeRendered() {
$page = $this->pageStorage
->load('node_view');
$panelsEverywhereVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-panels_everywhere-variant',
'variant' => 'panels_everywhere_variant',
'variant_settings' => [
'id' => 'panels_everywhere_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
'route_override_enabled' => FALSE,
],
]);
$panelsEverywhereVariant
->setPageEntity($page);
$this
->placeBlockOnVariant($panelsEverywhereVariant, 'system_main_block', 'content');
$this
->placeBlockOnVariant($panelsEverywhereVariant, 'system_powered_by_block', 'content');
$panelsEverywhereVariant
->save();
$panelsVariant = $this->pageVariantStorage
->create([
'id' => 'this-is-a-panels-variant',
'variant' => 'panels_variant',
'variant_settings' => [
'id' => 'panels_variant',
'layout' => 'layout_onecol',
'builder' => 'standard',
],
]);
$panelsVariant
->setPageEntity($page);
$this
->placeBlockOnVariant($panelsVariant, 'entity_view:node', 'content', [
'view_mode' => 'full',
'context_mapping' => [
'entity' => 'node',
],
]);
$this
->placeBlockOnVariant($panelsVariant, 'views_block:who_s_new-block_1', 'content', [
'label_display' => 'visible',
'items_per_page' => 'none',
]);
$panelsVariant
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->pageTextContains('Powered by');
$this
->assertSession()
->pageTextContains($this->node->body->value);
$this
->assertSession()
->pageTextContains("Who's new");
}
}