You are here

public function PanelizerNodeTranslationsTest::testPanelizerDefault in Panelizer 8.5

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/PanelizerNodeTranslationsTest.php \Drupal\Tests\panelizer\Functional\PanelizerNodeTranslationsTest::testPanelizerDefault()

Tests rendering a node with Panelizer default.

File

tests/src/Functional/PanelizerNodeTranslationsTest.php, line 148

Class

PanelizerNodeTranslationsTest
Test node translation handling in Panelizer.

Namespace

Drupal\Tests\panelizer\Functional

Code

public function testPanelizerDefault() {
  $this->container
    ->get('panelizer')
    ->setPanelizerSettings('node', $this->bundle, 'default', [
    'enable' => TRUE,
    'allow' => FALSE,
    'custom' => TRUE,
    'default' => 'default',
  ]);

  /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
  $panelizer = $this->container
    ->get('panelizer');
  $displays = $panelizer
    ->getDefaultPanelsDisplays($this->entityTypeId, $this->bundle, 'default');
  $display = $displays['default'];
  $display
    ->addBlock([
    'id' => 'panelizer_test',
    'label' => 'Panelizer test',
    'provider' => 'block_content',
    'region' => 'content',
  ]);
  $panelizer
    ->setDefaultPanelsDisplay('default', $this->entityTypeId, $this->bundle, 'default', $display);

  // Create a node, and check that the IPE is visible on it.
  $node = $this
    ->drupalCreateNode([
    'type' => $this->bundle,
    'langcode' => [
      [
        'value' => 'en',
      ],
    ],
  ]);
  $out = $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(200);
  $this
    ->verbose($out);
  $elements = $this
    ->xpath('//*[@id="panels-ipe-content"]');
  if (is_array($elements)) {
    $this
      ->assertIdentical(count($elements), 1);
  }
  else {
    $this
      ->fail('Could not parse page content.');
  }

  // Check that the block we added is visible.
  $this
    ->assertText('Panelizer test');
  $this
    ->assertText('Abracadabra');

  // Load the translation page.
  $this
    ->clickLink('Translate');
  $this
    ->assertText('English (Original language)');
  $this
    ->assertText('Published');
  $this
    ->assertText('Not translated');
}