diff --git a/models/classes/xmlEditor/XmlEditor.php b/models/classes/xmlEditor/XmlEditor.php index b925a8e19..69862ecce 100644 --- a/models/classes/xmlEditor/XmlEditor.php +++ b/models/classes/xmlEditor/XmlEditor.php @@ -22,15 +22,18 @@ namespace oat\taoQtiTest\models\xmlEditor; +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; -use core_kernel_classes_Resource; 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'; + /** @var @deprecated */ + private const LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED = 'XML_EDITOR_ENABLED'; + /** * {@inheritdoc} */ @@ -56,7 +59,10 @@ 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) + || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED) + ) { return false; } diff --git a/test/unit/models/classes/xml/XmlEditorTest.php b/test/unit/models/classes/xml/XmlEditorTest.php index bd00d89d9..e50757395 100644 --- a/test/unit/models/classes/xml/XmlEditorTest.php +++ b/test/unit/models/classes/xml/XmlEditorTest.php @@ -20,14 +20,16 @@ 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 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; @@ -57,13 +59,11 @@ public function setUp(): void $this->xmlDoc = $doc; $this->testResourceMock = $this->createMock(core_kernel_classes_Resource::class); - $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([ @@ -92,10 +92,14 @@ public function testSaveStringTest() // phpcs:disable Generic.Files.LineLength $xmlMock = <<<'EOL' - + - - + + EOL; @@ -168,16 +172,49 @@ public function testSaveStringTest() $service->saveStringTest($this->testResourceMock, $xmlMock); } - public function testIsLocked() + /** + * @dataProvider getFeatureIsLockedData + */ + public function testIsLocked($configFlag, $newFeatureFlag, $legacyFeatureFlag, $expectedLock) { - $service = new XmlEditor([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); + $service = new XmlEditor([XmlEditor::OPTION_XML_EDITOR_LOCK => $configFlag]); $service->setServiceLocator($this->serviceLocatorMock); $this->featureFlagCheckerMock ->method('isEnabled') - ->with('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, $service->isLocked()); + public function getFeatureIsLockedData(): array + { + return [ + 'unlocked by config' => [ + false, + false, + false, + false + ], + 'unlocked by new feature flag' => [ + true, + true, + false, + false + ], + 'unlocked by legacy feature flag' => [ + true, + false, + true, + false + ], + 'locked' => [ + true, + false, + false, + true + ], + ]; } }