Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
59.09% |
13 / 22 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TestClassCopier | |
59.09% |
13 / 22 |
|
75.00% |
3 / 4 |
8.46 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| copy | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| transfer | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| assertRootClass | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoTests\models\Copier; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | use core_kernel_classes_Class; |
| 27 | use oat\generis\model\data\Ontology; |
| 28 | use oat\tao\model\resources\Command\ResourceTransferCommand; |
| 29 | use oat\tao\model\resources\Contract\ResourceTransferInterface; |
| 30 | use oat\tao\model\resources\ResourceTransferResult; |
| 31 | use oat\tao\model\TaoOntology; |
| 32 | use oat\tao\model\resources\Contract\ClassCopierInterface; |
| 33 | |
| 34 | class TestClassCopier implements ClassCopierInterface, ResourceTransferInterface |
| 35 | { |
| 36 | private ResourceTransferInterface $taoClassCopier; |
| 37 | private Ontology $ontology; |
| 38 | |
| 39 | public function __construct(ResourceTransferInterface $taoClassCopier, Ontology $ontology) |
| 40 | { |
| 41 | $this->taoClassCopier = $taoClassCopier; |
| 42 | $this->ontology = $ontology; |
| 43 | } |
| 44 | |
| 45 | public function copy( |
| 46 | core_kernel_classes_Class $class, |
| 47 | core_kernel_classes_Class $destinationClass |
| 48 | ): core_kernel_classes_Class { |
| 49 | $result = $this->transfer( |
| 50 | new ResourceTransferCommand( |
| 51 | $class->getUri(), |
| 52 | $destinationClass->getUri(), |
| 53 | ResourceTransferCommand::ACL_KEEP_ORIGINAL, |
| 54 | ResourceTransferCommand::TRANSFER_MODE_COPY, |
| 55 | ) |
| 56 | ); |
| 57 | |
| 58 | return $this->ontology->getClass($result->getDestination()); |
| 59 | } |
| 60 | |
| 61 | public function transfer(ResourceTransferCommand $command): ResourceTransferResult |
| 62 | { |
| 63 | $this->assertRootClass($this->ontology->getClass($command->getFrom())); |
| 64 | |
| 65 | return $this->taoClassCopier->transfer($command); |
| 66 | } |
| 67 | |
| 68 | private function assertRootClass(core_kernel_classes_Class $class): void |
| 69 | { |
| 70 | $rootClass = $class->getClass(TaoOntology::CLASS_URI_TEST); |
| 71 | |
| 72 | if (!$class->equals($rootClass) && !$class->isSubClassOf($rootClass)) { |
| 73 | throw new InvalidArgumentException( |
| 74 | sprintf( |
| 75 | 'Selected class (%s) is not supported because it is not part of the root class (%s).', |
| 76 | $class->getUri(), |
| 77 | TaoOntology::CLASS_URI_TEST |
| 78 | ) |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | } |