19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
53 ?
int $throw_error_on_withdraw_obj_id =
null,
54 ?
int $throw_error_on_publish_obj_id =
null
57 $throw_error_on_withdraw_obj_id,
58 $throw_error_on_publish_obj_id
60 public array $exposed_withdrawn_objects = [];
61 public array $exposed_submitted_objects = [];
62 public array $exposed_published_objects = [];
65 protected ?
int $throw_error_on_withdraw_obj_id,
66 protected ?
int $throw_error_on_publish_obj_id
70 public function withdraw(
int $obj_id): void
72 if ($this->throw_error_on_withdraw_obj_id === $obj_id) {
73 throw new \ilMDOERHarvesterException(
'error');
75 $this->exposed_withdrawn_objects[] = $obj_id;
78 public function submit(
int $obj_id): void
80 $this->exposed_submitted_objects[] = $obj_id;
83 public function publish(
int $obj_id,
string $type): void
85 if ($this->throw_error_on_publish_obj_id === $obj_id) {
86 throw new \ilMDOERHarvesterException(
'error');
88 $this->exposed_published_objects[] = [$obj_id, $type];
94 bool $automatic_publishing_enabled =
false,
95 bool $editorial_step_enabled =
false,
97 array $copyright_ids = [],
98 int $publishing_container_ref_id = 0
101 $automatic_publishing_enabled,
102 $editorial_step_enabled,
105 $publishing_container_ref_id
108 protected bool $automatic_publishing_enabled,
109 protected bool $editorial_step_enabled,
110 protected array $types,
111 protected array $copyright_ids,
112 protected
int $publishing_container_ref_id
116 public function isAutomaticPublishingEnabled(): bool
118 return $this->automatic_publishing_enabled;
121 public function isEditorialStepEnabled(): bool
123 return $this->editorial_step_enabled;
126 public function getObjectTypesSelectedForPublishing(): array
131 public function getCopyrightEntryIDsSelectedForPublishing(): array
133 return $this->copyright_ids;
136 public function getContainerRefIDForPublishing():
int
138 return $this->publishing_container_ref_id;
144 array $deleted_obj_ids = [],
145 int $valid_publishing_container = 0,
146 array $ref_ids_in_container = [],
147 array $deleted_ref_ids = []
151 $valid_publishing_container,
152 $ref_ids_in_container,
154 ) extends NullObjectHandler {
156 protected array $deleted_obj_ids,
157 protected
int $valid_publishing_container,
158 protected array $ref_ids_in_container,
159 protected array $deleted_ref_ids
163 public function doesReferenceExist(
int $ref_id): bool
165 return !in_array(
$ref_id, $this->deleted_ref_ids);
168 public function isObjectDeleted(
int $obj_id): bool
170 return in_array($obj_id, $this->deleted_obj_ids);
173 public function isReferenceInContainer(
int $ref_id,
int $container_ref_id): bool
175 if ($container_ref_id !== $this->valid_publishing_container) {
178 return in_array(
$ref_id, $this->ref_ids_in_container);
181 public function getTypeOfObject(
int $obj_id): string
183 return 'type_' . $obj_id;
192 array $currently_harvested = [],
193 array $blocked_obj_ids = [],
194 bool $throw_error =
false
195 ): StatusRepository {
196 return new class ($currently_harvested, $blocked_obj_ids, $throw_error) extends NullStatusRepository {
198 protected array $currently_harvested,
199 protected array $blocked_obj_ids,
200 protected bool $throw_error
204 public function getAllHarvestedObjIDs(): \Generator
206 if ($this->throw_error ===
true) {
207 throw new \ilMDOERHarvesterException(
'error');
209 yield
from array_keys($this->currently_harvested);
212 public function filterOutBlockedObjects(
int ...$obj_ids): \Generator
214 foreach ($obj_ids as $obj_id) {
215 if (!in_array($obj_id, $this->blocked_obj_ids)) {
221 public function getHarvestRefID(
int $obj_id):
int
223 return $this->currently_harvested[$obj_id] ?? 0;
234 array $returned_records = [],
235 array $deleted_records = []
236 ): ExposedRecordRepository {
237 return new class ($returned_records, $deleted_records) extends NullExposedRecordRepository {
238 public array $exposed_deletions = [];
239 public array $exposed_updates = [];
242 protected array $returned_records,
243 protected array $deleted_records
247 public function getRecords(
248 ?\DateTimeImmutable $from =
null,
249 ?\DateTimeImmutable $until =
null,
253 foreach ($this->returned_records as $obj_id => $metadata) {
254 $is_deleted = in_array($obj_id, $this->deleted_records);
255 yield
new class ($obj_id, $is_deleted, $metadata) extends
NullRecord {
257 protected int $obj_id,
258 protected bool $is_deleted,
259 protected ?
string $metadata
263 public function infos(): RecordInfosInterface
265 return new class ($this->obj_id, $this->is_deleted) extends NullRecordInfos {
267 protected int $obj_id,
268 protected bool $is_deleted
272 public function objID():
int
274 return $this->obj_id;
277 public function isDeleted(): bool
279 return $this->is_deleted;
284 public function metadata(): ?\DOMDocument
286 if ($this->metadata ===
null) {
289 $xml = new \DOMDocument();
290 $xml->loadXML($this->metadata);
297 public function deleteRecordsMarkedAsDeletedOlderThan(\DateInterval $interval): void
299 $this->exposed_deletions[] = [
'interval' => $interval];
302 public function updateRecord(
int $obj_id,
bool $is_deleted, ?\DOMDocument $metadata): void
304 $this->exposed_updates[] = [
306 'deleted' => $is_deleted,
307 'metadata' => $metadata?->saveXML()
315 return new class ($search_result_obj_ids) extends
NullFactory {
316 public array $exposed_search_params;
318 public function __construct(
public array $search_result_obj_ids)
325 protected array $types = [];
326 protected bool $restricted_to_repository =
false;
328 public function __construct(
protected SearchFactory $factory)
332 public function withRestrictionToRepositoryObjects(
bool $restricted):
SearcherInterface
334 $clone = clone $this;
335 $clone->restricted_to_repository = $restricted;
341 $clone = clone $this;
342 $clone->types[] = $type;
347 LOMRepository $lom_repository,
349 int ...$further_entry_ids
351 $this->
factory->exposed_search_params[] = [
352 'restricted' => $this->restricted_to_repository,
353 'types' => $this->types,
354 'entries' => [$first_entry_id, ...$further_entry_ids]
356 foreach ($this->
factory->search_result_obj_ids as $obj_id) {
362 public function objID():
int
364 return $this->obj_id;
377 protected function getXMLWriter(array $returned_md = []): SimpleDCXMLWriter
379 return new class ($returned_md) extends
NullWriter {
380 public array $exposed_params = [];
382 public function __construct(
protected array $returned_md)
386 public function writeSimpleDCMetaData(
int $obj_id,
int $ref_id,
string $type): \DOMDocument
388 $this->exposed_params[] = [
394 $xml = new \DOMDocument();
395 $xml->loadXML($this->returned_md[$obj_id]);
403 return $this->createMock(\ilLogger::class);
409 public int $exposed_status;
410 public string $exposed_message;
414 $clone = clone $this;
415 $clone->exposed_message = $message;
421 $clone = clone $this;
422 $clone->exposed_status = $status;
431 $publisher = $this->getPublisher(),
432 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
433 $this->getObjectHandler(),
434 $this->getStatusRepository([32 => 12332, 45 => 12345]),
435 $this->getExposedRecordRepository(),
436 $search_factory = $this->getSearchFactory(45),
437 new NullLOMRepository(),
438 $this->getXMLWriter(),
439 $this->getNullLogger()
442 $result = $harvester->run($this->getCronResultWrapper());
444 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
446 'Withdrew 1 deprecated objects.<br>' .
447 'Updated 0 published objects.',
448 $result->exposed_message
451 [[
'restricted' =>
true,
'types' => [
'type',
'second type'],
'entries' => [12, 5]]],
452 $search_factory->exposed_search_params
454 $this->assertSame([32], $publisher->exposed_withdrawn_objects);
460 $publisher = $this->getPublisher(),
461 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
462 $this->getObjectHandler(),
463 $this->getStatusRepository([32 => 12332, 45 => 12345], [32]),
464 $this->getExposedRecordRepository(),
465 $this->getSearchFactory(45, 32),
466 new NullLOMRepository(),
467 $this->getXMLWriter(),
468 $this->getNullLogger()
471 $result = $harvester->run($this->getCronResultWrapper());
473 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
475 'Withdrew 1 deprecated objects.<br>' .
476 'Updated 0 published objects.',
477 $result->exposed_message
479 $this->assertSame([32], $publisher->exposed_withdrawn_objects);
485 $publisher = $this->getPublisher(),
486 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
487 $this->getObjectHandler([32]),
488 $this->getStatusRepository([32 => 12332, 45 => 12345]),
489 $this->getExposedRecordRepository(),
490 $this->getSearchFactory(45, 32),
491 new NullLOMRepository(),
492 $this->getXMLWriter(),
493 $this->getNullLogger()
496 $result = $harvester->run($this->getCronResultWrapper());
498 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
500 'Withdrew 1 deprecated objects.<br>' .
501 'Updated 0 published objects.',
502 $result->exposed_message
504 $this->assertSame([32], $publisher->exposed_withdrawn_objects);
510 $publisher = $this->getPublisher(),
511 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
512 $this->getObjectHandler([], 0, [], [12332]),
513 $this->getStatusRepository([32 => 12332, 45 => 12345]),
514 $this->getExposedRecordRepository(),
515 $this->getSearchFactory(45, 32),
516 new NullLOMRepository(),
517 $this->getXMLWriter(),
518 $this->getNullLogger()
521 $result = $harvester->run($this->getCronResultWrapper());
523 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
525 'Withdrew 1 deprecated objects.<br>' .
526 'Updated 0 published objects.',
527 $result->exposed_message
529 $this->assertSame([32], $publisher->exposed_withdrawn_objects);
535 $publisher = $this->getPublisher(45),
536 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
537 $this->getObjectHandler(),
538 $this->getStatusRepository([32 => 12332, 45 => 12345, 67 => 12367]),
539 $this->getExposedRecordRepository(),
540 $this->getSearchFactory(),
541 new NullLOMRepository(),
542 $this->getXMLWriter(),
543 $this->getNullLogger()
546 $result = $harvester->run($this->getCronResultWrapper());
548 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
550 'Withdrew 2 deprecated objects.<br>' .
551 'Updated 0 published objects.',
552 $result->exposed_message
554 $this->assertSame([32, 67], $publisher->exposed_withdrawn_objects);
560 $publisher = $this->getPublisher(),
561 $this->getSettings(
true,
false, [
'type',
'second type'], [12, 5], 123),
562 $this->getObjectHandler(),
563 $this->getStatusRepository([32 => 12332]),
564 $this->getExposedRecordRepository(),
565 $search_factory = $this->getSearchFactory(32, 45),
566 new NullLOMRepository(),
567 $this->getXMLWriter(),
568 $this->getNullLogger()
571 $result = $harvester->run($this->getCronResultWrapper());
573 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
575 'Withdrew 0 deprecated objects.<br>' .
576 'Updated 0 published objects.<br>' .
577 'Published or submitted for review 1 new objects.',
578 $result->exposed_message
582 'restricted' =>
true,
583 'types' => [
'type',
'second type'],
586 $search_factory->exposed_search_params
588 $this->assertSame([[45,
'type_45']], $publisher->exposed_published_objects);
594 $publisher = $this->getPublisher(),
595 $this->getSettings(
true,
true, [
'type',
'second type'], [12, 5], 123),
596 $this->getObjectHandler(),
597 $this->getStatusRepository([32 => 12332]),
598 $this->getExposedRecordRepository(),
599 $search_factory = $this->getSearchFactory(32, 45),
600 new NullLOMRepository(),
601 $this->getXMLWriter(),
602 $this->getNullLogger()
605 $result = $harvester->run($this->getCronResultWrapper());
607 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
609 'Withdrew 0 deprecated objects.<br>' .
610 'Updated 0 published objects.<br>' .
611 'Published or submitted for review 1 new objects.',
612 $result->exposed_message
616 'restricted' =>
true,
617 'types' => [
'type',
'second type'],
620 $search_factory->exposed_search_params
622 $this->assertSame([45], $publisher->exposed_submitted_objects);
628 $publisher = $this->getPublisher(),
629 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5], 123),
630 $this->getObjectHandler(),
631 $this->getStatusRepository([32 => 12332]),
632 $this->getExposedRecordRepository(),
633 $this->getSearchFactory(32, 45),
634 new NullLOMRepository(),
635 $this->getXMLWriter(),
636 $this->getNullLogger()
639 $result = $harvester->run($this->getCronResultWrapper());
641 $this->assertSame(JobResult::STATUS_NO_ACTION, $result->exposed_status);
643 'Withdrew 0 deprecated objects.<br>' .
644 'Updated 0 published objects.',
645 $result->exposed_message
647 $this->assertEmpty($publisher->exposed_published_objects);
653 $publisher = $this->getPublisher(),
654 $this->getSettings(
true,
false, [
'type',
'second type'], [12, 5], 123),
655 $this->getObjectHandler(),
656 $this->getStatusRepository([32 => 12332], [45]),
657 $this->getExposedRecordRepository(),
658 $this->getSearchFactory(32, 45),
659 new NullLOMRepository(),
660 $this->getXMLWriter(),
661 $this->getNullLogger()
664 $result = $harvester->run($this->getCronResultWrapper());
666 $this->assertSame(JobResult::STATUS_NO_ACTION, $result->exposed_status);
668 'Withdrew 0 deprecated objects.<br>' .
669 'Updated 0 published objects.<br>' .
670 'Published or submitted for review 0 new objects.',
671 $result->exposed_message
673 $this->assertEmpty($publisher->exposed_published_objects);
679 $publisher = $this->getPublisher(),
680 $this->getSettings(
true,
false, [
'type',
'second type'], [12, 5], 123),
681 $this->getObjectHandler([45]),
682 $this->getStatusRepository([32 => 12332]),
683 $this->getExposedRecordRepository(),
684 $this->getSearchFactory(32, 45),
685 new NullLOMRepository(),
686 $this->getXMLWriter(),
687 $this->getNullLogger()
690 $result = $harvester->run($this->getCronResultWrapper());
692 $this->assertSame(JobResult::STATUS_NO_ACTION, $result->exposed_status);
694 'Withdrew 0 deprecated objects.<br>' .
695 'Updated 0 published objects.<br>' .
696 'Published or submitted for review 0 new objects.',
697 $result->exposed_message
699 $this->assertEmpty($publisher->exposed_published_objects);
705 $publisher = $this->getPublisher(),
706 $this->getSettings(
true,
false, [
'type',
'second type'], [12, 5], 123),
707 $this->getObjectHandler(),
708 $this->getStatusRepository([32 => 12332, 45 => 12345]),
709 $this->getExposedRecordRepository(),
710 $this->getSearchFactory(32, 45),
711 new NullLOMRepository(),
712 $this->getXMLWriter(),
713 $this->getNullLogger()
716 $result = $harvester->run($this->getCronResultWrapper());
718 $this->assertSame(JobResult::STATUS_NO_ACTION, $result->exposed_status);
720 'Withdrew 0 deprecated objects.<br>' .
721 'Updated 0 published objects.<br>' .
722 'Published or submitted for review 0 new objects.',
723 $result->exposed_message
725 $this->assertEmpty($publisher->exposed_published_objects);
731 $publisher = $this->getPublisher(
null, 45),
732 $this->getSettings(
true,
false, [
'type',
'second type'], [12, 5], 123),
733 $this->getObjectHandler(),
734 $this->getStatusRepository(),
735 $this->getExposedRecordRepository(),
736 $this->getSearchFactory(32, 45, 67),
737 new NullLOMRepository(),
738 $this->getXMLWriter(),
739 $this->getNullLogger()
742 $result = $harvester->run($this->getCronResultWrapper());
744 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
746 'Withdrew 0 deprecated objects.<br>' .
747 'Updated 0 published objects.<br>' .
748 'Published or submitted for review 2 new objects.',
749 $result->exposed_message
754 ], $publisher->exposed_published_objects);
760 $this->getPublisher(),
761 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5], 123),
762 $this->getObjectHandler([], 123, [12332, 12345]),
763 $this->getStatusRepository([32 => 12332, 45 => 12345]),
764 $record_repo = $this->getExposedRecordRepository([32 =>
'<el>32</el>', 45 =>
'<el>45</el>']),
765 $this->getSearchFactory(32, 45),
766 new NullLOMRepository(),
767 $writer = $this->getXMLWriter([32 =>
'<el>32</el>', 45 =>
'<el>45 changed</el>']),
768 $this->getNullLogger()
771 $result = $harvester->run($this->getCronResultWrapper());
773 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
775 'Withdrew 0 deprecated objects.<br>' .
776 'Updated 1 published objects.',
777 $result->exposed_message
779 $this->assertCount(1, $record_repo->exposed_updates);
780 $this->assertSame(45, $record_repo->exposed_updates[0][
'obj_id']);
781 $this->assertSame(
false, $record_repo->exposed_updates[0][
'deleted']);
782 $this->assertXmlStringEqualsXmlString(
783 '<el>45 changed</el>',
784 $record_repo->exposed_updates[0][
'metadata']
788 [
'obj_id' => 32,
'ref_id' => 12332,
'type' =>
'type_32'],
789 [
'obj_id' => 45,
'ref_id' => 12345,
'type' =>
'type_45']
791 $writer->exposed_params
793 $this->assertCount(1, $record_repo->exposed_deletions);
799 $this->getPublisher(),
800 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5], 123),
801 $this->getObjectHandler([], 123, [12332, 12345]),
802 $this->getStatusRepository([32 => 12332, 45 => 12345]),
803 $record_repo = $this->getExposedRecordRepository([32 =>
'<el>32</el>', 45 =>
null], [45]),
804 $this->getSearchFactory(32, 45),
805 new NullLOMRepository(),
806 $writer = $this->getXMLWriter([32 =>
'<el>32</el>', 45 =>
'<el>45 changed</el>']),
807 $this->getNullLogger()
810 $result = $harvester->run($this->getCronResultWrapper());
812 $this->assertSame(JobResult::STATUS_OK, $result->exposed_status);
814 'Withdrew 0 deprecated objects.<br>' .
815 'Updated 1 published objects.',
816 $result->exposed_message
818 $this->assertCount(1, $record_repo->exposed_updates);
819 $this->assertSame(45, $record_repo->exposed_updates[0][
'obj_id']);
820 $this->assertSame(
false, $record_repo->exposed_updates[0][
'deleted']);
821 $this->assertXmlStringEqualsXmlString(
822 '<el>45 changed</el>',
823 $record_repo->exposed_updates[0][
'metadata']
827 [
'obj_id' => 32,
'ref_id' => 12332,
'type' =>
'type_32'],
828 [
'obj_id' => 45,
'ref_id' => 12345,
'type' =>
'type_45']
830 $writer->exposed_params
832 $this->assertCount(1, $record_repo->exposed_deletions);
838 $this->getPublisher(),
839 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5], 123),
840 $this->getObjectHandler([], 123, [12332]),
841 $this->getStatusRepository([32 => 12332]),
842 $record_repo = $this->getExposedRecordRepository([32 =>
'<el>32</el>', 45 =>
null], [45]),
843 $this->getSearchFactory(32),
844 new NullLOMRepository(),
845 $this->getXMLWriter([32 =>
'<el>32</el>', 45 =>
'<el>45 changed</el>']),
846 $this->getNullLogger()
849 $result = $harvester->run($this->getCronResultWrapper());
851 $this->assertSame(JobResult::STATUS_NO_ACTION, $result->exposed_status);
853 'Withdrew 0 deprecated objects.<br>' .
854 'Updated 0 published objects.',
855 $result->exposed_message
857 $this->assertEmpty($record_repo->exposed_updates);
858 $this->assertCount(1, $record_repo->exposed_deletions);
864 $this->getPublisher(),
865 $this->getSettings(
false,
false, [
'type',
'second type'], [12, 5]),
866 $this->getObjectHandler(),
867 $this->getStatusRepository([], [],
true),
868 $this->getExposedRecordRepository(),
869 $this->getSearchFactory(),
870 new NullLOMRepository(),
871 $this->getXMLWriter(),
872 $this->getNullLogger()
875 $result = $harvester->run($this->getCronResultWrapper());
877 $this->assertSame(JobResult::STATUS_FAIL, $result->exposed_status);
880 $result->exposed_message
__construct()
Constructor setup ILIAS global object @access public.
Component logger with individual log levels by component id.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc