Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/oat-sa/extension-tao-test
Browse files Browse the repository at this point in the history
…into feature/adf-1794/advanced-search-support
  • Loading branch information
shpran committed Nov 12, 2024
2 parents 451c6de + 2e0a837 commit bf65a76
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 27 deletions.
17 changes: 17 additions & 0 deletions actions/class.Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ public function authoring()
if (!empty($authoringUrl)) {
$userId = common_session_SessionManager::getSession()->getUser()->getIdentifier();
LockManager::getImplementation()->setLock($test, $userId);

// Add support for the translation and the side-by-side authoring tool
if ($this->getRequestParameter('translation') !== null) {
$authoringUrl = sprintf(
'%s&translation=%s',
$authoringUrl,
$this->getRequestParameter('translation')
);
}
if ($this->getRequestParameter('originResourceUri') !== null) {
$authoringUrl = sprintf(
'%s&originResourceUri=%s',
$authoringUrl,
$this->getRequestParameter('originResourceUri')
);
}

return $this->forwardUrl($authoringUrl);
}
throw new common_exception_NoImplementation();
Expand Down
2 changes: 1 addition & 1 deletion actions/structures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<icon id="icon-test"/>
</action>
<action id="test-translate" name="Translate" url="/tao/Translation/translate" context="instance" group="tree" binding="translateTest">
<icon id="icon-spell-check"/>
<icon id="icon-replace"/>
</action>
</actions>
</section>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
},
"require": {
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.24",
"oat-sa/tao-core": "dev-feat/HKD-6/integration as 99",
"oat-sa/generis": ">=15.39.0",
"oat-sa/tao-core": ">=54.23.0",
"oat-sa/extension-tao-backoffice": ">=6.0.0",
"oat-sa/extension-tao-item": "dev-feat/HKD-6/integration as 99"
"oat-sa/extension-tao-item": ">=12.4.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion locales/it-IT/messages.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
$GLOBALS['__l10n']["Default search"] = "Ricerca di default";
$GLOBALS['__l10n']["Default user cannot be deleted"] = "L'utilizzatore di default non può essere eliminato";
$GLOBALS['__l10n']["Define the default values"] = "Definisci i valori di default";
$GLOBALS['__l10n']["Delete"] = "Cancella";
$GLOBALS['__l10n']["Delete"] = "Elimina";
$GLOBALS['__l10n']["Deliveries"] = "Somministrazioni";
$GLOBALS['__l10n']["Demo Sandbox"] = "Demo Sandbox";
$GLOBALS['__l10n']["Disabled %s"] = "Disabilitata %s";
Expand Down
30 changes: 30 additions & 0 deletions migrations/Version202411111300542363_taoTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace oat\taoTests\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 Version202411111300542363_taoTests extends AbstractMigration
{
public function getDescription(): string
{
return 'Sync models';
}

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

public function down(Schema $schema): void
{
OntologyUpdater::syncModels();
}
}
6 changes: 6 additions & 0 deletions models/classes/Copier/CopierServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public function __invoke(ContainerConfigurator $configurator): void
[
tagged_iterator('tao.copier.permissions'),
]
)
->call(
'withEventManager',
[
service(EventManager::class),
]
);

$services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace oat\taoTests\models\Translation\Form\Modifier;

use core_kernel_classes_Literal;
use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\form\Modifier\AbstractFormModifier;
Expand Down Expand Up @@ -54,10 +56,13 @@ public function modify(Form $form, array $options = []): void
$translationType = $instance->getOnePropertyValue(
$this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE)
);
$translationTypeUri = $translationType instanceof core_kernel_classes_Literal
? (string) $translationType
: ($translationType instanceof core_kernel_classes_Resource ? $translationType->getUri() : null);

if (
empty($translationType)
|| $translationType->getUri() === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
|| $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL
) {
$form->removeElement(tao_helpers_Uri::encode(TaoTestOntology::PROPERTY_TRANSLATION_COMPLETION));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\oatbox\log\LoggerService;
use oat\tao\model\resources\Service\InstanceCopier;
use oat\tao\model\TaoOntology;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\Translation\Form\Modifier\TranslationFormModifier as TaoTranslationFormModifier;
Expand All @@ -37,7 +38,6 @@
use oat\taoTests\models\Translation\Listener\TestCreatedEventListener;
use oat\taoTests\models\Translation\Service\TranslationPostCreationService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use taoTests_models_classes_TestsService;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand Down Expand Up @@ -102,10 +102,10 @@ public function __invoke(ContainerConfigurator $configurator): void
$services
->get(TranslationCreationService::class)
->call(
'setOntologyClassService',
'setResourceTransfer',
[
TaoOntology::CLASS_URI_TEST,
service(taoTests_models_classes_TestsService::class)
service(InstanceCopier::class . '::TESTS')
]
)
->call(
Expand Down
5 changes: 5 additions & 0 deletions models/classes/event/TestDuplicatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public function jsonSerialize()
'cloneUri' => $this->cloneUri
];
}

public function getCloneUri(): string
{
return $this->cloneUri;
}
}
2 changes: 1 addition & 1 deletion models/ontology/taotest.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#Test"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAOTest.rdf#TranslationCompletion">
<tao:PropertyAlias><![CDATA[taoTranslationCompletion]]></tao:PropertyAlias>
<generis:alias><![CDATA[taoTranslationCompletion]]></generis:alias>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAOTest.rdf#Test"/>
<rdfs:label xml:lang="en-US"><![CDATA[Translation Completion]]></rdfs:label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testModifyTranslationDisabled(): void
$this->sut->modify($this->form);
}

private function translationTypeDataProvider(): array
public function translationTypeDataProvider(): array
{
return [
'Original' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
use core_kernel_classes_Property;
use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use oat\oatbox\user\UserLanguageServiceInterface;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\TaoOntology;
use oat\tao\model\Translation\Service\ResourceLanguageRetriever;
use oat\taoTests\models\event\TestCreatedEvent;
use oat\taoTests\models\Translation\Listener\TestCreatedEventListener;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -57,8 +57,8 @@ class TestCreatedEventListenerTest extends TestCase
/** @var Ontology|MockObject */
private Ontology $ontology;

/** @var UserLanguageServiceInterface|MockObject */
private $userLanguageService;
/** @var ResourceLanguageRetriever|MockObject */
private ResourceLanguageRetriever $resourceLanguageRetriever;

/** @var LoggerInterface|MockObject */
private LoggerInterface $logger;
Expand All @@ -75,13 +75,13 @@ protected function setUp(): void

$this->featureFlagChecker = $this->createMock(FeatureFlagCheckerInterface::class);
$this->ontology = $this->createMock(Ontology::class);
$this->userLanguageService = $this->createMock(UserLanguageServiceInterface::class);
$this->resourceLanguageRetriever = $this->createMock(ResourceLanguageRetriever::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->sut = new TestCreatedEventListener(
$this->featureFlagChecker,
$this->ontology,
$this->userLanguageService,
$this->resourceLanguageRetriever,
$this->logger
);
}
Expand Down Expand Up @@ -157,9 +157,10 @@ public function testPopulateTranslationProperties(): void
->expects($this->never())
->method('info');

$this->userLanguageService
$this->resourceLanguageRetriever
->expects($this->once())
->method('getDefaultLanguage')
->method('retrieve')
->with($this->test)
->willReturn('en-US');

$this->test
Expand Down Expand Up @@ -225,9 +226,11 @@ public function testPopulateTranslationPropertiesValueSet(): void
->expects($this->exactly(3))
->method('info');

$this->userLanguageService
->expects($this->never())
->method('getDefaultLanguage');
$this->resourceLanguageRetriever
->expects($this->once())
->method('retrieve')
->with($this->test)
->willReturn('en-US');

$this->test
->expects($this->never())
Expand Down
51 changes: 47 additions & 4 deletions views/js/controller/tests/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,60 @@
*/
define([
'i18n',
'layout/actions/binder',
'module',
'uri',
'layout/actions',
'layout/actions/binder',
'layout/section',
'form/translation',
'services/translation',
'ui/feedback',
'core/logger',
'taoTests/previewer/factory',
'module'
], function (__, binder, uri, feedback, loggerFactory, previewerFactory, module) {
'taoTests/previewer/factory'
], function (
__,
module,
uri,
actionManager,
binder,
section,
translationFormFactory,
translationService,
feedback,
loggerFactory,
previewerFactory
) {
'use strict';

const logger = loggerFactory('taoTests/controller/action');

binder.register('translateTest', function (actionContext) {
section.current().updateContentBlock('<div class="main-container flex-container-full"></div>');
const $container = $('.main-container', section.selected.panel);
const { rootClassUri, id: resourceUri } = actionContext;
translationFormFactory($container, { rootClassUri, resourceUri, allowDeletion: true })
.on('edit', (id, language) => {
return actionManager.exec('test-authoring', {
id,
language,
rootClassUri,
originResourceUri: resourceUri,
translation: true,
actionParams: ['originResourceUri', 'language', 'translation']
});
})
.on('delete', function onDelete(id, language) {
return translationService.deleteTranslation(resourceUri, language).then(() => {
feedback().success(__('Translation deleted'));
return this.refresh();
});
})
.on('error', error => {
logger.error(error);
feedback().error(__('An error occurred while processing your request.'));
});
});

binder.register('testPreview', function testPreview(actionContext) {
const config = module.config();
const previewerConfig = Object.fromEntries(
Expand Down
Loading

0 comments on commit bf65a76

Please sign in to comment.