public function UiPatternsSettingsRenderTest::testRender in UI Patterns Settings 8.2
Same name and namespace in other branches
- 8 tests/src/Functional/UiPatternsSettingsRenderTest.php \Drupal\Tests\ui_patterns_settings\Functional\UiPatternsSettingsRenderTest::testRender()
Tests pattern preview suggestions.
File
- tests/
src/ Functional/ UiPatternsSettingsRenderTest.php, line 52
Class
- UiPatternsSettingsRenderTest
- Test pattern preview rendering.
Namespace
Drupal\Tests\ui_patterns_settings\FunctionalCode
public function testRender() {
$assert_session = $this
->assertSession();
$this
->drupalCreateContentType([
'type' => 'article',
]);
$created_node = $this
->drupalCreateNode([
'title' => t('Hello Settings'),
'type' => 'article',
]);
$this
->enableTwigDebugMode();
$user = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($user);
// Define mapping for each setting type.
$mappings = [
'[textfield]' => [
'input' => 'Text',
'result' => 'Textfield: Text',
],
'[number]' => [
'input' => '10',
'result' => 'Number: 10',
],
'[token][input]' => [
'input' => '[node:nid]',
'result' => 'Token: 1',
],
'[url][input]' => [
'input' => 'internal:/node/1',
'result' => 'Url: /node/1',
],
'[boolean]' => [
'input' => '1',
'result' => 'Boolean: 1',
],
'[select]' => [
'input' => 'key',
'result' => 'Select: key',
],
'[enumeration]' => [
'input' => 'key',
'result' => 'Enumeration: key',
],
'[colorwidget][colorwidget]' => [
'input' => 'key',
'result' => 'Colorwidget: key',
],
'[checkboxes][box1]' => [
'input' => TRUE,
'result' => 'Checkboxes: Box1',
],
'[attributes]' => [
'input' => 'class="class"',
'result' => 'Attributes: class="class"',
],
'[group_sub]' => [
'input' => 'group_sub',
'result' => 'Group sub: group_sub',
],
];
// Select the layout.
$edit = [
'ds_layout' => 'pattern_foo_settings',
];
$this
->drupalPostForm('/admin/structure/types/manage/article/display', $edit, 'Save');
// Fill settings.
$edit = [];
foreach ($mappings as $key => $mapping) {
$edit['layout_configuration[pattern][settings]' . $key] = $mapping['input'];
}
$this
->drupalPostForm('/admin/structure/types/manage/article/display', $edit, 'Save');
// Check values.
$this
->drupalGet('/node/' . $created_node
->id());
foreach ($mappings as $key => $mapping) {
$assert_session
->responseContains($mapping['result']);
}
$assert_session
->responseContains('Configuration: config_value');
}