You are here

protected function PanelizerTestTrait::addPanelizerDefault in Panelizer 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/PanelizerTestTrait.php \Drupal\Tests\panelizer\Functional\PanelizerTestTrait::addPanelizerDefault()

Parameters

string $content_type: The content type, i.e. the node bundle ID, to configure; defaults to 'page'.

1 call to PanelizerTestTrait::addPanelizerDefault()
PanelizerDefaultsTest::test in tests/src/Functional/PanelizerDefaultsTest.php

File

tests/src/Functional/PanelizerTestTrait.php, line 138

Class

PanelizerTestTrait
Contains helper methods for writing functional tests of Panelizer.

Namespace

Drupal\Tests\panelizer\Functional

Code

protected function addPanelizerDefault($content_type = 'page', $display = 'default') {
  $label = $this
    ->getRandomGenerator()
    ->word(16);
  $id = strtolower($label);
  $default_id = "node__{$content_type}__{$display}__{$id}";
  $options = [
    'query' => [
      'js' => 'nojs',
    ],
  ];
  $path = "admin/structure/types/manage/{$content_type}/display";
  if (!empty($display)) {
    $path .= '/' . $display;
  }
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200);
  $this
    ->clickLink('Add a new Panelizer default display');

  // Step 1: Enter the default's label and ID.
  $edit = [
    'id' => $id,
    'label' => $label,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Next'));
  $this
    ->assertResponse(200);

  // Step 2: Define contexts.
  $this
    ->assertUrl("admin/structure/panelizer/add/{$default_id}/contexts", $options);
  $this
    ->drupalPostForm(NULL, [], t('Next'));
  $this
    ->assertResponse(200);

  // Step 3: Select layout.
  $this
    ->assertUrl("admin/structure/panelizer/add/{$default_id}/layout", $options);
  $this
    ->drupalPostForm(NULL, [], t('Next'));
  $this
    ->assertResponse(200);

  // Step 4: If the layout has settings (new since Drupal 8.8), accept the
  // defaults.
  $layout_settings_form = $this
    ->getSession()
    ->getPage()
    ->find('css', '#panels-layout-settings-form');
  if ($layout_settings_form) {
    $layout_settings_form
      ->pressButton('Next');
  }

  // Step 5: Select content.
  $this
    ->assertUrl("admin/structure/panelizer/add/{$default_id}/content", $options);
  $this
    ->drupalPostForm(NULL, [], t('Finish'));
  $this
    ->assertResponse(200);
  return $id;
}