From b0c5f06726d815f85c65c931577bd15b72a831d4 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 19 Nov 2024 16:52:59 +0100 Subject: [PATCH 1/4] feat: handle translation status based on amount of items in the test --- composer.json | 2 +- .../ResourceTranslatableStatusHandler.php | 46 ++++++++ .../TranslationServiceProvider.php | 19 +++ .../ResourceTranslatableStatusHandlerTest.php | 110 ++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 models/classes/Translation/Service/ResourceTranslatableStatusHandler.php create mode 100644 test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php diff --git a/composer.json b/composer.json index 77c8fc1d9..b1bad2bc1 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "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": "dev-feat/ADF-1826/avoid-empty-translation as 99.99", "oat-sa/extension-tao-item": ">=12.4.0", "oat-sa/extension-tao-itemqti": ">=30.22.0", "oat-sa/extension-tao-test": ">=16.3.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..311d3dabe --- /dev/null +++ b/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php @@ -0,0 +1,110 @@ +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, + 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()); + } +} From 065a08aa9d399d347e6e6bb8fc185d34b92f10cb Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Fri, 22 Nov 2024 17:30:55 +0300 Subject: [PATCH 2/4] chore: use proper branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b1bad2bc1..e634a41d2 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "oat-sa/oatbox-extension-installer": "~1.1||dev-master", "qtism/qtism": ">=0.28.3", "oat-sa/generis": ">=15.39.0", - "oat-sa/tao-core": "dev-feat/ADF-1826/avoid-empty-translation as 99.99", + "oat-sa/tao-core": "dev-feat/HKD-6/integration as 99.99", "oat-sa/extension-tao-item": ">=12.4.0", "oat-sa/extension-tao-itemqti": ">=30.22.0", "oat-sa/extension-tao-test": ">=16.3.0", From ddca4bfdc775b1369ab932ec8b8a2eb71ed598da Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 26 Nov 2024 17:03:18 +0100 Subject: [PATCH 3/4] chore: update composer version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e634a41d2..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": "dev-feat/HKD-6/integration as 99.99", + "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", From 134695ff94434f35ec5d971aba0c441d5c919f76 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 26 Nov 2024 17:07:54 +0100 Subject: [PATCH 4/4] chore: fix unit test --- .../Service/ResourceTranslatableStatusHandlerTest.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php b/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php index 311d3dabe..37ca0d676 100644 --- a/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php +++ b/test/unit/models/classes/Translation/Service/ResourceTranslatableStatusHandlerTest.php @@ -22,19 +22,11 @@ namespace oat\taoQtiTest\test\unit\models\classes\Translation\Service; -use core_kernel_classes_Class; -use core_kernel_classes_Property; use core_kernel_classes_Resource; use oat\generis\model\data\Ontology; use oat\tao\model\TaoOntology; -use oat\tao\model\Translation\Entity\ResourceCollection; use oat\tao\model\Translation\Entity\ResourceTranslatableStatus; -use oat\tao\model\Translation\Entity\ResourceTranslation; -use oat\tao\model\Translation\Query\ResourceTranslationQuery; -use oat\tao\model\Translation\Repository\ResourceTranslationRepository; use oat\taoQtiTest\models\Translation\Service\ResourceTranslatableStatusHandler; -use oat\taoQtiTest\models\Translation\Service\TestTranslator; -use oat\taoTests\models\TaoTestOntology; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use taoQtiTest_models_classes_QtiTestService; @@ -61,6 +53,7 @@ protected function setUp(): void $this->status = new ResourceTranslatableStatus( 'testUri', TaoOntology::CLASS_URI_TEST, + 'languageUri', true, true );