0ef8451aba27eebdbd02842bb8aa75c37b9da590
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Plugin / PluginBaseTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Plugin;
4
5 use Drupal\Tests\UnitTestCase;
6
7 /**
8  * @coversDefaultClass \Drupal\Component\Plugin\PluginBase
9  * @group Plugin
10  */
11 class PluginBaseTest extends UnitTestCase {
12
13   /**
14    * @dataProvider providerTestGetPluginId
15    * @covers ::getPluginId
16    */
17   public function testGetPluginId($plugin_id, $expected) {
18     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
19       [],
20       $plugin_id,
21       [],
22     ]);
23
24     $this->assertEquals($expected, $plugin_base->getPluginId());
25   }
26
27   /**
28    * Returns test data for testGetPluginId().
29    *
30    * @return array
31    */
32   public function providerTestGetPluginId() {
33     return [
34       ['base_id', 'base_id'],
35       ['base_id:derivative', 'base_id:derivative'],
36     ];
37   }
38
39   /**
40    * @dataProvider providerTestGetBaseId
41    * @coves ::getBaseId
42    */
43   public function testGetBaseId($plugin_id, $expected) {
44     /** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit_Framework_MockObject_MockObject $plugin_base */
45     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
46       [],
47       $plugin_id,
48       [],
49     ]);
50
51     $this->assertEquals($expected, $plugin_base->getBaseId());
52   }
53
54   /**
55    * Returns test data for testGetBaseId().
56    *
57    * @return array
58    */
59   public function providerTestGetBaseId() {
60     return [
61       ['base_id', 'base_id'],
62       ['base_id:derivative', 'base_id'],
63     ];
64   }
65
66
67   /**
68    * @dataProvider providerTestGetDerivativeId
69    * @covers ::getDerivativeId
70    */
71   public function testGetDerivativeId($plugin_id = NULL, $expected = NULL) {
72     /** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit_Framework_MockObject_MockObject $plugin_base */
73     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
74       [],
75       $plugin_id,
76       [],
77     ]);
78
79     $this->assertEquals($expected, $plugin_base->getDerivativeId());
80   }
81
82   /**
83    * Returns test data for testGetDerivativeId().
84    *
85    * @return array
86    */
87   public function providerTestGetDerivativeId() {
88     return [
89       ['base_id', NULL],
90       ['base_id:derivative', 'derivative'],
91     ];
92   }
93
94   /**
95    * @covers ::getPluginDefinition
96    */
97   public function testGetPluginDefinition() {
98     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
99       [],
100       'plugin_id',
101       ['value', ['key' => 'value']],
102     ]);
103
104     $this->assertEquals(['value', ['key' => 'value']], $plugin_base->getPluginDefinition());
105   }
106
107 }