Skip to content

Commit

Permalink
Merge pull request #4118 from oat-sa/fix/ADF-1809/duplicate-property-…
Browse files Browse the repository at this point in the history
…with-same-alias-issue

fix: class copy duplicates properties with same alias
  • Loading branch information
pnal authored Oct 31, 2024
2 parents 7bb4df2 + e55d35c commit f5e20e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions models/classes/resources/Service/ClassMetadataCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use core_kernel_classes_Class;
use core_kernel_classes_Property;
use oat\generis\model\GenerisRdf;
use oat\generis\model\OntologyRdfs;
use oat\tao\model\resources\Contract\ClassMetadataCopierInterface;
use oat\tao\model\resources\Contract\ClassMetadataMapperInterface;
Expand Down Expand Up @@ -71,6 +72,13 @@ private function copyProperty(
$newProperty->removePropertyValues($newProperty->getProperty(OntologyRdfs::RDFS_DOMAIN));
$newProperty->setDomain($destinationClass);

$this->skipAlias($newProperty);

return $newProperty;
}

private function skipAlias(core_kernel_classes_Property $newProperty)
{
$newProperty->removePropertyValues($newProperty->getProperty(GenerisRdf::PROPERTY_ALIAS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace oat\tao\test\unit\model\resources\Service;

use core_kernel_classes_Class;
use oat\generis\model\GenerisRdf;
use PHPUnit\Framework\TestCase;
use core_kernel_classes_Property;
use core_kernel_classes_Resource;
Expand All @@ -43,11 +44,14 @@ class ClassMetadataCopierTest extends TestCase

/** @var core_kernel_classes_Property|MockObject */
private $domainProperty;
/** @var core_kernel_classes_Property|MockObject */
private $aliasProperty;

protected function setUp(): void
{
$this->classMetadataMapper = $this->createMock(ClassMetadataMapperInterface::class);
$this->domainProperty = $this->createMock(core_kernel_classes_Property::class);
$this->aliasProperty = $this->createMock(core_kernel_classes_Property::class);

$this->sut = new ClassMetadataCopier($this->classMetadataMapper);
}
Expand Down Expand Up @@ -115,14 +119,20 @@ private function copyProperty(
->willReturn($newProperty);

$newProperty
->expects($this->once())
->expects(self::exactly(2))
->method('getProperty')
->with(OntologyRdfs::RDFS_DOMAIN)
->willReturn($this->domainProperty);
->withConsecutive(
[OntologyRdfs::RDFS_DOMAIN],
[GenerisRdf::PROPERTY_ALIAS]
)
->willReturnOnConsecutiveCalls($this->domainProperty, $this->aliasProperty);
$newProperty
->expects($this->once())
->expects(self::exactly(2))
->method('removePropertyValues')
->with($this->domainProperty);
->withConsecutive(
[$this->domainProperty],
[$this->aliasProperty]
);
$newProperty
->expects($this->once())
->method('setDomain')
Expand Down

0 comments on commit f5e20e7

Please sign in to comment.