From a4d1d438d8add8dee548f282ab749c8b108e1adc Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 8 Nov 2023 21:08:36 +0200 Subject: [PATCH 01/12] fix: feature flag for xml editor --- models/classes/xmlEditor/XmlEditor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index b925a8e19..289d3bfd3 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -30,7 +30,7 @@ class XmlEditor extends ConfigurableService implements XmlEditorInterface { - private const XML_EDITOR_ENABLED = 'XML_EDITOR_ENABLED'; + private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED'; /** * {@inheritdoc} */ @@ -56,7 +56,7 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS */ public function isLocked(): bool { - if ($this->getFeatureFlagChecker()->isEnabled(self::XML_EDITOR_ENABLED)) { + if ($this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) { return false; } From 6932cbcaf30656318d744209b30dc814c26849b6 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 8 Nov 2023 22:46:51 +0200 Subject: [PATCH 02/12] fix: feature flag for xml editor --- actions/class.XmlEditor.php | 2 +- ...{XmlEditor.conf.php => xmlEditor.conf.php} | 4 +- model/Container/TestQtiServiceProvider.php | 19 +++++++- models/classes/xmlEditor/XmlEditor.php | 46 ++++++++++++------- .../classes/xmlEditor/XmlEditorInterface.php | 1 - 5 files changed, 48 insertions(+), 24 deletions(-) rename config/default/{XmlEditor.conf.php => xmlEditor.conf.php} (92%) diff --git a/actions/class.XmlEditor.php b/actions/class.XmlEditor.php index 3d995bd78..388cf1203 100644 --- a/actions/class.XmlEditor.php +++ b/actions/class.XmlEditor.php @@ -85,6 +85,6 @@ public function edit(): void */ private function getXmlEditorService(): XmlEditorInterface { - return $this->getServiceLocator()->get(XmlEditorInterface::SERVICE_ID); + return $this->getServiceLocator()->getContainer()->get(XmlEditorInterface::class); } } diff --git a/config/default/XmlEditor.conf.php b/config/default/xmlEditor.conf.php similarity index 92% rename from config/default/XmlEditor.conf.php rename to config/default/xmlEditor.conf.php index 9bc04037a..13ee5af7a 100644 --- a/config/default/XmlEditor.conf.php +++ b/config/default/xmlEditor.conf.php @@ -24,6 +24,4 @@ use oat\taoQtiTest\models\xmlEditor\XmlEditor; -return new XmlEditor([ - XmlEditor::OPTION_XML_EDITOR_LOCK => true -]); +return [XmlEditor::OPTION_XML_EDITOR_LOCK => true]; diff --git a/model/Container/TestQtiServiceProvider.php b/model/Container/TestQtiServiceProvider.php index a5e884b83..eca6e3741 100644 --- a/model/Container/TestQtiServiceProvider.php +++ b/model/Container/TestQtiServiceProvider.php @@ -24,17 +24,18 @@ namespace oat\taoQtiTest\model\Container; +use common_ext_ExtensionsManager; use oat\generis\model\data\Ontology; use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; use oat\oatbox\event\EventManager; use oat\oatbox\log\LoggerService; -use oat\taoQtiItem\model\qti\Service; +use oat\tao\model\featureFlag\FeatureFlagChecker; use oat\taoQtiTest\model\Domain\Model\ItemResponseRepositoryInterface; use oat\taoQtiTest\model\Domain\Model\QtiTestRepositoryInterface; use oat\taoQtiTest\model\Domain\Model\ToolsStateRepositoryInterface; use oat\taoQtiTest\model\Infrastructure\QtiItemResponseRepository; -use oat\taoQtiTest\model\Infrastructure\QtiToolsStateRepository; use oat\taoQtiTest\model\Infrastructure\QtiTestRepository; +use oat\taoQtiTest\model\Infrastructure\QtiToolsStateRepository; use oat\taoQtiTest\model\Service\ExitTestService; use oat\taoQtiTest\model\Service\ListItemsService; use oat\taoQtiTest\model\Service\MoveService; @@ -44,7 +45,10 @@ use oat\taoQtiTest\model\Service\TimeoutService; use oat\taoQtiTest\models\runner\QtiRunnerService; use oat\taoQtiTest\models\TestModelService; +use oat\taoQtiTest\models\xmlEditor\XmlEditor; +use oat\taoQtiTest\models\xmlEditor\XmlEditorInterface; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use taoQtiTest_models_classes_QtiTestService; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; @@ -156,5 +160,16 @@ public function __invoke(ContainerConfigurator $configurator): void service(TestModelService::SERVICE_ID), ] ); + + $services + ->set(XmlEditorInterface::class, XmlEditor::class) + ->public() + ->args( + [ + service(common_ext_ExtensionsManager::SERVICE_ID), + service(taoQtiTest_models_classes_QtiTestService::class), + service(FeatureFlagChecker::class), + ] + ); } } diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index 289d3bfd3..fb7fe79d3 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -22,21 +22,43 @@ namespace oat\taoQtiTest\models\xmlEditor; -use oat\oatbox\service\ConfigurableService; +use common_ext_ExtensionsManager; +use core_kernel_classes_Resource; use oat\tao\model\featureFlag\FeatureFlagChecker; use qtism\data\storage\xml\XmlDocument; use taoQtiTest_models_classes_QtiTestService; -use core_kernel_classes_Resource; -class XmlEditor extends ConfigurableService implements XmlEditorInterface +class XmlEditor implements XmlEditorInterface { private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED'; + private const CONFIG = 'xmlEditor'; + + /** @var taoQtiTest_models_classes_QtiTestService */ + private taoQtiTest_models_classes_QtiTestService $qtiTestService; + + /** @var FeatureFlagChecker */ + private FeatureFlagChecker $featureFlagChecker; + + private array $options = []; + + public function __construct( + common_ext_ExtensionsManager $extensionsManager, + taoQtiTest_models_classes_QtiTestService $qtiTestService, + FeatureFlagChecker $featureFlagChecker + ) { + $this->options = $extensionsManager + ->getExtensionById('taoQtiTest') + ->getConfig(self::CONFIG); + $this->qtiTestService = $qtiTestService; + $this->featureFlagChecker = $featureFlagChecker; + } + /** * {@inheritdoc} */ public function getTestXml(core_kernel_classes_Resource $test): string { - return $this->getTestService()->getDoc($test)->saveToString(); + return $this->qtiTestService->getDoc($test)->saveToString(); } /** @@ -48,7 +70,7 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS $doc->loadFromString($testString, true); $converter = new \taoQtiTest_models_classes_QtiTestConverter($doc); - return $this->getTestService()->saveJsonTest($test, $converter->toJson()); + return $this->qtiTestService->saveJsonTest($test, $converter->toJson()); } /** @@ -56,20 +78,10 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS */ public function isLocked(): bool { - if ($this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) { + if ($this->featureFlagChecker->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) { return false; } - return $this->hasOption('is_locked') ? (bool)$this->getOption('is_locked') : true; - } - - private function getTestService(): taoQtiTest_models_classes_QtiTestService - { - return $this->getServiceLocator()->get(taoQtiTest_models_classes_QtiTestService::class); - } - - private function getFeatureFlagChecker(): FeatureFlagChecker - { - return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class); + return isset($this->options['is_locked']) ? (bool)$this->options['is_locked'] : true; } } diff --git a/models/classes/xmlEditor/XmlEditorInterface.php b/models/classes/xmlEditor/XmlEditorInterface.php index b6e929456..23a593061 100644 --- a/models/classes/xmlEditor/XmlEditorInterface.php +++ b/models/classes/xmlEditor/XmlEditorInterface.php @@ -26,7 +26,6 @@ interface XmlEditorInterface { - public const SERVICE_ID = 'taoQtiTest/XmlEditor'; public const XML_EDITOR_ROLE = 'http://www.tao.lu/Ontologies/generis.rdf#TestXMLEditor'; public const OPTION_XML_EDITOR_LOCK = 'is_locked'; From 04a5e89054b1fac29d00fa14a65dc8a6bf0bf952 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Thu, 9 Nov 2023 09:04:37 +0200 Subject: [PATCH 03/12] fix: feature flag for xml editor --- config/default/xmlEditor.conf.php | 2 - .../unit/models/classes/xml/XmlEditorTest.php | 79 +++++++++++++------ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/config/default/xmlEditor.conf.php b/config/default/xmlEditor.conf.php index 13ee5af7a..6ae74cd75 100644 --- a/config/default/xmlEditor.conf.php +++ b/config/default/xmlEditor.conf.php @@ -20,8 +20,6 @@ * */ -declare(strict_types=1); - use oat\taoQtiTest\models\xmlEditor\XmlEditor; return [XmlEditor::OPTION_XML_EDITOR_LOCK => true]; diff --git a/test/unit/models/classes/xml/XmlEditorTest.php b/test/unit/models/classes/xml/XmlEditorTest.php index bd00d89d9..723b84633 100644 --- a/test/unit/models/classes/xml/XmlEditorTest.php +++ b/test/unit/models/classes/xml/XmlEditorTest.php @@ -20,11 +20,13 @@ namespace oat\taoQtiTest\test\unit\models\classes\xml; +use common_ext_Extension; +use common_ext_ExtensionsManager; use core_kernel_classes_Resource; -use oat\generis\test\TestCase; use oat\tao\model\featureFlag\FeatureFlagChecker; use oat\taoQtiTest\models\xmlEditor\XmlEditor; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase as UnitTestCase; use qtism\data\storage\xml\XmlDocument; use qtism\data\storage\xml\XmlStorageException; use SplObjectStorage; @@ -33,7 +35,7 @@ use taoQtiTest_models_classes_QtiTestServiceException; use Zend\ServiceManager\ServiceLocatorInterface; -class XmlEditorTest extends TestCase +class XmlEditorTest extends UnitTestCase { /** @var XmlDocument */ private $xmlDoc; @@ -41,8 +43,11 @@ class XmlEditorTest extends TestCase /** @var core_kernel_classes_Resource|MockObject */ private $testResourceMock; - /** @var ServiceLocatorInterface */ - private $serviceLocatorMock; + /** @var common_ext_ExtensionsManager|MockObject */ + private $extensionsManagerMock; + + /** @var common_ext_Extension|MockObject */ + private $extensionMock; /** @var taoQtiTest_models_classes_QtiTestService|MockObject */ private $qtiTestServiceMock; @@ -57,26 +62,34 @@ public function setUp(): void $this->xmlDoc = $doc; $this->testResourceMock = $this->createMock(core_kernel_classes_Resource::class); - + $this->extensionMock = $this->createMock(common_ext_Extension::class); + $this->extensionsManagerMock = $this->createMock(common_ext_ExtensionsManager::class); + $this->extensionsManagerMock + ->expects(self::once()) + ->method('getExtensionById') + ->with('taoQtiTest') + ->willReturn($this->extensionMock); $this->qtiTestServiceMock = $this->createMock(taoQtiTest_models_classes_QtiTestService::class); $this->qtiTestServiceMock ->method('getDoc') ->with($this->testResourceMock) ->willReturn($this->xmlDoc); - $this->featureFlagCheckerMock = $this->createMock(FeatureFlagChecker::class); - - $this->serviceLocatorMock = $this->getServiceLocatorMock([ - taoQtiTest_models_classes_QtiTestService::class => $this->qtiTestServiceMock, - FeatureFlagChecker::class => $this->featureFlagCheckerMock, - ]); } public function testGetTestXml() { - $service = new XmlEditor(); - $service->setServiceLocator($this->serviceLocatorMock); - $xmlString = $service->getTestXml($this->testResourceMock); + $this->extensionMock + ->expects(self::once()) + ->method('getConfig') + ->with('xmlEditor') + ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); + + $serviceXmlEditor = new XmlEditor( + $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + ); + + $xmlString = $serviceXmlEditor->getTestXml($this->testResourceMock); $this->assertEquals($this->xmlDoc->saveToString(), $xmlString); } @@ -87,15 +100,27 @@ public function testGetTestXml() */ public function testSaveStringTest() { - $service = new XmlEditor(); + $this->extensionMock + ->expects(self::once()) + ->method('getConfig') + ->with('xmlEditor') + ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); + + $serviceXmlEditor = new XmlEditor( + $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + ); // phpcs:disable Generic.Files.LineLength $xmlMock = <<<'EOL' - + - - + + EOL; @@ -164,20 +189,26 @@ public function testSaveStringTest() ->method('saveJsonTest') ->with($this->testResourceMock, json_encode($expectArrayTest)); - $service->setServiceLocator($this->serviceLocatorMock); - $service->saveStringTest($this->testResourceMock, $xmlMock); + $serviceXmlEditor->saveStringTest($this->testResourceMock, $xmlMock); } public function testIsLocked() { - $service = new XmlEditor([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); - $service->setServiceLocator($this->serviceLocatorMock); + $this->extensionMock + ->expects(self::once()) + ->method('getConfig') + ->with('xmlEditor') + ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); + + $serviceXmlEditor = new XmlEditor( + $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + ); $this->featureFlagCheckerMock ->method('isEnabled') - ->with('XML_EDITOR_ENABLED') + ->with('FEATURE_FLAG_XML_EDITOR_ENABLED') ->willReturn(true); - $this->assertEquals(false, $service->isLocked()); + $this->assertEquals(false, $serviceXmlEditor->isLocked()); } } From 265665e52000ac99c6f3e04e4fada4e2b3ad6e5d Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Thu, 9 Nov 2023 11:24:44 +0200 Subject: [PATCH 04/12] fix: feature flag for xml editor --- test/unit/models/classes/xml/XmlEditorTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/unit/models/classes/xml/XmlEditorTest.php b/test/unit/models/classes/xml/XmlEditorTest.php index 723b84633..d755826ca 100644 --- a/test/unit/models/classes/xml/XmlEditorTest.php +++ b/test/unit/models/classes/xml/XmlEditorTest.php @@ -86,7 +86,9 @@ public function testGetTestXml() ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + $this->extensionsManagerMock, + $this->qtiTestServiceMock, + $this->featureFlagCheckerMock ); $xmlString = $serviceXmlEditor->getTestXml($this->testResourceMock); @@ -107,7 +109,9 @@ public function testSaveStringTest() ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + $this->extensionsManagerMock, + $this->qtiTestServiceMock, + $this->featureFlagCheckerMock ); // phpcs:disable Generic.Files.LineLength @@ -201,7 +205,9 @@ public function testIsLocked() ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, $this->qtiTestServiceMock, $this->featureFlagCheckerMock + $this->extensionsManagerMock, + $this->qtiTestServiceMock, + $this->featureFlagCheckerMock ); $this->featureFlagCheckerMock From 285ad052647a6e1157aa35b34ff96aa80e387cb7 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 29 Nov 2023 15:39:58 +0200 Subject: [PATCH 05/12] fix: feature flag for xml editor --- .../Version202311291155452260_taoQtiTest.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 migrations/Version202311291155452260_taoQtiTest.php diff --git a/migrations/Version202311291155452260_taoQtiTest.php b/migrations/Version202311291155452260_taoQtiTest.php new file mode 100644 index 000000000..c80552c61 --- /dev/null +++ b/migrations/Version202311291155452260_taoQtiTest.php @@ -0,0 +1,63 @@ +getExtension(); + $extension->unsetConfig($oldXmlConfigKey); + $extension->setConfig($newXmlConfigKey, ['is_locked' => true]); + } + + public function down(Schema $schema): void + { + $oldXmlConfigKey = 'XmlEditor'; + $newXmlConfigKey = 'xmlEditor'; + $extension = $this->getExtension(); + $extension->unsetConfig($newXmlConfigKey); + $extension->setConfig($oldXmlConfigKey, ['is_locked' => false]); + } + + private function getExtension(): Extension + { + return $this->getServiceLocator() + ->getContainer() + ->get(ExtensionsManager::SERVICE_ID) + ->getExtensionById('taoQtiTest'); + } +} From 9d197c69dbceffb81080d93deb57b07eb9d21f67 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 29 Nov 2023 15:48:04 +0200 Subject: [PATCH 06/12] fix: feature flag for xml editor --- migrations/Version202311291155452260_taoQtiTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/migrations/Version202311291155452260_taoQtiTest.php b/migrations/Version202311291155452260_taoQtiTest.php index c80552c61..1158bd035 100644 --- a/migrations/Version202311291155452260_taoQtiTest.php +++ b/migrations/Version202311291155452260_taoQtiTest.php @@ -23,7 +23,6 @@ namespace oat\taoQtiTest\migrations; use common_ext_Extension as Extension; -use common_ext_ExtensionException as ExtensionException; use common_ext_ExtensionsManager as ExtensionsManager; use Doctrine\DBAL\Schema\Schema; use oat\tao\scripts\tools\migrations\AbstractMigration; From e6960173f54dbe45d8c18e5e15e25ec8ffb6823c Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 29 Nov 2023 17:29:34 +0200 Subject: [PATCH 07/12] fix: feature flag for xml editor --- migrations/Version202311291155452260_taoQtiTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migrations/Version202311291155452260_taoQtiTest.php b/migrations/Version202311291155452260_taoQtiTest.php index 1158bd035..59bc0c51b 100644 --- a/migrations/Version202311291155452260_taoQtiTest.php +++ b/migrations/Version202311291155452260_taoQtiTest.php @@ -45,11 +45,7 @@ public function up(Schema $schema): void public function down(Schema $schema): void { - $oldXmlConfigKey = 'XmlEditor'; - $newXmlConfigKey = 'xmlEditor'; - $extension = $this->getExtension(); - $extension->unsetConfig($newXmlConfigKey); - $extension->setConfig($oldXmlConfigKey, ['is_locked' => false]); + $this->throwIrreversibleMigrationException(); } private function getExtension(): Extension From ee2058575d4621c6fe1dfba2cceab140aca8b070 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 1 Dec 2023 23:20:20 +0200 Subject: [PATCH 08/12] fix: feature flag for xml editor --- actions/class.XmlEditor.php | 2 +- ...{xmlEditor.conf.php => XmlEditor.conf.php} | 6 +- .../Version202311291155452260_taoQtiTest.php | 58 ---------- model/Container/TestQtiServiceProvider.php | 16 --- models/classes/xmlEditor/XmlEditor.php | 46 +++----- .../classes/xmlEditor/XmlEditorInterface.php | 1 + .../unit/models/classes/xml/XmlEditorTest.php | 108 +++++++++--------- 7 files changed, 80 insertions(+), 157 deletions(-) rename config/default/{xmlEditor.conf.php => XmlEditor.conf.php} (89%) delete mode 100644 migrations/Version202311291155452260_taoQtiTest.php diff --git a/actions/class.XmlEditor.php b/actions/class.XmlEditor.php index 388cf1203..3d995bd78 100644 --- a/actions/class.XmlEditor.php +++ b/actions/class.XmlEditor.php @@ -85,6 +85,6 @@ public function edit(): void */ private function getXmlEditorService(): XmlEditorInterface { - return $this->getServiceLocator()->getContainer()->get(XmlEditorInterface::class); + return $this->getServiceLocator()->get(XmlEditorInterface::SERVICE_ID); } } diff --git a/config/default/xmlEditor.conf.php b/config/default/XmlEditor.conf.php similarity index 89% rename from config/default/xmlEditor.conf.php rename to config/default/XmlEditor.conf.php index 6ae74cd75..c9b0c0c5e 100644 --- a/config/default/xmlEditor.conf.php +++ b/config/default/XmlEditor.conf.php @@ -20,6 +20,10 @@ * */ +declare(strict_types=1); + use oat\taoQtiTest\models\xmlEditor\XmlEditor; -return [XmlEditor::OPTION_XML_EDITOR_LOCK => true]; +return new XmlEditor([ + XmlEditor::OPTION_XML_EDITOR_LOCK => true +]); \ No newline at end of file diff --git a/migrations/Version202311291155452260_taoQtiTest.php b/migrations/Version202311291155452260_taoQtiTest.php deleted file mode 100644 index 59bc0c51b..000000000 --- a/migrations/Version202311291155452260_taoQtiTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getExtension(); - $extension->unsetConfig($oldXmlConfigKey); - $extension->setConfig($newXmlConfigKey, ['is_locked' => true]); - } - - public function down(Schema $schema): void - { - $this->throwIrreversibleMigrationException(); - } - - private function getExtension(): Extension - { - return $this->getServiceLocator() - ->getContainer() - ->get(ExtensionsManager::SERVICE_ID) - ->getExtensionById('taoQtiTest'); - } -} diff --git a/model/Container/TestQtiServiceProvider.php b/model/Container/TestQtiServiceProvider.php index eca6e3741..277b174e2 100644 --- a/model/Container/TestQtiServiceProvider.php +++ b/model/Container/TestQtiServiceProvider.php @@ -24,12 +24,10 @@ namespace oat\taoQtiTest\model\Container; -use common_ext_ExtensionsManager; use oat\generis\model\data\Ontology; use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; use oat\oatbox\event\EventManager; use oat\oatbox\log\LoggerService; -use oat\tao\model\featureFlag\FeatureFlagChecker; use oat\taoQtiTest\model\Domain\Model\ItemResponseRepositoryInterface; use oat\taoQtiTest\model\Domain\Model\QtiTestRepositoryInterface; use oat\taoQtiTest\model\Domain\Model\ToolsStateRepositoryInterface; @@ -45,10 +43,7 @@ use oat\taoQtiTest\model\Service\TimeoutService; use oat\taoQtiTest\models\runner\QtiRunnerService; use oat\taoQtiTest\models\TestModelService; -use oat\taoQtiTest\models\xmlEditor\XmlEditor; -use oat\taoQtiTest\models\xmlEditor\XmlEditorInterface; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use taoQtiTest_models_classes_QtiTestService; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; @@ -160,16 +155,5 @@ public function __invoke(ContainerConfigurator $configurator): void service(TestModelService::SERVICE_ID), ] ); - - $services - ->set(XmlEditorInterface::class, XmlEditor::class) - ->public() - ->args( - [ - service(common_ext_ExtensionsManager::SERVICE_ID), - service(taoQtiTest_models_classes_QtiTestService::class), - service(FeatureFlagChecker::class), - ] - ); } } diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index fb7fe79d3..a69bcaf50 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -22,43 +22,24 @@ namespace oat\taoQtiTest\models\xmlEditor; -use common_ext_ExtensionsManager; use core_kernel_classes_Resource; +use oat\oatbox\service\ConfigurableService; use oat\tao\model\featureFlag\FeatureFlagChecker; use qtism\data\storage\xml\XmlDocument; use taoQtiTest_models_classes_QtiTestService; -class XmlEditor implements XmlEditorInterface +class XmlEditor extends ConfigurableService implements XmlEditorInterface { private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED'; - private const CONFIG = 'xmlEditor'; - - /** @var taoQtiTest_models_classes_QtiTestService */ - private taoQtiTest_models_classes_QtiTestService $qtiTestService; - - /** @var FeatureFlagChecker */ - private FeatureFlagChecker $featureFlagChecker; - - private array $options = []; - - public function __construct( - common_ext_ExtensionsManager $extensionsManager, - taoQtiTest_models_classes_QtiTestService $qtiTestService, - FeatureFlagChecker $featureFlagChecker - ) { - $this->options = $extensionsManager - ->getExtensionById('taoQtiTest') - ->getConfig(self::CONFIG); - $this->qtiTestService = $qtiTestService; - $this->featureFlagChecker = $featureFlagChecker; - } + /** @var @depricated */ + private const LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED = 'XML_EDITOR_ENABLED'; /** * {@inheritdoc} */ public function getTestXml(core_kernel_classes_Resource $test): string { - return $this->qtiTestService->getDoc($test)->saveToString(); + return $this->getTestService()->getDoc($test)->saveToString(); } /** @@ -70,7 +51,7 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS $doc->loadFromString($testString, true); $converter = new \taoQtiTest_models_classes_QtiTestConverter($doc); - return $this->qtiTestService->saveJsonTest($test, $converter->toJson()); + return $this->getTestService()->saveJsonTest($test, $converter->toJson()); } /** @@ -78,10 +59,21 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS */ public function isLocked(): bool { - if ($this->featureFlagChecker->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) { + if ($this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED) + || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED)) { return false; } - return isset($this->options['is_locked']) ? (bool)$this->options['is_locked'] : true; + return $this->hasOption('is_locked') ? (bool)$this->getOption('is_locked') : true; + } + + private function getTestService(): taoQtiTest_models_classes_QtiTestService + { + return $this->getServiceLocator()->get(taoQtiTest_models_classes_QtiTestService::class); + } + + private function getFeatureFlagChecker(): FeatureFlagChecker + { + return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class); } } diff --git a/models/classes/xmlEditor/XmlEditorInterface.php b/models/classes/xmlEditor/XmlEditorInterface.php index 23a593061..b6e929456 100644 --- a/models/classes/xmlEditor/XmlEditorInterface.php +++ b/models/classes/xmlEditor/XmlEditorInterface.php @@ -26,6 +26,7 @@ interface XmlEditorInterface { + public const SERVICE_ID = 'taoQtiTest/XmlEditor'; public const XML_EDITOR_ROLE = 'http://www.tao.lu/Ontologies/generis.rdf#TestXMLEditor'; public const OPTION_XML_EDITOR_LOCK = 'is_locked'; diff --git a/test/unit/models/classes/xml/XmlEditorTest.php b/test/unit/models/classes/xml/XmlEditorTest.php index d755826ca..0a3eca749 100644 --- a/test/unit/models/classes/xml/XmlEditorTest.php +++ b/test/unit/models/classes/xml/XmlEditorTest.php @@ -26,16 +26,16 @@ use oat\tao\model\featureFlag\FeatureFlagChecker; use oat\taoQtiTest\models\xmlEditor\XmlEditor; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase as UnitTestCase; use qtism\data\storage\xml\XmlDocument; use qtism\data\storage\xml\XmlStorageException; use SplObjectStorage; +use oat\generis\test\TestCase; use taoQtiTest_models_classes_QtiTestConverterException; use taoQtiTest_models_classes_QtiTestService; use taoQtiTest_models_classes_QtiTestServiceException; use Zend\ServiceManager\ServiceLocatorInterface; -class XmlEditorTest extends UnitTestCase +class XmlEditorTest extends TestCase { /** @var XmlDocument */ private $xmlDoc; @@ -43,11 +43,8 @@ class XmlEditorTest extends UnitTestCase /** @var core_kernel_classes_Resource|MockObject */ private $testResourceMock; - /** @var common_ext_ExtensionsManager|MockObject */ - private $extensionsManagerMock; - - /** @var common_ext_Extension|MockObject */ - private $extensionMock; + /** @var ServiceLocatorInterface */ + private $serviceLocatorMock; /** @var taoQtiTest_models_classes_QtiTestService|MockObject */ private $qtiTestServiceMock; @@ -62,36 +59,24 @@ public function setUp(): void $this->xmlDoc = $doc; $this->testResourceMock = $this->createMock(core_kernel_classes_Resource::class); - $this->extensionMock = $this->createMock(common_ext_Extension::class); - $this->extensionsManagerMock = $this->createMock(common_ext_ExtensionsManager::class); - $this->extensionsManagerMock - ->expects(self::once()) - ->method('getExtensionById') - ->with('taoQtiTest') - ->willReturn($this->extensionMock); $this->qtiTestServiceMock = $this->createMock(taoQtiTest_models_classes_QtiTestService::class); $this->qtiTestServiceMock ->method('getDoc') ->with($this->testResourceMock) ->willReturn($this->xmlDoc); $this->featureFlagCheckerMock = $this->createMock(FeatureFlagChecker::class); + + $this->serviceLocatorMock = $this->getServiceLocatorMock([ + taoQtiTest_models_classes_QtiTestService::class => $this->qtiTestServiceMock, + FeatureFlagChecker::class => $this->featureFlagCheckerMock, + ]); } public function testGetTestXml() { - $this->extensionMock - ->expects(self::once()) - ->method('getConfig') - ->with('xmlEditor') - ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); - - $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, - $this->qtiTestServiceMock, - $this->featureFlagCheckerMock - ); - - $xmlString = $serviceXmlEditor->getTestXml($this->testResourceMock); + $service = new XmlEditor(); + $service->setServiceLocator($this->serviceLocatorMock); + $xmlString = $service->getTestXml($this->testResourceMock); $this->assertEquals($this->xmlDoc->saveToString(), $xmlString); } @@ -102,17 +87,7 @@ public function testGetTestXml() */ public function testSaveStringTest() { - $this->extensionMock - ->expects(self::once()) - ->method('getConfig') - ->with('xmlEditor') - ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => true]); - - $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, - $this->qtiTestServiceMock, - $this->featureFlagCheckerMock - ); + $service = new XmlEditor(); // phpcs:disable Generic.Files.LineLength $xmlMock = <<<'EOL' @@ -193,28 +168,53 @@ public function testSaveStringTest() ->method('saveJsonTest') ->with($this->testResourceMock, json_encode($expectArrayTest)); - $serviceXmlEditor->saveStringTest($this->testResourceMock, $xmlMock); + $service->setServiceLocator($this->serviceLocatorMock); + $service->saveStringTest($this->testResourceMock, $xmlMock); } - public function testIsLocked() + /** + * @dataProvider getFeatureIsLockedData + */ + public function testIsLocked($configFlag, $newFeatureFlag, $legacyFeatureFlag, $expectedLock) { - $this->extensionMock - ->expects(self::once()) - ->method('getConfig') - ->with('xmlEditor') - ->willReturn([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); - - $serviceXmlEditor = new XmlEditor( - $this->extensionsManagerMock, - $this->qtiTestServiceMock, - $this->featureFlagCheckerMock - ); + $service = new XmlEditor([XmlEditor::OPTION_XML_EDITOR_LOCK => $configFlag]); + $service->setServiceLocator($this->serviceLocatorMock); $this->featureFlagCheckerMock ->method('isEnabled') - ->with('FEATURE_FLAG_XML_EDITOR_ENABLED') - ->willReturn(true); + ->withConsecutive(['FEATURE_FLAG_XML_EDITOR_ENABLED'], ['XML_EDITOR_ENABLED']) + ->willReturnOnConsecutiveCalls($newFeatureFlag, $legacyFeatureFlag); + + $this->assertEquals($expectedLock, $service->isLocked()); + } - $this->assertEquals(false, $serviceXmlEditor->isLocked()); + public function getFeatureIsLockedData(): array + { + return [ + 'unlocked by config' => [ + true, + false, + false, + false + ], + 'unlocked by new feature flag' => [ + false, + true, + false, + false + ], + 'unlocked by legacy feature flag' => [ + false, + false, + true, + false + ], + 'locked' => [ + false, + false, + false, + true + ], + ]; } } From 9af43174d0ddaba1807c33a7252992fd989ecd6a Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Tue, 5 Dec 2023 11:27:56 +0200 Subject: [PATCH 09/12] fix: feature flag for xml editor --- test/unit/models/classes/xml/XmlEditorTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/models/classes/xml/XmlEditorTest.php b/test/unit/models/classes/xml/XmlEditorTest.php index 0a3eca749..e50757395 100644 --- a/test/unit/models/classes/xml/XmlEditorTest.php +++ b/test/unit/models/classes/xml/XmlEditorTest.php @@ -192,25 +192,25 @@ public function getFeatureIsLockedData(): array { return [ 'unlocked by config' => [ - true, + false, false, false, false ], 'unlocked by new feature flag' => [ - false, + true, true, false, false ], 'unlocked by legacy feature flag' => [ - false, + true, false, true, false ], 'locked' => [ - false, + true, false, false, true From 3e1db0b72f40cfdd61c84dee5991984bf3432fcf Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Tue, 5 Dec 2023 11:42:03 +0200 Subject: [PATCH 10/12] fix: feature flag for xml editor --- config/default/XmlEditor.conf.php | 2 +- models/classes/xmlEditor/XmlEditor.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/default/XmlEditor.conf.php b/config/default/XmlEditor.conf.php index c9b0c0c5e..9bc04037a 100644 --- a/config/default/XmlEditor.conf.php +++ b/config/default/XmlEditor.conf.php @@ -26,4 +26,4 @@ return new XmlEditor([ XmlEditor::OPTION_XML_EDITOR_LOCK => true -]); \ No newline at end of file +]); diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index a69bcaf50..51e9aa659 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -59,8 +59,10 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS */ public function isLocked(): bool { - if ($this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED) - || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED)) { + if ( + $this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED) + || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED)) + { return false; } From ecb403f74587e5b795d093ca6fae592dd338dd59 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Tue, 5 Dec 2023 11:45:01 +0200 Subject: [PATCH 11/12] fix: feature flag for xml editor --- models/classes/xmlEditor/XmlEditor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index 51e9aa659..a39399b65 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -61,8 +61,8 @@ public function isLocked(): bool { if ( $this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED) - || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED)) - { + || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED) + ) { return false; } From 178853a95ec17b5108b7dea76c7207a1d7fafc95 Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Wed, 6 Dec 2023 13:26:13 +0100 Subject: [PATCH 12/12] fix: typo --- models/classes/xmlEditor/XmlEditor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index a39399b65..69862ecce 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -31,7 +31,7 @@ class XmlEditor extends ConfigurableService implements XmlEditorInterface { private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED'; - /** @var @depricated */ + /** @var @deprecated */ private const LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED = 'XML_EDITOR_ENABLED'; /**