prophesize(); $prophecy->willExtend(\common_ext_Extension::class); return $prophecy->reveal(); } /** * @see \oat\oatbox\AbstractRegistry::getConfigId() */ protected function getConfigId() { return 'plugin_registry'; } } /** * Concrete class PluginService * @package oat\tao\test\unit\plugins */ class PluginService extends AbstractPluginService { } /** * Test the AbstractPluginService * * @author Bertrand Chevrier * @author Jean-Sébastien Conan */ class AbstractPluginServiceTest extends TestCase { //data to stub the registry content private static $pluginData = [ 'my/wonderful/plugin/title' => [ 'id' => 'title', 'module' => 'my/wonderful/plugin/title', 'bundle' => 'plugins/bundle.min', 'position' => 1, 'name' => 'Wonderful Title', 'description' => 'Display a wonderful title', 'category' => 'content', 'active' => true, 'tags' => ['core', 'component'] ], 'my/wonderful/plugin/text' => [ 'id' => 'text', 'module' => 'my/wonderful/plugin/text', 'bundle' => 'plugins/bundle.min', 'position' => 2, 'name' => 'Wonderful Text', 'description' => 'Display a wonderful text', 'category' => 'content', 'active' => true, 'tags' => ['core', 'component'] ] ]; /** * Get the service with the stubbed registry * @return AbstractPluginService */ protected function getPluginService() { $prophet = new Prophet(); $prophecy = $prophet->prophesize(); $prophecy->willExtend(PluginRegistry::class); $prophecy->getMap()->willReturn(self::$pluginData); $pluginService = new PluginService(); $pluginService->setRegistry($prophecy->reveal()); return $pluginService; } /** * Check the service is a service */ public function testApi() { $pluginService = $this->getPluginService(); $this->assertInstanceOf(AbstractPluginService::class, $pluginService); $this->assertInstanceOf(ConfigurableService::class, $pluginService); } /** * Test the method AbstractPluginService::getAllPlugins */ public function testGetAllPlugins() { $pluginService = $this->getPluginService(); $plugins = $pluginService->getAllPlugins(); $this->assertEquals(2, count($plugins)); $plugin0 = $plugins['my/wonderful/plugin/title']; $plugin1 = $plugins['my/wonderful/plugin/text']; $this->assertInstanceOf(PluginModule::class, $plugin0); $this->assertInstanceOf(PluginModule::class, $plugin1); $this->assertEquals('title', $plugin0->getId()); $this->assertEquals('text', $plugin1->getId()); $this->assertEquals('Wonderful Title', $plugin0->getName()); $this->assertEquals('Wonderful Text', $plugin1->getName()); $this->assertEquals(1, $plugin0->getPosition()); $this->assertEquals(2, $plugin1->getPosition()); $this->assertTrue($plugin0->isActive()); $this->assertTrue($plugin1->isActive()); } /** * Test the method AbstractPluginService::getPlugin */ public function testGetOnePlugin() { $pluginService = $this->getPluginService(); $plugin = $pluginService->getPlugin('text'); $this->assertInstanceOf(PluginModule::class, $plugin); $this->assertEquals('text', $plugin->getId()); $this->assertEquals('Wonderful Text', $plugin->getName()); $this->assertEquals(2, $plugin->getPosition()); $this->assertEquals('my/wonderful/plugin/text', $plugin->getModule()); $this->assertEquals('content', $plugin->getCategory()); $this->assertTrue($plugin->isActive()); } }