PluginManagerTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Plugin Manager tests
  4. */
  5. require_once 'application/PluginManager.php';
  6. /**
  7. * Unit tests for Plugins
  8. */
  9. class PluginManagerTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Path to tests plugin.
  13. * @var string $pluginPath
  14. */
  15. private static $pluginPath = 'tests/plugins';
  16. /**
  17. * Test plugin.
  18. * @var string $pluginName
  19. */
  20. private static $pluginName = 'test';
  21. /**
  22. * @var PluginManager $pluginManager Plugin Mananger instance.
  23. */
  24. protected $pluginManager;
  25. public function setUp()
  26. {
  27. $conf = new ConfigManager('');
  28. $this->pluginManager = new PluginManager($conf);
  29. }
  30. /**
  31. * Test plugin loading and hook execution.
  32. *
  33. * @return void
  34. */
  35. public function testPlugin()
  36. {
  37. PluginManager::$PLUGINS_PATH = self::$pluginPath;
  38. $this->pluginManager->load(array(self::$pluginName));
  39. $this->assertTrue(function_exists('hook_test_random'));
  40. $data = array(0 => 'woot');
  41. $this->pluginManager->executeHooks('random', $data);
  42. $this->assertEquals('woot', $data[1]);
  43. $data = array(0 => 'woot');
  44. $this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
  45. $this->assertEquals('page test', $data[1]);
  46. $data = array(0 => 'woot');
  47. $this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
  48. $this->assertEquals('loggedin', $data[1]);
  49. }
  50. /**
  51. * Test missing plugin loading.
  52. *
  53. * @return void
  54. */
  55. public function testPluginNotFound()
  56. {
  57. $this->pluginManager->load(array());
  58. $this->pluginManager->load(array('nope', 'renope'));
  59. }
  60. /**
  61. * Test plugin metadata loading.
  62. */
  63. public function testGetPluginsMeta()
  64. {
  65. PluginManager::$PLUGINS_PATH = self::$pluginPath;
  66. $this->pluginManager->load(array(self::$pluginName));
  67. $expectedParameters = array(
  68. 'pop' => array(
  69. 'value' => '',
  70. 'desc' => 'pop description',
  71. ),
  72. 'hip' => array(
  73. 'value' => '',
  74. 'desc' => '',
  75. ),
  76. );
  77. $meta = $this->pluginManager->getPluginsMeta();
  78. $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
  79. $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
  80. }
  81. }