You are here

protected function PanelizerNodeFunctionalTest::setUp in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/Tests/PanelizerNodeFunctionalTest.php \Drupal\Tests\panelizer\Functional\PanelizerNodeFunctionalTest::setUp()
  2. 8.4 tests/src/Functional/PanelizerNodeFunctionalTest.php \Drupal\Tests\panelizer\Functional\PanelizerNodeFunctionalTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/PanelizerNodeFunctionalTest.php, line 43

Class

PanelizerNodeFunctionalTest
Basic functional tests of using Panelizer with nodes.

Namespace

Drupal\Tests\panelizer\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('local_tasks_block');
  $this
    ->createContentType([
    'type' => 'page',
  ]);
  BlockContentType::create([
    'id' => 'test',
    'label' => 'Test',
  ])
    ->save();
  block_content_add_body_field('test');
  $blocks = [
    'alpha',
    'beta',
    'charlie',
  ];
  foreach ($blocks as $block) {
    BlockContent::create([
      'type' => 'test',
      'info' => "{$block} title",
      'body' => "{$block} body",
      'uuid' => $block,
    ])
      ->save();
  }

  /** @var \Drupal\panelizer\Panelizer $panelizer */
  $panelizer = $this->container
    ->get('panelizer');

  // Enable all of Panelizer's functionality for the 'full' view mode,
  // including the ability to set up custom layouts per entity and choose from
  // non-default layouts in the view display.
  $panelizer
    ->setPanelizerSettings('node', 'page', 'full', [
    'enable' => TRUE,
    'allow' => TRUE,
    'custom' => TRUE,
    'default' => 'default',
  ]);

  // Enable Panelizer for teasers, but don't allow per-entity customization
  // or non-default layout choices (yet).
  $panelizer
    ->setPanelizerSettings('node', 'page', 'teaser', [
    'enable' => TRUE,
    'allow' => FALSE,
    'custom' => FALSE,
    'default' => 'default',
  ]);
  $panelizer
    ->setDisplayStaticContexts('default', 'node', 'page', 'full', [
    'value' => [
      'type' => 'any',
      'label' => 'Lucky number',
      'description' => 'Always loop to this number and great things will happen',
      'value' => 42,
    ],
    'letter' => [
      'type' => 'string',
      'label' => 'Letter of the day',
      'description' => 'Straight from the NATO phonetic alphabet',
      'value' => 'Juliet',
    ],
  ]);
  $default = $panelizer
    ->getDefaultPanelsDisplay('default', 'node', 'page', 'full');
  $default
    ->addBlock([
    'id' => 'context_block',
    'region' => 'content',
    'weight' => 0,
  ]);
  $panelizer
    ->setDefaultPanelsDisplay('default', 'node', 'page', 'full', $default);

  // Clone the default display and save it with a new identifier so we can
  // test migration of non-default layouts.
  $alpha = clone $default;
  $configuration = $alpha
    ->getConfiguration();
  $configuration['label'] = 'Alpha';
  $configuration['static_context'] = [
    'value' => [
      'type' => 'any',
      'label' => 'Lucky number',
      'description' => '100 with an off-by-one error',
      'value' => 99,
    ],
    'letter' => [
      'type' => 'string',
      'label' => 'Letter of the day',
      'description' => 'The coolest letter in existence',
      'value' => 'X-ray',
    ],
  ];
  $alpha
    ->setConfiguration($configuration)
    ->addBlock([
    'id' => 'system_powered_by_block',
    'region' => 'content',
    'weight' => 0,
  ]);
  $alpha
    ->addBlock([
    'id' => 'block_content:alpha',
    'label' => 'alpha title',
    'region' => 'content',
    'weight' => 1,
  ]);
  $alpha
    ->addBlock([
    'id' => 'context_block',
    'region' => 'content',
    'weight' => 2,
  ]);
  $panelizer
    ->setDefaultPanelsDisplay('alpha', 'node', 'page', 'full', $alpha);
  $teaser_display = $panelizer
    ->getDefaultPanelsDisplay('default', 'node', 'page', 'teaser');
  $teaser_display
    ->addBlock([
    'id' => 'block_content:alpha',
    'label' => 'alpha teaser',
    'region' => 'content',
    'weight' => 1,
  ]);
  $teaser_display
    ->addBlock([
    'id' => 'context_block',
    'region' => 'content',
    'weight' => 2,
  ]);
  $configuration = $teaser_display
    ->getConfiguration();
  $configuration['static_context'] = [
    'value' => [
      'type' => 'any',
      'label' => 'Lucky number',
      'description' => 'A very good age to be',
      'value' => 35,
    ],
    'letter' => [
      'type' => 'string',
      'label' => 'Letter of the day',
      'description' => 'Ever dance with the devil in the pale moonlight?',
      'value' => 'Tango',
    ],
  ];
  $teaser_display
    ->setConfiguration($configuration);
  $panelizer
    ->setDefaultPanelsDisplay('default', 'node', 'page', 'teaser', $teaser_display);
  $this
    ->loginUser1();
}