View source
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\block\Entity\Block;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\views\Entity\View;
class AreaEntityUITest extends UITestBase {
protected static $modules = [
'entity_test',
];
protected $defaultTheme = 'stark';
public function testUI() {
$block = Block::create([
'id' => 'test_id',
'plugin' => 'system_main_block',
]);
$block
->save();
$entity_test = EntityTest::create([
'bundle' => 'entity_test',
]);
$entity_test
->save();
$default = $this
->randomView([]);
$id = $default['id'];
$view = View::load($id);
$this
->drupalGet($view
->toUrl('edit-form'));
$this
->drupalGet("admin/structure/views/nojs/add-handler/{$id}/page_1/argument");
$this
->submitForm([
'name[views.null]' => TRUE,
], 'Add and configure contextual filters');
$this
->submitForm([], 'Apply');
$this
->drupalGet("admin/structure/views/nojs/add-handler/{$id}/page_1/header");
$this
->submitForm([
'name[views.entity_block]' => TRUE,
], 'Add and configure header');
$this
->submitForm([
'options[target]' => $block
->id(),
], 'Apply');
$this
->drupalGet("admin/structure/views/nojs/add-handler/{$id}/page_1/header");
$this
->submitForm([
'name[views.entity_entity_test]' => TRUE,
], 'Add and configure header');
$this
->submitForm([
'options[target]' => $entity_test
->id(),
], 'Apply');
$this
->submitForm([], 'Save');
$view = View::load($id);
$header = $view
->getDisplay('default')['display_options']['header'];
$this
->assertEquals([
'entity_block',
'entity_entity_test',
], array_keys($header));
$this
->assertEquals($block
->id(), $header['entity_block']['target']);
$this
->assertEquals($entity_test
->uuid(), $header['entity_entity_test']['target']);
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
$this
->assertSession()
->fieldValueEquals('options[target]', $block
->id());
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
$this
->assertSession()
->fieldValueEquals('options[target]', $entity_test
->id());
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
$this
->submitForm([
'options[target]' => '{{ raw_arguments.null }}',
], 'Apply');
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
$this
->submitForm([
'options[target]' => '{{ raw_arguments.null }}',
], 'Apply');
$this
->submitForm([], 'Save');
$view = View::load($id);
$header = $view
->getDisplay('default')['display_options']['header'];
$this
->assertEquals([
'entity_block',
'entity_entity_test',
], array_keys($header));
$this
->assertEquals('{{ raw_arguments.null }}', $header['entity_block']['target']);
$this
->assertEquals('{{ raw_arguments.null }}', $header['entity_entity_test']['target']);
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
$this
->assertSession()
->fieldValueEquals('options[target]', '{{ raw_arguments.null }}');
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
$this
->assertSession()
->fieldValueEquals('options[target]', '{{ raw_arguments.null }}');
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
$this
->submitForm([
'options[target]' => $block
->id(),
], 'Apply');
$this
->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
$this
->submitForm([
'options[target]' => $entity_test
->id(),
], 'Apply');
$this
->submitForm([], 'Save');
$view = View::load($id);
$header = $view
->getDisplay('default')['display_options']['header'];
$this
->assertEquals([
'entity_block',
'entity_entity_test',
], array_keys($header));
$this
->assertEquals($block
->id(), $header['entity_block']['target']);
$this
->assertEquals($entity_test
->uuid(), $header['entity_entity_test']['target']);
}
}