View source
<?php
namespace Drupal\Tests\ds\Functional;
class DynamicFieldPluginTest extends TestBase {
public function testDsFields() {
$edit = [
'name' => 'Test field',
'id' => 'test_field',
'entities[node]' => '1',
'content[value]' => 'Test field',
];
$this
->dsCreateTokenField($edit);
$this
->drupalPostForm('admin/structure/ds/fields/manage_token', $edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
$this
->dsSelectLayout();
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('fields[dynamic_token_field:node-test_field][weight]');
$this
->drupalGet('admin/config/people/accounts/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_token_field:node-test_field][weight]');
$edit = [
'name' => 'Test field 2',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_token/test_field', $edit, 'Save');
$this
->assertSession()
->pageTextContains('The field Test field 2 has been saved');
$this
->dsSelectLayout([], [], 'admin/structure/types/manage/page/display');
$this
->dsSelectLayout([], [], 'admin/structure/types/manage/article/display/teaser');
$edit = [
'ui_limit' => 'article|default',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_token/test_field', $edit, 'Save');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('fields[dynamic_token_field:node-test_field][weight]');
$this
->drupalGet('admin/structure/types/manage/article/display/teaser');
$this
->assertSession()
->responseNotContains('fields[dynamic_token_field:node-test_field][weight]');
$this
->drupalGet('admin/structure/types/manage/page/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_token_field:node-test_field][weight]');
$edit = [
'ui_limit' => 'article|*',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_token/test_field', $edit, 'Save');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('fields[dynamic_token_field:node-test_field][weight]');
$this
->drupalGet('admin/structure/types/manage/article/display/teaser');
$this
->assertSession()
->responseContains('fields[dynamic_token_field:node-test_field][weight]');
$this
->drupalPostForm('admin/structure/ds/fields/delete/test_field', [], 'Confirm');
$this
->assertSession()
->pageTextContains('The field Test field 2 has been deleted');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_token_field:node-test_field][weight]');
$edit = [
'name' => 'Test block field',
'id' => 'test_block_field',
'entities[node]' => '1',
'block' => 'system_powered_by_block',
];
$this
->dsCreateBlockField($edit);
$this
->drupalPostForm('admin/structure/ds/fields/manage_block', $edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
$this
->dsSelectLayout();
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('fields[dynamic_block_field:node-test_block_field][weight]');
$this
->drupalGet('admin/config/people/accounts/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_block_field:node-test_block_field][weight]');
$edit = [
'name' => 'Test block field 2',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_block/test_block_field', $edit, 'Save');
$this
->assertSession()
->pageTextContains('The field Test block field 2 has been saved');
$this
->drupalPostForm('admin/structure/ds/fields/delete/test_block_field', [], 'Confirm');
$this
->assertSession()
->pageTextContains('The field Test block field 2 has been deleted');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_block_field:node-test_block_field][weight]');
$edit = [
'name' => 'Configurable block <script>alert("XSS")</script>',
'id' => 'test_block_configurable',
'entities[node]' => '1',
'block' => 'system_menu_block:tools',
];
$this
->dsCreateBlockField($edit);
$edit = [
'depth' => '3',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_block/test_block_configurable/block_config', $edit, 'Save');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->responseContains('fields[dynamic_block_field:node-test_block_configurable][weight]');
$this
->drupalGet('admin/config/people/accounts/display');
$this
->assertSession()
->responseNotContains('fields[dynamic_block_field:node-test_block_configurable][weight]');
$fields = [
'fields[dynamic_block_field:node-test_block_configurable][region]' => 'left',
'fields[dynamic_block_field:node-test_block_configurable][label]' => 'above',
];
$this
->dsConfigureUi($fields, 'admin/structure/types/manage/article/display');
$node = $this
->entitiesTestSetup();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains('Add content');
$this
->assertSession()
->responseNotContains('<script>alert("XSS")</script>');
$edit = [
'level' => '2',
];
$this
->drupalPostForm('admin/structure/ds/fields/manage_block/test_block_configurable/block_config', $edit, 'Save');
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseNotContains('Add content');
}
}