diff --git a/composer.json b/composer.json index 77c8fc1d9..2b3b61603 100644 --- a/composer.json +++ b/composer.json @@ -64,9 +64,9 @@ "oat-sa/oatbox-extension-installer": "~1.1||dev-master", "qtism/qtism": ">=0.28.3", "oat-sa/generis": ">=15.39.0", - "oat-sa/tao-core": ">=54.23.0", + "oat-sa/tao-core": ">=54.25.0", "oat-sa/extension-tao-item": ">=12.4.0", - "oat-sa/extension-tao-itemqti": ">=30.22.0", + "oat-sa/extension-tao-itemqti": ">=30.23.0", "oat-sa/extension-tao-test": ">=16.3.0", "oat-sa/extension-tao-delivery": ">=15.0.0", "oat-sa/extension-tao-outcome": ">=13.0.0", diff --git a/models/classes/Translation/Service/ResourceTranslatableStatusHandler.php b/models/classes/Translation/Service/ResourceTranslatableStatusHandler.php new file mode 100644 index 000000000..fd5b802d9 --- /dev/null +++ b/models/classes/Translation/Service/ResourceTranslatableStatusHandler.php @@ -0,0 +1,46 @@ +testQtiService = $testQtiService; + $this->ontology = $ontology; + } + + public function __invoke(ResourceTranslatableStatus $status): void + { + $originalTest = $this->ontology->getResource($status->getUri()); + + $status->setEmpty(empty($this->testQtiService->getItems($originalTest))); + } +} diff --git a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php index 0c0eaa757..3b37a331b 100644 --- a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php +++ b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php @@ -27,10 +27,12 @@ use oat\oatbox\log\LoggerService; use oat\tao\model\TaoOntology; use oat\tao\model\Translation\Repository\ResourceTranslationRepository; +use oat\tao\model\Translation\Service\ResourceTranslatableStatusRetriever; use oat\tao\model\Translation\Service\TranslationCreationService; use oat\tao\model\Translation\Service\TranslationSyncService as TaoTranslationSyncService; use oat\tao\model\Translation\Service\TranslationUniqueIdSetter; use oat\taoQtiTest\models\Qti\Identifier\Service\QtiIdentifierSetter; +use oat\taoQtiTest\models\Translation\Service\ResourceTranslatableStatusHandler; use oat\taoQtiTest\models\Translation\Service\TestTranslator; use oat\taoQtiTest\models\Translation\Service\TranslationPostCreationService; use oat\taoQtiTest\models\Translation\Service\TranslationSyncService; @@ -54,6 +56,13 @@ public function __invoke(ContainerConfigurator $configurator): void service(LoggerService::SERVICE_ID), ]); + $services + ->set(ResourceTranslatableStatusHandler::class, ResourceTranslatableStatusHandler::class) + ->args([ + service(taoQtiTest_models_classes_QtiTestService::class), + service(Ontology::SERVICE_ID), + ]); + $services ->set(TranslationSyncService::class, TranslationSyncService::class) ->args([ @@ -104,5 +113,15 @@ public function __invoke(ContainerConfigurator $configurator): void service(TranslationUniqueIdSetter::class), ] ); + + $services + ->get(ResourceTranslatableStatusRetriever::class) + ->call( + 'addCallable', + [ + TaoOntology::CLASS_URI_TEST, + service(ResourceTranslatableStatusHandler::class) + ] + ); } } diff --git a/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php b/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php new file mode 100644 index 000000000..37ca0d676 --- /dev/null +++ b/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php @@ -0,0 +1,103 @@ +test = $this->createMock(core_kernel_classes_Resource::class); + $this->testQtiService = $this->createMock(taoQtiTest_models_classes_QtiTestService::class); + $this->ontology = $this->createMock(Ontology::class); + $this->status = new ResourceTranslatableStatus( + 'testUri', + TaoOntology::CLASS_URI_TEST, + 'languageUri', + true, + true + ); + + $this->sut = new ResourceTranslatableStatusHandler($this->testQtiService, $this->ontology); + } + + public function testMustMarkAsEmptyIfTestHasNoItems(): void + { + $this->ontology + ->expects($this->once()) + ->method('getResource') + ->with('testUri') + ->willReturn($this->test); + + $this->testQtiService + ->expects($this->once()) + ->method('getItems') + ->with($this->test) + ->willReturn([]); + + $this->sut->__invoke($this->status); + + $this->assertTrue($this->status->isEmpty()); + } + + public function testMustMarkAsNotEmptyIfTestHasNoItems(): void + { + $this->ontology + ->expects($this->once()) + ->method('getResource') + ->with('testUri') + ->willReturn($this->test); + + $this->testQtiService + ->expects($this->once()) + ->method('getItems') + ->with($this->test) + ->willReturn([ + $this->createMock(core_kernel_classes_Resource::class) + ]); + + $this->sut->__invoke($this->status); + + $this->assertFalse($this->status->isEmpty()); + } +}