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

[Fix] Translation metadata not persisted in datastore #4135

Merged
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 @@ -67,7 +67,7 @@
"oat-sa/jig": "~0.2",
"oat-sa/composer-npm-bridge": "~0.4.2||dev-master",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.39.0",
"oat-sa/generis": "dev-fix/adf-1828/translation-data-in-datastore as 99.99",
"composer/package-versions-deprecated": "^1.11",
"paragonie/random_compat": "^2.0",
"phpdocumentor/reflection-docblock": "^5.2",
Expand Down
30 changes: 30 additions & 0 deletions migrations/Version202411200904142234_tao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace oat\tao\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\tao\scripts\update\OntologyUpdater;

/**
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202411200904142234_tao extends AbstractMigration
shpran marked this conversation as resolved.
Show resolved Hide resolved
{
public function getDescription(): string
{
return 'Sync models';
}

public function up(Schema $schema): void
{
OntologyUpdater::syncModels();
}

public function down(Schema $schema): void
{
OntologyUpdater::syncModels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@
namespace oat\tao\model\Lists\Business\Specification;

use core_kernel_classes_Class;
use oat\generis\model\data\Ontology;
use oat\generis\model\GenerisRdf;
use oat\tao\model\Language\Business\Specification\LanguageClassSpecification;
use oat\tao\model\Specification\ClassSpecificationInterface;

class EditableListClassSpecification implements ClassSpecificationInterface
{
/** @var ClassSpecificationInterface */
private $listClassSpecification;
/** @var ClassSpecificationInterface */
private $languageClassSpecification;
private ClassSpecificationInterface $listClassSpecification;
private Ontology $ontology;

public function __construct(
ClassSpecificationInterface $listClassSpecification,
ClassSpecificationInterface $languageClassSpecification
Ontology $ontology
) {
$this->listClassSpecification = $listClassSpecification;
$this->languageClassSpecification = $languageClassSpecification;
$this->ontology = $ontology;
}

public function isSatisfiedBy(core_kernel_classes_Class $class): bool
{
return $this->listClassSpecification->isSatisfiedBy($class)
&& !$this->languageClassSpecification->isSatisfiedBy($class);
if (!$this->listClassSpecification->isSatisfiedBy($class)) {
return false;
}

$isEditableProperty = $this->ontology->getProperty(GenerisRdf::PROPERTY_IS_EDITABLE);
$isEditable = $class->getOnePropertyValue($isEditableProperty);

return empty($isEditable) || $isEditable->getUri() !== GenerisRdf::GENERIS_FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function __invoke(ContainerConfigurator $configurator): void
->args(
[
service(ListClassSpecification::class),
service(LanguageClassSpecification::class),
service(Ontology::SERVICE_ID),
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use tao_helpers_form_elements_Calendar;
use tao_helpers_form_elements_Hiddenbox;
use tao_helpers_form_elements_Htmlarea;
use tao_helpers_form_elements_Readonly;
use tao_helpers_form_elements_Textarea;
use tao_helpers_form_elements_Textbox;

Expand Down Expand Up @@ -77,7 +78,8 @@ public function isWidgetSupported(string $widgetUri): bool
tao_helpers_form_elements_Textarea::WIDGET_ID,
tao_helpers_form_elements_Htmlarea::WIDGET_ID,
tao_helpers_form_elements_Calendar::WIDGET_ID,
tao_helpers_form_elements_Hiddenbox::WIDGET_ID
tao_helpers_form_elements_Hiddenbox::WIDGET_ID,
tao_helpers_form_elements_Readonly::WIDGET_ID,
],
true
);
Expand Down
10 changes: 7 additions & 3 deletions models/ontology/tao.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#Languages">
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#List"/>
<rdfs:label xml:lang="en-US"><![CDATA[Languages]]></rdfs:label>
<generis:is_editable rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#False"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsages">
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
Expand Down Expand Up @@ -349,7 +350,8 @@
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationTypes">
<rdfs:label xml:lang="en-US"><![CDATA[Translation Type]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Translation Type]]></rdfs:comment>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#SystemObject"/>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#List"/>
<generis:is_editable rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#False"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationTypeOriginal">
<rdf:type rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#TranslationTypes"/>
Expand All @@ -365,7 +367,8 @@
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationProgressStatuses">
<rdfs:label xml:lang="en-US"><![CDATA[Translation Progress Statuses]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Translation Progress Statuses]]></rdfs:comment>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#SystemObject"/>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#List"/>
<generis:is_editable rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#False"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationProgressStatusPending">
<rdf:type rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#TranslationProgressStatuses"/>
Expand All @@ -386,7 +389,8 @@
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationStatuses">
<rdfs:label xml:lang="en-US"><![CDATA[Translation Statuses]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Translation Statuses]]></rdfs:comment>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#SystemObject"/>
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#List"/>
<generis:is_editable rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#False"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#TranslationStatusNotReadyForTranslation">
<rdf:type rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#TranslationStatuses"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,122 @@
namespace oat\tao\test\unit\model\Lists\Business\Specification;

use core_kernel_classes_Class;
use core_kernel_classes_Property;
use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use oat\generis\model\GenerisRdf;
use oat\generis\test\TestCase;
use oat\tao\model\Lists\Business\Specification\EditableListClassSpecification;
use PHPUnit\Framework\MockObject\MockObject;
use oat\tao\model\Specification\ClassSpecificationInterface;

class EditableListClassSpecificationTest extends TestCase
{
/** @var EditableListClassSpecification */
private $sut;
/** @var core_kernel_classes_Class|MockObject */
private core_kernel_classes_Class $class;

/** @var ClassSpecificationInterface|MockObject */
private $languageClassSpecification;
/** @var core_kernel_classes_Property|MockObject */
private core_kernel_classes_Property $property;

/** @var ClassSpecificationInterface|MockObject */
private $listClassSpecification;
private ClassSpecificationInterface $listClassSpecification;

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

private EditableListClassSpecification $sut;

protected function setUp(): void
{
$this->listClassSpecification = $this->createMock(ClassSpecificationInterface::class);
$this->languageClassSpecification = $this->createMock(ClassSpecificationInterface::class);

$this->class = $this->createMock(core_kernel_classes_Class::class);
$this->property = $this->createMock(core_kernel_classes_Property::class);

$this->listClassSpecification = $this->createMock(ClassSpecificationInterface::class);
$this->ontology = $this->createMock(Ontology::class);

$this->sut = new EditableListClassSpecification(
$this->listClassSpecification,
$this->languageClassSpecification
);
$this->sut = new EditableListClassSpecification($this->listClassSpecification, $this->ontology);
}

public function testIsSatisfiedByValid(): void
public function testIsSatisfiedByValidWithoutIsEditablePropertyValue(): void
{
$this->listClassSpecification
->method('isSatisfiedBy')
->willReturn(true);

$this->languageClassSpecification
->method('isSatisfiedBy')
->willReturn(false);
$this->ontology
->expects($this->once())
->method('getProperty')
->willReturn($this->property);

$this->class
->expects($this->once())
->method('getOnePropertyValue')
->willReturn(null);

$this->assertTrue($this->sut->isSatisfiedBy($this->class));
}

public function testIsSatisfiedByWithNotAListClass(): void
public function testIsSatisfiedByValidWithIsEditablePropertyValue(): void
{
$this->listClassSpecification
->method('isSatisfiedBy')
->willReturn(false);
->willReturn(true);

$this->languageClassSpecification
->method('isSatisfiedBy')
->willReturn(false);
$this->ontology
->expects($this->once())
->method('getProperty')
->willReturn($this->property);

$this->assertFalse($this->sut->isSatisfiedBy($this->class));
$isEditable = $this->createMock(core_kernel_classes_Resource::class);

$this->class
->expects($this->once())
->method('getOnePropertyValue')
->willReturn($isEditable);

$isEditable
->expects($this->once())
->method('getUri')
->willReturn(GenerisRdf::GENERIS_TRUE);

$this->assertTrue($this->sut->isSatisfiedBy($this->class));
}

public function testIsSatisfiedByWithNotLanguageListClass(): void
public function testIsSatisfiedByNotValidWithIsEditablePropertyValue(): void
{
$this->listClassSpecification
->method('isSatisfiedBy')
->willReturn(true);

$this->languageClassSpecification
$this->ontology
->expects($this->once())
->method('getProperty')
->willReturn($this->property);

$isEditable = $this->createMock(core_kernel_classes_Resource::class);

$this->class
->expects($this->once())
->method('getOnePropertyValue')
->willReturn($isEditable);

$isEditable
->expects($this->once())
->method('getUri')
->willReturn(GenerisRdf::GENERIS_FALSE);

$this->assertFalse($this->sut->isSatisfiedBy($this->class));
}

public function testIsSatisfiedByWithNotAListClass(): void
{
$this->listClassSpecification
->method('isSatisfiedBy')
->willReturn(true);
->willReturn(false);

$this->ontology
->expects($this->never())
->method($this->anything());

$this->assertFalse($this->sut->isSatisfiedBy($this->class));
}
Expand Down
Loading