Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / AreaEntityUITest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\block\Entity\Block;
6 use Drupal\entity_test\Entity\EntityTest;
7 use Drupal\views\Entity\View;
8
9 /**
10  * Tests the entity area UI test.
11  *
12  * @see \Drupal\views\Plugin\views\area\Entity
13  * @group views_ui
14  */
15 class AreaEntityUITest extends UITestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['entity_test'];
21
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']);
25     $block->save();
26
27     $entity_test = EntityTest::create(['bundle' => 'entity_test']);
28     $entity_test->save();
29
30     $default = $this->randomView([]);
31     $id = $default['id'];
32     $view = View::load($id);
33
34     $this->drupalGet($view->urlInfo('edit-form'));
35
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');
39
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');
44
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');
47
48     $this->drupalPostForm(NULL, [], 'Save');
49
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));
54
55     $this->assertEqual($block->id(), $header['entity_block']['target']);
56     $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
57
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());
62
63     $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
64     $this->assertFieldByName('options[target]', $entity_test->id());
65
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');
70
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));
75
76     $this->assertEqual('{{ raw_arguments.null }}', $header['entity_block']['target']);
77     $this->assertEqual('{{ raw_arguments.null }}', $header['entity_entity_test']['target']);
78
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 }}');
82
83     $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test");
84     $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
85
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');
90
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));
96
97     $this->assertEqual($block->id(), $header['entity_block']['target']);
98     $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
99   }
100
101 }