PluginIdTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Drupal\Tests\Component\Annotation;
  3. use Drupal\Component\Annotation\PluginID;
  4. use PHPUnit\Framework\TestCase;
  5. /**
  6. * @coversDefaultClass \Drupal\Component\Annotation\PluginId
  7. * @group Annotation
  8. */
  9. class PluginIdTest extends TestCase {
  10. /**
  11. * @covers ::get
  12. */
  13. public function testGet() {
  14. // Assert plugin starts empty regardless of constructor.
  15. $plugin = new PluginID([
  16. 'foo' => 'bar',
  17. 'biz' => [
  18. 'baz' => 'boom',
  19. ],
  20. 'nestedAnnotation' => new PluginID([
  21. 'foo' => 'bar',
  22. ]),
  23. 'value' => 'biz',
  24. ]);
  25. $this->assertEquals([
  26. 'id' => NULL,
  27. 'class' => NULL,
  28. 'provider' => NULL,
  29. ], $plugin->get());
  30. // Set values and ensure we can retrieve them.
  31. $plugin->value = 'foo';
  32. $plugin->setClass('bar');
  33. $plugin->setProvider('baz');
  34. $this->assertEquals([
  35. 'id' => 'foo',
  36. 'class' => 'bar',
  37. 'provider' => 'baz',
  38. ], $plugin->get());
  39. }
  40. /**
  41. * @covers ::getId
  42. */
  43. public function testGetId() {
  44. $plugin = new PluginID([]);
  45. $plugin->value = 'example';
  46. $this->assertEquals('example', $plugin->getId());
  47. }
  48. }