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 1 commit
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
18 changes: 9 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,24 @@ 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,
]);

if ($this->featureFlagChecker->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shpran I wonder if we really need this if here now? If we are creating a translation, it may be useful to for them to have always the same TaoOntology::PROPERTY_UNIQUE_IDENTIFIER?

I know this is only needed for HKDir for the moment, but I do not see why restrict is as default behavior.

  • I know it was previous rule in place, but better thinking about it, we may remove this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If for us it's not a problem if we are going to set this property every time - I will remove this condition 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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 @@ -65,32 +65,79 @@ protected function setUp(): void
public function testUniqueIdFeatureDisabled(): void
{
$this->featureFlagChecker
->expects($this->once())
->expects($this->exactly(2))
->method('isEnabled')
->with('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')
->willReturn(false);
->withConsecutive(
['FEATURE_FLAG_TRANSLATION_ENABLED'],
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER']
)
->willReturnOnConsecutiveCalls(true, false);

$originalResourceUriProperty = $this->createPropertyMock();
$uniqueIdProperty = $this->createPropertyMock();

$this->ontology
->expects($this->exactly(2))
->method('getProperty')
->withConsecutive(
[TaoOntology::PROPERTY_TRANSLATION_ORIGINAL_RESOURCE_URI],
[TaoOntology::PROPERTY_UNIQUE_IDENTIFIER]
)
->willReturnOnConsecutiveCalls(
$originalResourceUriProperty,
$uniqueIdProperty
);

$this->resource
->expects($this->once())
->method('getOnePropertyValue')
->with($originalResourceUriProperty)
->willReturn('originalResourceUri');

$originalResource = $this->createResourceMock();

$this->ontology
->expects($this->once())
->method('getResource')
->with('originalResourceUri')
->willReturn($originalResource);

$identifier = $this->createMock(core_kernel_classes_Literal::class);
$identifier->literal = 'identifier';

$originalResource
->expects($this->once())
->method('getOnePropertyValue')
->with($uniqueIdProperty)
->willReturn($identifier);

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

$this->resource
->expects($this->once())
->method('getRootId')
->willReturn('resourceType');

$this->qtiIdentifierSetter
->expects($this->never())
->method('set');
->expects($this->once())
->method('set')
->with([
AbstractQtiIdentifierSetter::OPTION_RESOURCE => $this->resource,
AbstractQtiIdentifierSetter::OPTION_IDENTIFIER => 'identifier',
]);

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

public function testTranslationFeatureDisabled(): 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, false);
->with('FEATURE_FLAG_TRANSLATION_ENABLED')
->willReturn(false);

$this->resource
->expects($this->never())
Expand All @@ -106,13 +153,10 @@ public function testTranslationFeatureDisabled(): void
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 +186,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 +240,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 +284,7 @@ public function testNoQtiIdentifierSetterForSpecifiedType(): void
->willReturn($identifier);

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

Expand All @@ -271,8 +309,8 @@ public function testSuccess(): void
->expects($this->exactly(2))
->method('isEnabled')
->withConsecutive(
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER'],
['FEATURE_FLAG_TRANSLATION_ENABLED']
['FEATURE_FLAG_TRANSLATION_ENABLED'],
['FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER']
)
->willReturnOnConsecutiveCalls(true, true);

Expand Down
Loading