Skip to content

Commit

Permalink
Export: adds tests and adjusts code to allow for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chlulei committed Oct 21, 2024
1 parent ffd4e94 commit f557fa0
Show file tree
Hide file tree
Showing 29 changed files with 679 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ interface HandlerInterface
{
public const ELEMENT_TYPE = 'xml';

public function withKey(ilExportHandlerRepositoryKeyInterface $key): HandlerInterface;
public function withKey(
ilExportHandlerRepositoryKeyInterface $key
): HandlerInterface;

public function withValues(ilExportHandlerRepositoryValuesInterface $values): HandlerInterface;
public function withValues(
ilExportHandlerRepositoryValuesInterface $values
): HandlerInterface;

public function getKey(): ilExportHandlerRepositoryKeyInterface;

Expand All @@ -44,4 +48,8 @@ public function getIRSS(): ilExportHandlerRepositoryElementIRSSWrapperInterface;
public function getFileType(): string;

public function isStorable(): bool;

public function equals(
HandlerInterface $other_element
): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
namespace ILIAS\Export\ExportHandler\I\Repository\Key;

use ILIAS\Data\ObjectId;
use ILIAS\Export\ExportHandler\I\Repository\Key\HandlerInterface as ilExportHandlerRepositoryKeyInterface;

interface HandlerInterface
{
public const EMPTY_RESOURCE_IDENTIFICATION = "";
public const EMPTY_OBJECT_ID = -1;

public function withObjectId(ObjectId $object_id): HandlerInterface;
public function withObjectId(
ObjectId $object_id
): HandlerInterface;

public function withResourceIdSerialized(string $resource_identification_serialized): HandlerInterface;
public function withResourceIdSerialized(
string $resource_identification_serialized
): HandlerInterface;

public function getObjectId(): ObjectId;

Expand All @@ -40,4 +45,8 @@ public function isCompleteKey(): bool;
public function isObjectIdKey(): bool;

public function isResourceIdKey(): bool;

public function equals(
ilExportHandlerRepositoryKeyInterface $other_repository_key
): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

interface HandlerInterface extends ResourceStakeholder
{
public const DEFAULT_OWNER_ID = 6;

public function withOwnerId(int $owner_id): HandlerInterface;

public function getOwnerId(): int;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@
namespace ILIAS\Export\ExportHandler\I\Repository\Values;

use DateTimeImmutable;
use ILIAS\Export\ExportHandler\I\Repository\Values\HandlerInterface as ilExportHandlerRepositoryValuesInterface;

interface HandlerInterface
{
public function withOwnerId(int $owner_id): HandlerInterface;
public function withOwnerId(
int $owner_id
): HandlerInterface;

public function withCreationDate(DateTimeImmutable $creation_date): HandlerInterface;
public function withCreationDate(
DateTimeImmutable $creation_date
): HandlerInterface;

public function getOwnerId(): int;

public function getCreationDate(): DateTimeImmutable;

public function isValid(): bool;

public function equals(
ilExportHandlerRepositoryValuesInterface $other_repository_values
): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ interface HandlerInterface
public function createEmptyContainer(
ilExportHandlerExportInfoInterface $info,
ilExportHandlerRepositoryStakeholderInterface $stakeholder
): ResourceIdentification;
): string;

public function getCreationDate(ResourceIdentification $resource_id): DateTimeImmutable;
public function getCreationDate(
string $resource_identification_serialized
): DateTimeImmutable;

public function removeContainer(
string $resource_identification_serialized,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ILIAS\Export\ExportHandler\I\Info\Export\CollectionInterface as ilExportHandlerExportInfoCollectionInterface;
use ILIAS\Export\ExportHandler\I\Info\Export\HandlerInterface as ilExportHandlerExportInfoInterface;

class collection implements ilExportHandlerExportInfoCollectionInterface
class Collection implements ilExportHandlerExportInfoCollectionInterface
{
protected array $elements;
protected int $index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
use ILIAS\Export\ExportHandler\I\Info\Export\Container\FactoryInterface as ilExportHandlerContainerExportInfoFactoryInterface;
use ILIAS\Export\ExportHandler\I\Info\Export\FactoryInterface as ilExportHandlerExportInfoFactory;
use ILIAS\Export\ExportHandler\I\Info\Export\HandlerInterface as ilExportHandlerExportInfoInterface;
use ILIAS\Export\ExportHandler\Info\Export\collection as ilExportHandlerExportInfoCollection;
use ILIAS\Export\ExportHandler\Info\Export\Collection as ilExportHandlerExportInfoCollection;
use ILIAS\Export\ExportHandler\Info\Export\Component\Factory as ilExportHandlerExportComponentInfoFactory;
use ILIAS\Export\ExportHandler\Info\Export\Container\Factory as ilExportHandlerContainerExportInfoFactory;
use ILIAS\Export\ExportHandler\Info\Export\handler as ilExportHandlerExportInfo;
use ILIAS\Export\ExportHandler\Info\Export\Handler as ilExportHandlerExportInfo;

class factory implements ilExportHandlerExportInfoFactory
class Factory implements ilExportHandlerExportInfoFactory
{
protected ilExportHandlerFactoryInterface $export_handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use ILIAS\Export\ExportHandler\I\Repository\Element\HandlerInterface as ilExportHandlerRepositoryElementInterface;
use ILIAS\Export\ExportHandler\I\Target\HandlerInterface as ilExportHandlerTargetInterface;

class handler implements ilExportHandlerExportInfoInterface
class Handler implements ilExportHandlerExportInfoInterface
{
protected ilExportHandlerFactoryInterface $export_handler;
protected ilExportHandlerTargetInterface $export_target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use ILIAS\Export\ExportHandler\I\Info\Export\FactoryInterface as ilExportHandlerExportInfoFactoryInterface;
use ILIAS\Export\ExportHandler\I\Info\FactoryInterface as ilExportHandlerInfoFactoryInterface;
use ILIAS\Export\ExportHandler\I\Info\File\FactoryInterface as ilExportHandlerFileInfoFactoryInterface;
use ILIAS\Export\ExportHandler\Info\Export\factory as ilExportHandlerExportInfoFactory;
use ILIAS\Export\ExportHandler\Info\Export\Factory as ilExportHandlerExportInfoFactory;
use ILIAS\Export\ExportHandler\Info\File\Factory as ilExportHandlerFileInfoFactory;
use ILIAS\ResourceStorage\Services as ResourcesStorageService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use ILIAS\Export\ExportHandler\I\Manager\HandlerInterface as ilExportHandlerManagerInterface;
use ILIAS\Export\ExportHandler\I\Repository\Element\HandlerInterface as ilExportHandlerRepositoryElementInterface;
use ILIAS\Export\ExportHandler\I\Target\HandlerInterface as ilExportHandlerTargetInterface;
use ILIAS\Export\ExportHandler\Info\Export\handler as ilExportHandlerExportInfo;
use ILIAS\Export\ExportHandler\Info\Export\Handler as ilExportHandlerExportInfo;
use ILIAS\Filesystem\Stream\Streams;
use ilImportExportFactory;
use ilObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,28 @@ public function isStorable(): bool
$this->values->isValid()
);
}

public function equals(
ilExportHandlerRepositoryElementInterface $other_element
): bool {
$key_equals =
(
isset($this->key) and
isset($other_element->key) and
$this->key->equals($other_element->key)
) || (
!isset($this->key) and
!isset($other_element->key)
);
$values_equals =
(
isset($this->values) and
isset($other_element->values) and
$this->values->equals($other_element->values)
) || (
!isset($this->values) and
!isset($other_element->values)
);
return $key_equals and $values_equals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public function createElement(
ilExportHandlerExportInfoInterface $info,
ilExportHandlerRepositoryStakeholderInterface $stakeholder
): ilExportHandlerRepositoryElementInterface {
$resource_id = $this->irss_wrapper->createEmptyContainer($info, $stakeholder);
$resource_id_serialized = $this->irss_wrapper->createEmptyContainer($info, $stakeholder);
$key = $this->key_factory->handler()
->withObjectId($object_id)
->withResourceIdSerialized($resource_id->serialize());
->withResourceIdSerialized($resource_id_serialized);
$values = $this->values_factory->handler()
->withOwnerId($stakeholder->getOwnerId())
->withCreationDate($this->irss_wrapper->getCreationDate($resource_id));
->withCreationDate($this->irss_wrapper->getCreationDate($resource_id_serialized));
$element = $this->element_factory->handler()
->withKey($key)
->withValues($values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,28 @@ public function isResourceIdKey(): bool
$this->resource_identification_serialized !== self::EMPTY_RESOURCE_IDENTIFICATION
);
}

public function equals(
ilExportHandlerRepositoryKeyInterface $other_repository_key
): bool {
$object_id_equals =
(
isset($this->object_id) and
isset($other_repository_key->object_id) and
$this->object_id->toInt() === $other_repository_key->object_id->toInt()
) || (
!isset($this->object_id) and
!isset($other_repository_key->object_id)
);
$resource_id_equals =
(
isset($this->resource_identification_serialized) and
isset($other_repository_key->resource_identification_serialized) and
$this->resource_identification_serialized === $other_repository_key->resource_identification_serialized
) || (
!isset($this->resource_identification_serialized) and
!isset($other_repository_key->resource_identification_serialized)
);
return $resource_id_equals and $object_id_equals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Handler extends AbstractResourceStakeholder implements ilExportHandlerRepo
{
protected int $owner_id;

public function __construct(int $usr_id = 6)
public function __construct(int $usr_id = null)
{
$this->owner_id = $usr_id;
$this->owner_id = $usr_id ?? self::DEFAULT_OWNER_ID;
}

public function getId(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,28 @@ public function isValid(): bool
isset($this->creation_date)
);
}

public function equals(
ilExportHandlerRepositoryValuesInterface $other_repository_values
): bool {
$owner_id_equals =
(
isset($this->owner_id) and
isset($other_repository_values->owner_id) and
$this->owner_id = $other_repository_values->owner_id
) || (
!isset($this->owner_id) and
!isset($other_repository_values->owner_id)
);
$creation_date_equals =
(
isset($this->creation_date) and
isset($other_repository_values->creation_date) and
$this->creation_date->getTimestamp() === $other_repository_values->creation_date->getTimestamp()
) || (
!isset($this->creation_date) and
!isset($other_repository_values->creation_date)
);
return $owner_id_equals and $creation_date_equals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
public function createEmptyContainer(
ilExportHandlerExportInfoInterface $info,
ilExportHandlerRepositoryStakeholderInterface $stakeholder
): ResourceIdentification {
): string {
$tmp_dir_info = new SplFileInfo(ilFileUtils::ilTempnam());
$this->filesystems->temp()->createDir($tmp_dir_info->getFilename());
$export_dir = $tmp_dir_info->getRealPath();
Expand All @@ -62,13 +62,15 @@ public function createEmptyContainer(
$zip->addStream(Streams::ofString(self::TMP_FILE_CONTENT), self::TMP_FILE_PATH);
$rid = $this->irss->manageContainer()->containerFromStream($zip->get(), $stakeholder);
ilFileUtils::delDir($export_dir);
return $rid;
return $rid->serialize();
}

public function getCreationDate(ResourceIdentification $resource_id): DateTimeImmutable
{
return $this->irss->manageContainer()->getResource($resource_id)->getCurrentRevision()->getInformation()
->getCreationDate();
public function getCreationDate(
string $resource_identification_serialized
): DateTimeImmutable {
$resource_identification = $this->irss->manageContainer()->find($resource_identification_serialized);
return $this->irss->manageContainer()->getResource($resource_identification)->getCurrentRevision()
->getInformation()->getCreationDate();
}

public function removeContainer(
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Export/classes/class.ilExportGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ final protected function builtExportOptionCommand(ilExportHandlerConsumerExportO

final protected function enableStandardXMLExport(): void
{
# Exception for Test, TestQuestionPool, OrgUnit
# Exception for Test, TestQuestionPool
if (in_array($this->obj->getType(), ["tst", "qpl"])) {
return;
}
Expand Down
Loading

0 comments on commit f557fa0

Please sign in to comment.