diff --git a/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php b/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php new file mode 100644 index 0000000..ba21799 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php @@ -0,0 +1,107 @@ +annotationValue = [ + 'id' => $this->randomMachineName(), + 'class' => $this->getMockClass('\stdClass'), + // Test an arbitrary annotation key. + $this->randomMachineName() => $this->randomMachineName(), + // Test a NULL value. + 'null' => NULL, + 'provider' => $this->randomMachineName(), + ]; + + $this->sut = new Plugin($this->annotationValue); + } + + /** + * @covers ::__construct + * @covers ::parse + */ + public function testConstruct() { + $this->sut = new Plugin($this->annotationValue); + } + + /** + * @covers ::get + */ + public function testGet() { + $definition = $this->sut->get(); + // The SUT's default implementation returns array plugin definitions. + $this->assertInternalType('array', $definition); + // The $definition property is not part of the annotation, but is an + // implementation detail instead. As such, it must not appear in the plugin + // definition. + $this->assertArrayNotHasKey('definition', $definition); + + foreach ($this->annotationValue as $key => $value) { + $this->assertSame($value, $definition[$key]); + } + } + + /** + * @covers ::getId + */ + public function testGetId() { + $this->assertSame($this->annotationValue['id'], $this->sut->getId()); + } + + /** + * @covers ::getClass + * @covers ::setClass + */ + public function testGetClass() { + $this->assertSame($this->annotationValue['class'], $this->sut->getClass()); + $class = $this->getMockClass('\stdClass'); + $this->sut->setClass($class); + $this->assertSame($class, $this->sut->getClass()); + } + + /** + * @covers ::getProvider + * @covers ::setProvider + */ + public function testGetProvider() { + $this->assertSame($this->annotationValue['provider'], $this->sut->getProvider()); + $provider = $this->randomMachineName(); + $this->sut->setProvider($provider); + $this->assertSame($provider, $this->sut->getProvider()); + } + +}