3 namespace Drupal\Tests\views_ui\Functional;
5 use Drupal\block\Entity\Block;
6 use Drupal\entity_test\Entity\EntityTest;
7 use Drupal\views\Entity\View;
10 * Tests the entity area UI test.
12 * @see \Drupal\views\Plugin\views\area\Entity
15 class AreaEntityUITest extends UITestBase {
20 public static $modules = ['entity_test'];
22 public function testUI() {
23 // Set up a block and a entity_test entity.
24 $block = Block::create(['id' => 'test_id', 'plugin' => 'system_main_block']);
27 $entity_test = EntityTest::create(['bundle' => 'entity_test']);
30 $default = $this->randomView([]);
32 $view = View::load($id);
34 $this->drupalGet($view->urlInfo('edit-form'));
36 // Add a global NULL argument to the view for testing argument placeholders.
37 $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/argument", ['name[views.null]' => TRUE], 'Add and configure contextual filters');
38 $this->drupalPostForm(NULL, [], 'Apply');
40 // Configure both the entity_test area header and the block header to
41 // reference the given entities.
42 $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_block]' => TRUE], 'Add and configure header');
43 $this->drupalPostForm(NULL, ['options[target]' => $block->id()], 'Apply');
45 $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_entity_test]' => TRUE], 'Add and configure header');
46 $this->drupalPostForm(NULL, ['options[target]' => $entity_test->id()], 'Apply');
48 $this->drupalPostForm(NULL, [], 'Save');
50 // Confirm the correct target identifiers were saved for both entities.
51 $view = View::load($id);
52 $header = $view->getDisplay('default')['display_options']['header'];
53 $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
55 $this->assertEqual($block->id(), $header['entity_block']['target']);
56 $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
58 // Confirm that the correct serial ID (for the entity_test) and config ID
59 // (for the block) are displayed in the form.
60 $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block");
61 $this->assertFieldByName('options[target]', $block->id());
63 $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
64 $this->assertFieldByName('options[target]', $entity_test->id());
66 // Replace the header target entities with argument placeholders.
67 $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
68 $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
69 $this->drupalPostForm(NULL, [], 'Save');
71 // Confirm that the argument placeholders are saved.
72 $view = View::load($id);
73 $header = $view->getDisplay('default')['display_options']['header'];
74 $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
76 $this->assertEqual('{{ raw_arguments.null }}', $header['entity_block']['target']);
77 $this->assertEqual('{{ raw_arguments.null }}', $header['entity_entity_test']['target']);
79 // Confirm that the argument placeholders are still displayed in the form.
80 $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block");
81 $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
83 $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
84 $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
86 // Change the targets for both headers back to the entities.
87 $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => $block->id()], 'Apply');
88 $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => $entity_test->id()], 'Apply');
89 $this->drupalPostForm(NULL, [], 'Save');
91 // Confirm the targets were again saved correctly and not skipped based on
92 // the previous form value.
93 $view = View::load($id);
94 $header = $view->getDisplay('default')['display_options']['header'];
95 $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
97 $this->assertEqual($block->id(), $header['entity_block']['target']);
98 $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);