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

Properties without range will throw exception #2587

Merged
Show file tree
Hide file tree
Changes from all 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
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);
}
}
Loading