View source
<?php
namespace Drupal\Tests\ds\Functional;
class LayoutPluginTest extends TestBase {
public function testFieldPlugin() {
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('Test One column');
$this
->assertSession()
->responseContains('Test Two column');
$layout = [
'ds_layout' => 'dstest_2col',
];
$assert = [
'regions' => [
'left' => '<td colspan="8">' . t('Left') . '</td>',
'right' => '<td colspan="8">' . t('Right') . '</td>',
],
];
$fields = [
'fields[node_author][region]' => 'left',
'fields[node_links][region]' => 'left',
'fields[body][region]' => 'right',
];
$this
->dsSelectLayout($layout, $assert);
$this
->dsConfigureUi($fields);
$settings = [
'type' => 'article',
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains('group-left');
$this
->assertSession()
->responseContains('group-right');
$this
->assertSession()
->responseContains('dstest-2col.css');
$settings = [
'type' => 'article',
'title' => 'Alter me!',
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains('cool!');
}
public function testResetLayout() {
$layout = [
'ds_layout' => 'ds_reset',
];
$assert = [
'regions' => [
'ds_content' => '<td colspan="8">' . t('Content') . '</td>',
],
];
$fields = [
'fields[node_author][region]' => 'ds_content',
];
$this
->dsSelectLayout($layout, $assert);
$this
->dsConfigureUi($fields);
$settings = [
'type' => 'article',
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node
->id());
}
public function testDefaultWrappers() {
$settings = [
'type' => 'article',
];
$node = $this
->drupalCreateNode($settings);
$this
->dsSelectLayout();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseNotContains('<>');
$assert = [
'regions' => [
'ds_content' => '<td colspan="8">' . t('Content') . '</td>',
],
];
$this
->dsSelectLayout([
'ds_layout' => 'ds_1col',
], $assert);
$this
->drupalGet('node/' . $node
->id());
$elements = $this
->xpath('//div[@class="node node--type-article node--view-mode-full ds-1col clearfix"]/div/p');
$this
->assertCount(1, $elements);
$this
->assertTrimEqual($elements[0]
->getText(), $node
->get('body')->value);
$this->container
->get('theme_installer')
->install([
'ds_test_layout_theme',
]);
$config = \Drupal::configFactory()
->getEditable('system.theme');
$config
->set('default', 'ds_test_layout_theme')
->save();
drupal_flush_all_caches();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains('id="overridden-ds-1-col-template"');
$elements = $this
->xpath('//div[@class="node node--type-article node--view-mode-full ds-1col clearfix"]/div/p');
$this
->assertCount(1, $elements);
$this
->assertTrimEqual($elements[0]
->getText(), $node
->get('body')->value);
}
}