Skip to content

Commit

Permalink
Merge pull request #2587 from oat-sa/fix/AUT-3916/throw-error-for-pro…
Browse files Browse the repository at this point in the history
…perties-without-range

Properties without range will throw exception
  • Loading branch information
bartlomiejmarszal authored Oct 21, 2024
2 parents 966add0 + 3ad8fc5 commit 0ef2ab5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions model/import/ChecksumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace oat\taoQtiItem\model\import;

use core_kernel_classes_Property as Property;
use InvalidArgumentException;
use oat\taoBackOffice\model\lists\ListService;

class ChecksumGenerator
Expand All @@ -36,6 +37,15 @@ public function __construct(ListService $listService)

public function getRangeChecksum(Property $property): string
{
if ($property->getRange() === null) {
throw new InvalidArgumentException(
sprintf(
'Property %s does not have range set. Only properties with range can have checksum',
$property->getUri()
)
);
}

$labels = [];
foreach ($this->listService->getListElements($property->getRange()) as $listEntry) {
$labels[] = strtolower($listEntry->getLabel());
Expand Down
14 changes: 13 additions & 1 deletion test/unit/model/import/ChecksumGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use core_kernel_classes_Class as ClassResource;
use core_kernel_classes_Property as Property;
use core_kernel_classes_Resource as Resource;
use oat\generis\model\data\Ontology;
use InvalidArgumentException;
use oat\taoBackOffice\model\lists\ListService;
use oat\taoQtiItem\model\import\ChecksumGenerator;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -74,4 +74,16 @@ public function testGetRangeChecksum(): void
$this->checksumGenerator->getRangeChecksum($this->propertyMock)
);
}

public function testThrowExceptionOnPropertyWithoutRange(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'Property propertyUri does not have range set. Only properties with range can have checksum'
);
$this->propertyMock->method('getRange')->willReturn(null);
$this->propertyMock->method('getUri')->willReturn('propertyUri');

$this->checksumGenerator->getRangeChecksum($this->propertyMock);
}
}

0 comments on commit 0ef2ab5

Please sign in to comment.