Skip to content

Commit

Permalink
fix: set QTI ID even if FF disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Mar 3, 2025
1 parent f68f51e commit 2106b60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
15 changes: 7 additions & 8 deletions model/UniqueId/Listener/ItemCreationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public function populateUniqueId(Event $event): void
return;
}

if (!$this->featureFlagChecker->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')) {
return;
}

$item = $this->getEventItem($event);

// We are not going to populate Unique ID for translations
Expand All @@ -78,15 +74,18 @@ public function populateUniqueId(Event $event): void
}

$identifier = $this->identifierGenerator->generate([IdentifierGeneratorInterface::OPTION_RESOURCE => $item]);
$item->editPropertyValues(
$this->ontology->getProperty(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER),
$identifier
);

$this->qtiIdentifierSetter->set([
AbstractQtiIdentifierSetter::OPTION_RESOURCE => $item,
AbstractQtiIdentifierSetter::OPTION_IDENTIFIER => $identifier,
]);

if ($this->featureFlagChecker->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')) {
$item->editPropertyValues(
$this->ontology->getProperty(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER),
$identifier
);
}
}

private function getEventItem(Event $event): core_kernel_classes_Resource
Expand Down
34 changes: 27 additions & 7 deletions test/unit/model/UniqueId/Listener/ItemCreationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,48 @@ public function testFeatureDisabled(): void
->with('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')
->willReturn(false);

$this->ontology
->expects($this->once())
->method('getResource')
->with('itemUri')
->willReturn($this->resource);

$this->resource
->expects($this->once())
->method('getRootId')
->willReturn(TaoOntology::CLASS_URI_ITEM);

$this->identifierGenerator
->expects($this->once())
->method('generate')
->with([IdentifierGeneratorInterface::OPTION_RESOURCE => $this->resource])
->willReturn('123456789');

$this->ontology
->expects($this->never())
->method('generate');
->method('getProperty');

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

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

$this->sut->populateUniqueId(new ItemCreatedEvent('itemUri'));
}

public function testIsNotItem(): void
{
$this->featureFlagChecker
->expects($this->once())
->expects($this->never())
->method('isEnabled')
->with('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER')
->willReturn(true);
->with('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER');

$this->ontology
->expects($this->once())
Expand Down

0 comments on commit 2106b60

Please sign in to comment.