*/ class TestPluginServiceTest extends TestCase { //data to stub the regsitry content private static $pluginData = [ 'taoQtiTest/runner/plugins/controls/title/title' => [ 'id' => 'title', 'module' => 'taoQtiTest/runner/plugins/controls/title/title', 'bundle' => 'plugins/bundle.min', 'position' => 1, 'name' => 'Title indicator', 'description' => 'Display the title of current test element', 'category' => 'controls', 'active' => true, 'tags' => ['core', 'qti' ] ], 'taoQtiTest/runner/plugins/controls/timer/timer' => [ 'id' => 'timer', 'module' => 'taoQtiTest/runner/plugins/controls/timer/timer', 'bundle' => 'plugins/bundle.min', 'position' => 2, 'name' => 'Timer indicator', 'description' => 'Add countdown when remaining time', 'category' => 'controls', 'active' => true, 'tags' => ['core' ] ] ]; /** * Get the service with the stubbed registry * @return TestPluginService */ protected function getTestPluginService() { $testPluginService = new TestPluginService(); $prophet = new Prophet(); $prophecy = $prophet->prophesize(); $prophecy->willExtend(PluginRegistry::class); $prophecy->getMap()->willReturn(self::$pluginData); $testPluginService->setRegistry($prophecy->reveal()); return $testPluginService; } /** * Check the service is a service */ public function testApi() { $testPluginService = $this->getTestPluginService(); $this->assertInstanceOf(TestPluginService::class, $testPluginService); $this->assertInstanceOf(ConfigurableService::class, $testPluginService); } /** * Test the method TestPluginService::getAllPlugins */ public function testGetAllPlugins() { $testPluginService = $this->getTestPluginService(); $plugins = $testPluginService->getAllPlugins(); $this->assertEquals(2, count($plugins)); $plugin0 = $plugins['taoQtiTest/runner/plugins/controls/title/title']; $plugin1 = $plugins['taoQtiTest/runner/plugins/controls/timer/timer']; $this->assertInstanceOf(TestPlugin::class, $plugin0); $this->assertInstanceOf(TestPlugin::class, $plugin1); $this->assertEquals('title', $plugin0->getId()); $this->assertEquals('timer', $plugin1->getId()); $this->assertEquals('Title indicator', $plugin0->getName()); $this->assertEquals('Timer indicator', $plugin1->getName()); $this->assertEquals(1, $plugin0->getPosition()); $this->assertEquals(2, $plugin1->getPosition()); $this->assertTrue($plugin0->isActive()); $this->assertTrue($plugin1->isActive()); } /** * Test the method TestPluginService::getPlugin */ public function testGetOnePlugin() { $testPluginService = $this->getTestPluginService(); $plugin = $testPluginService->getPlugin('timer'); $this->assertInstanceOf(TestPlugin::class, $plugin); $this->assertEquals('timer', $plugin->getId()); $this->assertEquals('Timer indicator', $plugin->getName()); $this->assertEquals(2, $plugin->getPosition()); $this->assertEquals('taoQtiTest/runner/plugins/controls/timer/timer', $plugin->getModule()); $this->assertEquals('controls', $plugin->getCategory()); $this->assertTrue($plugin->isActive()); } }