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] Keep translation QTI ID the same #4206

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions models/classes/Translation/Service/TranslationUniqueIdSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
* Copyright (c) 2024-2025 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);
Expand Down Expand Up @@ -59,24 +59,22 @@ public function addQtiIdentifierSetter(AbstractQtiIdentifierSetter $qtiIdentifie

public function __invoke(core_kernel_classes_Resource $resource): void
{
if (
!$this->featureFlagChecker->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')
|| !$this->featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')
) {
if (!$this->featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')) {
return;
}

$originalResource = $this->getOriginalResource($resource);
$uniqueIdentifier = $this->getUniqueId($originalResource);

$resource->editPropertyValues(
$this->getProperty(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER),
$uniqueIdentifier
);
$this->getQtiIdentifierSetter($resource)->set([
AbstractQtiIdentifierSetter::OPTION_RESOURCE => $resource,
AbstractQtiIdentifierSetter::OPTION_IDENTIFIER => $uniqueIdentifier,
]);

$resource->editPropertyValues(
$this->getProperty(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER),
$uniqueIdentifier
);
}

private function getOriginalResource(core_kernel_classes_Resource $resource): core_kernel_classes_Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
* Copyright (c) 2024-2025 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);
Expand Down Expand Up @@ -62,12 +62,12 @@ protected function setUp(): void
$this->sut->addQtiIdentifierSetter($this->qtiIdentifierSetter, 'resourceType');
}

public function testUniqueIdFeatureDisabled(): void
public function testTranslationFeatureDisabled(): void
{
$this->featureFlagChecker
->expects($this->once())
->method('isEnabled')
->with('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(false);

$this->resource
Expand All @@ -81,38 +81,13 @@ public function testUniqueIdFeatureDisabled(): void
$this->sut->__invoke($this->resource);
}

public function testTranslationFeatureDisabled(): void
{
$this->featureFlagChecker
->expects($this->exactly(2))
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
)
->willReturnOnConsecutiveCalls(true, false);

$this->resource
->expects($this->never())
->method($this->anything());

$this->qtiIdentifierSetter
->expects($this->never())
->method('set');

$this->sut->__invoke($this->resource);
}

public function testNoOriginalResourceUri(): void
{
$this->featureFlagChecker
->expects($this->exactly(2))
->expects($this->once())
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
)
->willReturnOnConsecutiveCalls(true, true);
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(true);

$originalResourceUriProperty = $this->createPropertyMock();

Expand Down Expand Up @@ -142,13 +117,10 @@ public function testNoOriginalResourceUri(): void
public function testNoUniqueId(): void
{
$this->featureFlagChecker
->expects($this->exactly(2))
->expects($this->once())
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
)
->willReturnOnConsecutiveCalls(true, true);
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(true);

$originalResourceUriProperty = $this->createPropertyMock();
$uniqueIdProperty = $this->createPropertyMock();
Expand Down Expand Up @@ -199,13 +171,10 @@ public function testNoUniqueId(): void
public function testNoQtiIdentifierSetterForSpecifiedType(): void
{
$this->featureFlagChecker
->expects($this->exactly(2))
->expects($this->once())
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
)
->willReturnOnConsecutiveCalls(true, true);
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(true);

$originalResourceUriProperty = $this->createPropertyMock();
$uniqueIdProperty = $this->createPropertyMock();
Expand Down Expand Up @@ -246,7 +215,7 @@ public function testNoQtiIdentifierSetterForSpecifiedType(): void
->willReturn($identifier);

$this->resource
->expects($this->once())
->expects($this->never())
->method('editPropertyValues')
->with($uniqueIdProperty, 'identifier');

Expand All @@ -268,13 +237,10 @@ public function testNoQtiIdentifierSetterForSpecifiedType(): void
public function testSuccess(): void
{
$this->featureFlagChecker
->expects($this->exactly(2))
->expects($this->once())
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
)
->willReturnOnConsecutiveCalls(true, true);
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(true);

$originalResourceUriProperty = $this->createPropertyMock();
$uniqueIdProperty = $this->createPropertyMock();
Expand Down
Loading