Skip to content

Commit

Permalink
MetaData: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Sep 26, 2024
1 parent 1eb4c45 commit 7f79d4d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Services/MetaData/test/Copyright/Search/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
use ILIAS\MetaData\Paths\NullFactory as NullPathFactory;
use ILIAS\MetaData\Search\Clauses\NullFactory as NullClauseFactory;
use ILIAS\MetaData\Search\Filters\NullFactory as NullFilterFactory;
use ILIAS\MetaData\Repository\NullRepository;

class FactoryTest extends TestCase
{
public function testGet(): void
{
$factory = new Factory(
new NullRepository(),
new NullFilterFactory(),
new NullClauseFactory(),
new NullPathFactory(),
Expand Down
18 changes: 6 additions & 12 deletions Services/MetaData/test/Copyright/Search/SearcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ public function buildIdentifierFromEntryID(int $entry_id): string
public function testSearch(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
$this->getIdentifierHandler()
);

$results = $searcher->search(32);
$results = $searcher->search($repo = $this->getLOMRepository(), 32);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand All @@ -240,14 +239,13 @@ public function testSearch(): void
public function testSearchWithMultipleEntries(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
$this->getIdentifierHandler()
);

$results = $searcher->search(32, 9, 1234);
$results = $searcher->search($repo = $this->getLOMRepository(), 32, 9, 1234);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand Down Expand Up @@ -286,15 +284,14 @@ public function testSearchWithMultipleEntries(): void
public function testSearchRestrictedToRepositoryObjects(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
$this->getIdentifierHandler()
);

$results = $searcher->withRestrictionToRepositoryObjects(true)
->search(32);
->search($repo = $this->getLOMRepository(), 32);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand Down Expand Up @@ -322,15 +319,14 @@ public function testSearchRestrictedToRepositoryObjects(): void
public function testSearchRestrictedToObjectType(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
$this->getIdentifierHandler()
);

$results = $searcher->withAdditionalTypeFilter('some type')
->search(32);
->search($repo = $this->getLOMRepository(), 32);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand Down Expand Up @@ -358,7 +354,6 @@ public function testSearchRestrictedToObjectType(): void
public function testSearchRestrictedToMultipleObjectTypes(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
Expand All @@ -368,7 +363,7 @@ public function testSearchRestrictedToMultipleObjectTypes(): void
$results = $searcher->withAdditionalTypeFilter('some type')
->withAdditionalTypeFilter('some other type')
->withAdditionalTypeFilter('a third type')
->search(32);
->search($repo = $this->getLOMRepository(), 32);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand Down Expand Up @@ -406,7 +401,6 @@ public function testSearchRestrictedToMultipleObjectTypes(): void
public function testSearchRestrictedToMultipleObjectTypesAndRepositoryObjects(): void
{
$searcher = new Searcher(
$repo = $this->getLOMRepository(),
$this->getSearchFilterFactory(),
$this->getSearchClauseFactory(),
$this->getPathFactory(),
Expand All @@ -417,7 +411,7 @@ public function testSearchRestrictedToMultipleObjectTypesAndRepositoryObjects():
->withAdditionalTypeFilter('some other type')
->withAdditionalTypeFilter('a third type')
->withRestrictionToRepositoryObjects(true)
->search(32);
->search($repo = $this->getLOMRepository(), 32);

$this->assertCorrectSearchResults(...$results);
$this->assertEquals(
Expand Down
37 changes: 31 additions & 6 deletions Services/MetaData/test/OERHarvester/HarvesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
use ILIAS\MetaData\OERHarvester\ExposedRecords\NullRecordInfos;
use ILIAS\MetaData\OERHarvester\Results\WrapperInterface;
use ILIAS\MetaData\OERHarvester\Results\NullWrapper;
use ilMDOERHarvesterException;
use ILIAS\MetaData\Repository\RepositoryInterface as LOMRepository;
use ILIAS\MetaData\Repository\NullRepository as NullLOMRepository;

class HarvesterTest extends TestCase
{
Expand Down Expand Up @@ -120,7 +121,7 @@ public function __construct(
public function referenceObjectInTargetContainer(int $obj_id, int $container_ref_id): int
{
if ($obj_id === $this->throw_error_on_ref_creation_obj_id) {
throw new ilMDOERHarvesterException('error');
throw new \ilMDOERHarvesterException('error');
}
$new_ref_id = (int) ($container_ref_id . $obj_id);
$this->exposed_ref_creations[] = [
Expand All @@ -147,7 +148,7 @@ public function isObjectDeleted(int $obj_id): bool
public function deleteReference(int $ref_id): void
{
if ($ref_id === $this->throw_error_on_deletion_ref_id) {
throw new ilMDOERHarvesterException('error');
throw new \ilMDOERHarvesterException('error');
}
$this->exposed_ref_deletions[] = $ref_id;
}
Expand Down Expand Up @@ -181,7 +182,7 @@ public function __construct(
public function getAllHarvestedObjIDs(): \Generator
{
if ($this->throw_error === true) {
throw new ilMDOERHarvesterException('error');
throw new \ilMDOERHarvesterException('error');
}
yield from array_keys($this->currently_harvested);
}
Expand Down Expand Up @@ -324,8 +325,11 @@ public function withAdditionalTypeFilter(string $type): SearcherInterface
return $clone;
}

public function search(int $first_entry_id, int ...$further_entry_ids): \Generator
{
public function search(
LOMRepository $lom_repository,
int $first_entry_id,
int ...$further_entry_ids
): \Generator {
$this->factory->exposed_search_params[] = [
'restricted' => $this->restricted_to_repository,
'types' => $this->types,
Expand Down Expand Up @@ -411,6 +415,7 @@ public function testRunDeleteDeprecatedReferenceIncorrectTypeOrCopyright(): void
$status_repo = $this->getStatusRepository([32 => 12332, 45 => 12345]),
$this->getExposedRecordRepository(),
$search_factory = $this->getSearchFactory(45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand Down Expand Up @@ -440,6 +445,7 @@ public function testRunDeleteDeprecatedReferenceBlocked(): void
$status_repo = $this->getStatusRepository([32 => 12332, 45 => 12345], [32]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(45, 32),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -465,6 +471,7 @@ public function testRunDeleteDeprecatedReferenceObjectDeleted(): void
$status_repo = $this->getStatusRepository([32 => 12332, 45 => 12345]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(45, 32),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -490,6 +497,7 @@ public function testRunDeleteDeprecatedReferenceContinueDespiteError(): void
$status_repo = $this->getStatusRepository([32 => 12332, 45 => 12345, 67 => 12367]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -515,6 +523,7 @@ public function testRunHarvestObject(): void
$status_repo = $this->getStatusRepository([32 => 12332]),
$this->getExposedRecordRepository(),
$search_factory = $this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand Down Expand Up @@ -554,6 +563,7 @@ public function testRunDoNotHarvestBlockedObject(): void
$status_repo = $this->getStatusRepository([32 => 12332], [45]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -579,6 +589,7 @@ public function testRunDoNotHarvestDeletedObject(): void
$status_repo = $this->getStatusRepository([32 => 12332]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -604,6 +615,7 @@ public function testRunDoNotHarvestAlreadyHarvestedObject(): void
$status_repo = $this->getStatusRepository([32 => 12332, 45 => 12345]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -629,6 +641,7 @@ public function testRunDoNotHarvestIfNoTargetContainerIsSet(): void
$status_repo = $this->getStatusRepository([32 => 12332]),
$this->getExposedRecordRepository(),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand All @@ -654,6 +667,7 @@ public function testRunHarvestObjectContinueDespiteError(): void
$status_repo = $this->getStatusRepository(),
$this->getExposedRecordRepository(),
$this->getSearchFactory(32, 45, 67),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand Down Expand Up @@ -691,6 +705,7 @@ public function testRunDeleteExposedRecordIncorrectTypeOrCopyright(): void
$this->getStatusRepository([32 => 12332]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>', 45 => '<el>45</el>']),
$search_factory = $this->getSearchFactory(32),
new NullLOMRepository(),
$this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -728,6 +743,7 @@ public function testRunDeleteExposedRecordBlocked(): void
$this->getStatusRepository([32 => 12332], [45]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -757,6 +773,7 @@ public function testRunDeleteExposedRecordObjectDeleted(): void
$this->getStatusRepository([32 => 12332]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -786,6 +803,7 @@ public function testRunDeleteExposedRecordNotInSourceContainer(): void
$this->getStatusRepository([32 => 12332, 45 => 12345]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -815,6 +833,7 @@ public function testRunUpdateExposedRecord(): void
$this->getStatusRepository([32 => 12332, 45 => 12345]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>', 45 => '<el>45</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 changed</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -853,6 +872,7 @@ public function testRunCreateNewExposedRecord(): void
$this->getStatusRepository([32 => 12332, 45 => 12345]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 new</el>']),
$this->getNullLogger()
);
Expand Down Expand Up @@ -892,6 +912,7 @@ public function testRunDoNotCreateNewExposedRecordWhenBlocked(): void
$this->getStatusRepository([32 => 12332], [45]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 new</el>']),
$this->getNullLogger()
);
Expand All @@ -918,6 +939,7 @@ public function testRunDoNotCreateNewExposedRecordWhenObjectDeleted(): void
$this->getStatusRepository([32 => 12332]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 new</el>']),
$this->getNullLogger()
);
Expand All @@ -944,6 +966,7 @@ public function testRunDoNotCreateNewExposedRecordWhenNotInSourceContainer(): vo
$this->getStatusRepository([32 => 12332, 45 => 12345]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 new</el>']),
$this->getNullLogger()
);
Expand All @@ -970,6 +993,7 @@ public function testRunDoNotCreateNewExposedRecordWhenNoSourceContainerIsSet():
$this->getStatusRepository([32 => 12332, 45 => 12345]),
$record_repo = $this->getExposedRecordRepository([32 => '<el>32</el>']),
$this->getSearchFactory(32, 45),
new NullLOMRepository(),
$writer = $this->getXMLWriter([32 => '<el>32</el>', 45 => '<el>45 new</el>']),
$this->getNullLogger()
);
Expand All @@ -996,6 +1020,7 @@ public function testRunWithUnforeseenError(): void
$status_repo = $this->getStatusRepository([], [], true),
$this->getExposedRecordRepository(),
$search_factory = $this->getSearchFactory(),
new NullLOMRepository(),
$this->getXMLWriter(),
$this->getNullLogger()
);
Expand Down

0 comments on commit 7f79d4d

Please sign in to comment.