PluginBaseTest.php 2.5 KB

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