Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feature flag for xml editor #2418

Merged
merged 13 commits into from
Dec 6, 2023
12 changes: 9 additions & 3 deletions models/classes/xmlEditor/XmlEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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;
}

Expand Down
59 changes: 48 additions & 11 deletions test/unit/models/classes/xml/XmlEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -92,10 +92,14 @@ public function testSaveStringTest()
// phpcs:disable Generic.Files.LineLength
$xmlMock = <<<'EOL'
<?xml version="1.0" encoding="UTF-8"?>
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" identifier="UnitTestQtiItem" title="UnitTestQtiItem" toolName="tao" toolVersion="3.4.0-sprint130" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd">
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
identifier="UnitTestQtiItem" title="UnitTestQtiItem" toolName="tao" toolVersion="3.4.0-sprint130"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd">
<testPart identifier="testPart-1" navigationMode="linear" submissionMode="individual">
<itemSessionControl maxAttempts="0" showFeedback="false" allowReview="true" showSolution="false" allowComment="false" allowSkipping="true" validateResponses="false"/>
<assessmentSection identifier="assessmentSection-1" required="true" fixed="false" title="Section 1" visible="true" keepTogether="true"/>
<itemSessionControl maxAttempts="0" showFeedback="false" allowReview="true" showSolution="false"
allowComment="false" allowSkipping="true" validateResponses="false"/>
<assessmentSection identifier="assessmentSection-1" required="true" fixed="false" title="Section 1"
visible="true" keepTogether="true"/>
</testPart>
</assessmentTest>
EOL;
Expand Down Expand Up @@ -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
],
];
}
}
Loading