Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Plugin / PluginBaseTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Plugin;
4
5 use PHPUnit\Framework\TestCase;
6
7 /**
8  * @coversDefaultClass \Drupal\Component\Plugin\PluginBase
9  * @group Plugin
10  */
11 class PluginBaseTest extends TestCase {
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    * @dataProvider providerTestGetDerivativeId
68    * @covers ::getDerivativeId
69    */
70   public function testGetDerivativeId($plugin_id = NULL, $expected = NULL) {
71     /** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit_Framework_MockObject_MockObject $plugin_base */
72     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
73       [],
74       $plugin_id,
75       [],
76     ]);
77
78     $this->assertEquals($expected, $plugin_base->getDerivativeId());
79   }
80
81   /**
82    * Returns test data for testGetDerivativeId().
83    *
84    * @return array
85    */
86   public function providerTestGetDerivativeId() {
87     return [
88       ['base_id', NULL],
89       ['base_id:derivative', 'derivative'],
90     ];
91   }
92
93   /**
94    * @covers ::getPluginDefinition
95    */
96   public function testGetPluginDefinition() {
97     $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
98       [],
99       'plugin_id',
100       ['value', ['key' => 'value']],
101     ]);
102
103     $this->assertEquals(['value', ['key' => 'value']], $plugin_base->getPluginDefinition());
104   }
105
106 }