View source
<?php
namespace Drupal\Tests\panelizer\Functional;
use Drupal\Tests\content_translation\Functional\ContentTranslationTestBase;
class PanelizerNodeTranslationsTest extends ContentTranslationTestBase {
use PanelizerTestTrait;
protected $profile = 'standard';
public static $modules = [
'content_translation',
'field',
'field_ui',
'language',
'layout_discovery',
'node',
'ctools',
'ctools_block',
'panels',
'panels_ipe',
'panelizer',
'panelizer_test',
];
protected function setUp() {
parent::setUp();
$this
->loginUser1();
}
protected $entityTypeId = 'node';
protected $bundle = 'page';
public function _testWizardUI() {
$this
->panelize($this->bundle, NULL, [
'panelizer[custom]' => TRUE,
]);
$this
->drupalGet("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default__default");
$this
->assertResponse(200);
$this
->assertText('Wizard Information');
$this
->assertField('edit-label');
$this
->clickLink('Contexts');
$this
->assertText('@panelizer.entity_context:entity', 'The current entity context is present.');
$this
->clickLink('Layout');
$this
->assertSession()
->buttonExists('edit-update-layout');
$this
->clickLink('Content', 1);
$this
->clickLink('Add new block');
$this
->clickLink('Title');
$edit = [
'region' => 'content',
];
$this
->drupalPostForm(NULL, $edit, t('Add block'));
$this
->assertResponse(200);
$this
->drupalPostForm(NULL, [], t('Update and save'));
$this
->assertResponse(200);
$this
->assertText('Wizard Information');
$this
->assertField('edit-label');
$this
->drupalPostForm(NULL, [], t('Cancel'));
$this
->assertResponse(200);
$this
->assertFieldChecked('edit-panelizer-custom');
$edit = [
'panelizer[custom]' => FALSE,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertResponse(200);
$this
->assertNoFieldChecked('edit-panelizer-custom');
$this
->drupalGet("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default__default/content");
$this
->assertResponse(200);
$this
->clickLink('Add new block');
$this
->clickLink('Body');
$edit = [
'region' => 'content',
];
$this
->drupalPostForm(NULL, $edit, t('Add block'));
$this
->assertResponse(200);
$this
->assertText("entity_field:{$this->entityTypeId}:body", 'The body block was added successfully.');
$this
->drupalPostForm(NULL, [], t('Save'));
$this
->assertResponse(200);
$this
->clickLink('Content', 1);
$this
->assertText("entity_field:{$this->entityTypeId}:body", 'The body block was saved successfully.');
$this
->assertNoRaw('<div id="field-display-overview-wrapper">');
$this
->unpanelize($this->bundle);
$this
->assertNoLinkByHref("admin/structure/panelizer/edit/{$this->entityTypeId}__{$this->bundle}__default");
$this
->assertRaw('<div id="field-display-overview-wrapper">');
}
public function testPanelizerDefault() {
$this
->panelize($this->bundle, NULL, [
'panelizer[custom]' => TRUE,
]);
$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);
$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.');
}
$this
->assertText('Panelizer test');
$this
->assertText('Abracadabra');
$this
->clickLink('Translate');
$this
->assertText('English (Original language)');
$this
->assertText('Published');
$this
->assertText('Not translated');
}
}