Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / tests / src / Unit / Plugin / HandlerBaseTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\views\Unit\Plugin\HandlerBaseTest.
6  */
7
8 namespace Drupal\Tests\views\Unit\Plugin;
9
10 use Drupal\Tests\UnitTestCase;
11 use Drupal\views\Plugin\views\HandlerBase;
12
13 /**
14  * @coversDefaultClass \Drupal\views\Plugin\views\HandlerBase
15  * @group Views
16  */
17 class HandlerBaseTest extends UnitTestCase {
18
19   use HandlerTestTrait;
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $this->setupViewsData();
28     $this->setupExecutableAndView();
29     $this->setupDisplay();
30   }
31
32   /**
33    * @covers ::getEntityType
34    */
35   public function testGetEntityTypeForFieldOnBaseTable() {
36     $handler = new TestHandler([], 'test_handler', []);
37     $handler->init($this->executable, $this->display);
38
39     $this->view->expects($this->any())
40       ->method('get')
41       ->with('base_table')
42       ->willReturn('test_entity_type_table');
43     $this->viewsData->expects($this->any())
44       ->method('get')
45       ->with('test_entity_type_table')
46       ->willReturn([
47         'table' => ['entity type' => 'test_entity_type']
48       ]);
49     $handler->setViewsData($this->viewsData);
50
51     $this->assertEquals('test_entity_type', $handler->getEntityType());
52   }
53
54   /**
55    * @covers ::getEntityType
56    */
57   public function testGetEntityTypeForFieldWithRelationship() {
58     $handler = new TestHandler([], 'test_handler', []);
59
60     $options = ['relationship' => 'test_relationship'];
61     $handler->init($this->executable, $this->display, $options);
62
63     $this->display->expects($this->atLeastOnce())
64       ->method('getOption')
65       ->with('relationships')
66       ->willReturn(['test_relationship' => ['table' => 'test_entity_type_table', 'id' => 'test_relationship', 'field' => 'test_relationship']]);
67
68     $this->view->expects($this->any())
69       ->method('get')
70       ->with('base_table')
71       ->willReturn('test_entity_type_table');
72
73     $this->viewsData->expects($this->any())
74       ->method('get')
75       ->willReturnMap([
76         [
77           'test_entity_type_table',
78           [
79             'table' => ['entity type' => 'test_entity_type'],
80             'test_relationship' => [
81               'relationship' => [
82                 'base' => 'test_other_entity_type_table',
83                 'base field' => 'id',
84               ],
85             ],
86           ],
87         ],
88         [
89           'test_other_entity_type_table',
90           ['table' => ['entity type' => 'test_other_entity_type']],
91         ],
92       ]);
93     $handler->setViewsData($this->viewsData);
94
95     $this->assertEquals('test_other_entity_type', $handler->getEntityType());
96   }
97
98 }
99
100 /**
101  * Allow testing base handler implementation by extending the abstract class.
102  */
103 class TestHandler extends HandlerBase {
104
105 }