X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews_ui%2Fsrc%2FTests%2FAreaEntityUITest.php;fp=web%2Fcore%2Fmodules%2Fviews_ui%2Fsrc%2FTests%2FAreaEntityUITest.php;h=ffe895ab036b6fdfa20fde269b5918a564539fec;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views_ui/src/Tests/AreaEntityUITest.php b/web/core/modules/views_ui/src/Tests/AreaEntityUITest.php new file mode 100644 index 000000000..ffe895ab0 --- /dev/null +++ b/web/core/modules/views_ui/src/Tests/AreaEntityUITest.php @@ -0,0 +1,101 @@ + '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->urlInfo('edit-form')); + + // Add a global NULL argument to the view for testing argument placeholders. + $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/argument", ['name[views.null]' => 1], 'Add and configure contextual filters'); + $this->drupalPostForm(NULL, [], 'Apply'); + + // Configure both the entity_test area header and the block header to + // reference the given entities. + $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_block]' => 1], 'Add and configure header'); + $this->drupalPostForm(NULL, ['options[target]' => $block->id()], 'Apply'); + + $this->drupalPostForm("admin/structure/views/nojs/add-handler/$id/page_1/header", ['name[views.entity_entity_test]' => 1], 'Add and configure header'); + $this->drupalPostForm(NULL, ['options[target]' => $entity_test->id()], 'Apply'); + + $this->drupalPostForm(NULL, [], 'Save'); + + // Confirm the correct target identifiers were saved for both entities. + $view = View::load($id); + $header = $view->getDisplay('default')['display_options']['header']; + $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header)); + + $this->assertEqual($block->id(), $header['entity_block']['target']); + $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']); + + // Confirm that the correct serial ID (for the entity_test) and config ID + // (for the block) are displayed in the form. + $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block"); + $this->assertFieldByName('options[target]', $block->id()); + + $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test"); + $this->assertFieldByName('options[target]', $entity_test->id()); + + // Replace the header target entities with argument placeholders. + $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply'); + $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply'); + $this->drupalPostForm(NULL, [], 'Save'); + + // Confirm that the argument placeholders are saved. + $view = View::load($id); + $header = $view->getDisplay('default')['display_options']['header']; + $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header)); + + $this->assertEqual('{{ raw_arguments.null }}', $header['entity_block']['target']); + $this->assertEqual('{{ raw_arguments.null }}', $header['entity_entity_test']['target']); + + // Confirm that the argument placeholders are still displayed in the form. + $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_block"); + $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}'); + + $this->drupalGet("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test"); + $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}'); + + // Change the targets for both headers back to the entities. + $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_block", ['options[target]' => $block->id()], 'Apply'); + $this->drupalPostForm("admin/structure/views/nojs/handler/$id/page_1/header/entity_entity_test", ['options[target]' => $entity_test->id()], 'Apply'); + $this->drupalPostForm(NULL, [], 'Save'); + + // Confirm the targets were again saved correctly and not skipped based on + // the previous form value. + $view = View::load($id); + $header = $view->getDisplay('default')['display_options']['header']; + $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header)); + + $this->assertEqual($block->id(), $header['entity_block']['target']); + $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']); + } + +}