Mercurial > hg > cmmr2012-drupal-site
comparison core/tests/Drupal/Tests/Component/Annotation/PluginTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\Component\Annotation; | |
4 | |
5 use Drupal\Component\Annotation\Plugin; | |
6 use PHPUnit\Framework\TestCase; | |
7 | |
8 /** | |
9 * @coversDefaultClass \Drupal\Component\Annotation\Plugin | |
10 * @group Annotation | |
11 */ | |
12 class PluginTest extends TestCase { | |
13 | |
14 /** | |
15 * @covers ::__construct | |
16 * @covers ::parse | |
17 * @covers ::get | |
18 */ | |
19 public function testGet() { | |
20 // Assert all values are accepted through constructor and default value is | |
21 // used for non existent but defined property. | |
22 $plugin = new PluginStub([ | |
23 'foo' => 'bar', | |
24 'biz' => [ | |
25 'baz' => 'boom', | |
26 ], | |
27 'nestedAnnotation' => new Plugin([ | |
28 'foo' => 'bar', | |
29 ]), | |
30 ]); | |
31 $this->assertEquals([ | |
32 // This property wasn't in our definition but is defined as a property on | |
33 // our plugin class. | |
34 'defaultProperty' => 'testvalue', | |
35 'foo' => 'bar', | |
36 'biz' => [ | |
37 'baz' => 'boom', | |
38 ], | |
39 'nestedAnnotation' => [ | |
40 'foo' => 'bar', | |
41 ], | |
42 ], $plugin->get()); | |
43 | |
44 // Without default properties, we get a completely empty plugin definition. | |
45 $plugin = new Plugin([]); | |
46 $this->assertEquals([], $plugin->get()); | |
47 } | |
48 | |
49 /** | |
50 * @covers ::getProvider | |
51 */ | |
52 public function testGetProvider() { | |
53 $plugin = new Plugin(['provider' => 'example']); | |
54 $this->assertEquals('example', $plugin->getProvider()); | |
55 } | |
56 | |
57 /** | |
58 * @covers ::setProvider | |
59 */ | |
60 public function testSetProvider() { | |
61 $plugin = new Plugin([]); | |
62 $plugin->setProvider('example'); | |
63 $this->assertEquals('example', $plugin->getProvider()); | |
64 } | |
65 | |
66 /** | |
67 * @covers ::getId | |
68 */ | |
69 public function testGetId() { | |
70 $plugin = new Plugin(['id' => 'example']); | |
71 $this->assertEquals('example', $plugin->getId()); | |
72 } | |
73 | |
74 /** | |
75 * @covers ::getClass | |
76 */ | |
77 public function testGetClass() { | |
78 $plugin = new Plugin(['class' => 'example']); | |
79 $this->assertEquals('example', $plugin->getClass()); | |
80 } | |
81 | |
82 /** | |
83 * @covers ::setClass | |
84 */ | |
85 public function testSetClass() { | |
86 $plugin = new Plugin([]); | |
87 $plugin->setClass('example'); | |
88 $this->assertEquals('example', $plugin->getClass()); | |
89 } | |
90 | |
91 } | |
92 /** | |
93 * {@inheritdoc} | |
94 */ | |
95 class PluginStub extends Plugin { | |
96 protected $defaultProperty = 'testvalue'; | |
97 | |
98 } |