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

Feat/hkd 6/integration #2537

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.
*/

declare(strict_types=1);

namespace oat\taoQtiTest\models\Translation\Service;

use oat\generis\model\data\Ontology;
use oat\tao\model\Translation\Entity\ResourceTranslatableStatus;
use taoQtiTest_models_classes_QtiTestService;

class ResourceTranslatableStatusHandler
{
private taoQtiTest_models_classes_QtiTestService $testQtiService;
private Ontology $ontology;

public function __construct(taoQtiTest_models_classes_QtiTestService $testQtiService, Ontology $ontology)
{
$this->testQtiService = $testQtiService;
$this->ontology = $ontology;
}

public function __invoke(ResourceTranslatableStatus $status): void
{
$originalTest = $this->ontology->getResource($status->getUri());

$status->setEmpty(empty($this->testQtiService->getItems($originalTest)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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([
Expand Down Expand Up @@ -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)
]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.
*/

declare(strict_types=1);

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;

class ResourceTranslatableStatusHandlerTest extends TestCase
{
/** @var core_kernel_classes_Resource|MockObject */
private $test;

/** @var taoQtiTest_models_classes_QtiTestService|MockObject */
private $testQtiService;

/** @var Ontology|MockObject */
private $ontology;

private ResourceTranslatableStatusHandler $sut;
private ResourceTranslatableStatus $status;

protected function setUp(): void
{
$this->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());
}
}
Loading