Skip to content

Commit

Permalink
Merge branch 'release-15.16.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 27, 2023
2 parents 66947ba + c1bac2a commit 5b66b7e
Show file tree
Hide file tree
Showing 8 changed files with 555 additions and 25 deletions.
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.22",
"oat-sa/tao-core": ">=50.24.6",
"oat-sa/generis": ">=15.24",
"oat-sa/tao-core": ">=52.1",
"oat-sa/extension-tao-backoffice": ">=6.0.0",
"oat-sa/extension-tao-item": ">=11.0.0"
"oat-sa/extension-tao-item": ">=11.33"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 14 additions & 6 deletions manifest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -14,19 +15,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg (under the project TAO & TAO2);
* 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung (under the project TAO-TRANSFER);
* 2009-2012 (update and modification) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV);
* 2013- (update and modification) Open Assessment Technologies SA;
* Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg
* (under the project TAO & TAO2);
* 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung
* (under the project TAO-TRANSFER);
* 2009-2012 (update and modification) Public Research Centre Henri Tudor
* (under the project TAO-SUSTAIN & TAO-DEV);
* 2013-2023 (update and modification) Open Assessment Technologies SA.
*/

/*
* @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu}
* @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php
*
*/

use oat\tao\model\user\TaoRoles;
use oat\taoTests\models\Copier\CopierServiceProvider;
use oat\taoTests\scripts\update\Updater;
use oat\taoTests\scripts\install\SetupProvider;
use oat\taoTests\scripts\install\RegisterFrontendPaths;
Expand All @@ -39,7 +43,8 @@
return [
'name' => 'taoTests',
'label' => 'Test core extension',
'description' => 'TAO Tests extension contains the abstraction of the test-runners, but requires an implementation in order to be able to run tests',
'description' => 'TAO Tests extension contains the abstraction of the test-runners, but requires an implementation '
. 'in order to be able to run tests',
'license' => 'GPL-2.0',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'models' => [
Expand Down Expand Up @@ -85,4 +90,7 @@
#BASE URL (usually the domain root)
'BASE_URL' => ROOT_URL . 'taoTests/',
],
'containerServiceProviders' => [
CopierServiceProvider::class,
],
];
149 changes: 149 additions & 0 deletions models/classes/Copier/CopierServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

namespace oat\taoTests\models\Copier;

use oat\generis\model\data\Ontology;
use oat\generis\model\OntologyRdf;
use oat\generis\model\OntologyRdfs;
use oat\tao\model\resources\Service\InstanceCopierProxy;
use oat\tao\model\TaoOntology;
use oat\oatbox\event\EventManager;
use oat\tao\model\resources\Service\ClassCopier;
use oat\tao\model\resources\Service\InstanceCopier;
use oat\tao\model\resources\Service\ClassCopierProxy;
use oat\tao\model\resources\Service\ClassMetadataCopier;
use oat\tao\model\resources\Service\ClassMetadataMapper;
use oat\tao\model\resources\Service\InstanceMetadataCopier;
use oat\tao\model\resources\Service\RootClassesListService;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use taoTests_models_classes_TestsService;

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

/**
* @codeCoverageIgnore
*/
class CopierServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();

$services
->set(taoTests_models_classes_TestsService::class, taoTests_models_classes_TestsService::class)
->factory(taoTests_models_classes_TestsService::class . '::singleton');

$services
->get(InstanceMetadataCopier::class)
->call(
'addPropertyUrisToBlacklist',
[
[
taoTests_models_classes_TestsService::PROPERTY_TEST_CONTENT,
OntologyRdfs::RDFS_LABEL,
]
]
);

$services
->set(TestContentCopier::class, TestContentCopier::class)
->args(
[
service(taoTests_models_classes_TestsService::class),
service(EventManager::SERVICE_ID),
]
);

$services
->set(InstanceCopier::class . '::TESTS', InstanceCopier::class)
->args(
[
service(InstanceMetadataCopier::class),
service(Ontology::SERVICE_ID)
]
)
->call(
'withInstanceContentCopier',
[
service(TestContentCopier::class),
]
)
->call(
'withPermissionCopiers',
[
tagged_iterator('tao.copier.permissions'),
]
);

$services
->set(ClassCopier::class . '::TESTS', ClassCopier::class)
->share(false)
->args(
[
service(RootClassesListService::class),
service(ClassMetadataCopier::class),
service(InstanceCopier::class . '::TESTS'),
service(ClassMetadataMapper::class),
service(Ontology::SERVICE_ID),
]
)
->call(
'withPermissionCopiers',
[
tagged_iterator('tao.copier.permissions'),
]
);

$services
->set(TestClassCopier::class, TestClassCopier::class)
->share(false)
->args(
[
service(ClassCopier::class . '::TESTS'),
service(Ontology::SERVICE_ID),
]
);

$services
->get(ClassCopierProxy::class)
->call(
'addClassCopier',
[
TaoOntology::CLASS_URI_TEST,
service(TestClassCopier::class),
]
);

$services
->get(InstanceCopierProxy::class)
->call(
'addInstanceCopier',
[
TaoOntology::CLASS_URI_TEST,
service(InstanceCopier::class . '::TESTS'),
]
);
}
}
82 changes: 82 additions & 0 deletions models/classes/Copier/TestClassCopier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

namespace oat\taoTests\models\Copier;

use InvalidArgumentException;
use core_kernel_classes_Class;
use oat\generis\model\data\Ontology;
use oat\tao\model\resources\Command\ResourceTransferCommand;
use oat\tao\model\resources\Contract\ResourceTransferInterface;
use oat\tao\model\resources\ResourceTransferResult;
use oat\tao\model\TaoOntology;
use oat\tao\model\resources\Contract\ClassCopierInterface;

class TestClassCopier implements ClassCopierInterface, ResourceTransferInterface
{
private ResourceTransferInterface $taoClassCopier;
private Ontology $ontology;

public function __construct(ResourceTransferInterface $taoClassCopier, Ontology $ontology)
{
$this->taoClassCopier = $taoClassCopier;
$this->ontology = $ontology;
}

public function copy(
core_kernel_classes_Class $class,
core_kernel_classes_Class $destinationClass
): core_kernel_classes_Class {
$result = $this->transfer(
new ResourceTransferCommand(
$class->getUri(),
$destinationClass->getUri(),
ResourceTransferCommand::ACL_KEEP_ORIGINAL,
ResourceTransferCommand::TRANSFER_MODE_COPY,
)
);

return $this->ontology->getClass($result->getDestination());
}

public function transfer(ResourceTransferCommand $command): ResourceTransferResult
{
$this->assertRootClass($this->ontology->getClass($command->getFrom()));

return $this->taoClassCopier->transfer($command);
}

private function assertRootClass(core_kernel_classes_Class $class): void
{
$rootClass = $class->getClass(TaoOntology::CLASS_URI_TEST);

if (!$class->equals($rootClass) && !$class->isSubClassOf($rootClass)) {
throw new InvalidArgumentException(
sprintf(
'Selected class (%s) is not supported because it is not part of the root class (%s).',
$class->getUri(),
TaoOntology::CLASS_URI_TEST
)
);
}
}
}
59 changes: 59 additions & 0 deletions models/classes/Copier/TestContentCopier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

namespace oat\taoTests\models\Copier;

use core_kernel_classes_Resource;
use oat\oatbox\event\EventManager;
use oat\tao\model\resources\Contract\InstanceContentCopierInterface;
use oat\taoTests\models\event\TestDuplicatedEvent;
use taoTests_models_classes_TestsService;

class TestContentCopier implements InstanceContentCopierInterface
{
private taoTests_models_classes_TestsService $testsService;
private EventManager $eventManager;

public function __construct(taoTests_models_classes_TestsService $testsService, EventManager $eventManager)
{
$this->testsService = $testsService;
$this->eventManager = $eventManager;
}

public function copy(
core_kernel_classes_Resource $instance,
core_kernel_classes_Resource $destinationInstance
): void {
$this->copyModel($instance, $destinationInstance);
$this->testsService->cloneContent($instance, $destinationInstance);

$this->eventManager->trigger(new TestDuplicatedEvent($instance->getUri(), $destinationInstance->getUri()));
}

private function copyModel(core_kernel_classes_Resource $from, core_kernel_classes_Resource $to): void
{
$modelProperty = $from->getProperty(taoTests_models_classes_TestsService::PROPERTY_TEST_TESTMODEL);
$model = $from->getOnePropertyValue($modelProperty);

$to->editPropertyValues($modelProperty, $model instanceof core_kernel_classes_Resource ? $model : null);
}
}
Loading

0 comments on commit 5b66b7e

Please sign in to comment.