From 7d0e6fa1707f3f6e109f5cd16761b15cae4271da Mon Sep 17 00:00:00 2001 From: haogatyp Date: Mon, 30 Jan 2023 10:35:57 +0100 Subject: [PATCH 1/9] Added additional repository functional test instead of unit tests. --- Tests/Fixtures/Repository/collections.xml | 120 +++++++++ Tests/Fixtures/Repository/mail.xml | 39 +++ Tests/Fixtures/Repository/metadata.xml | 229 ++++++++++++++++++ Tests/Fixtures/Repository/token.xml | 35 +++ .../Repository/CollectionRepsitoryTest.php | 172 +++++++++++++ .../Repository/MailRepsitoryTest.php | 47 ++++ .../Repository/MetatdataRepsitoryTest.php | 84 +++++++ .../Repository/TokenRepsitoryTest.php | 79 ++++++ 8 files changed, 805 insertions(+) create mode 100644 Tests/Fixtures/Repository/collections.xml create mode 100644 Tests/Fixtures/Repository/mail.xml create mode 100644 Tests/Fixtures/Repository/metadata.xml create mode 100644 Tests/Fixtures/Repository/token.xml create mode 100644 Tests/Functional/Repository/CollectionRepsitoryTest.php create mode 100644 Tests/Functional/Repository/MailRepsitoryTest.php create mode 100644 Tests/Functional/Repository/MetatdataRepsitoryTest.php create mode 100644 Tests/Functional/Repository/TokenRepsitoryTest.php diff --git a/Tests/Fixtures/Repository/collections.xml b/Tests/Fixtures/Repository/collections.xml new file mode 100644 index 000000000..3fd2b91fa --- /dev/null +++ b/Tests/Fixtures/Repository/collections.xml @@ -0,0 +1,120 @@ + + + + + 1101 + 20000 + 1631279509 + 1631279509 + 2 + 0 + 0 + 0 + + a:8:{s:5:"label";N;s:10:"index_name";N;s:8:"oai_name";N;s:11:"description";N;s:9:"documents";N;s:5:"owner";N;s:6:"status";N;s:16:"sys_language_uid";N;} + + 0 + + + 0 + 0 + + Musik + + music + + + 3 + 0 + 0 + 0 + + + + 1102 + 20000 + 1631279509 + 1631279509 + 2 + 0 + 0 + 0 + + a:8:{s:5:"label";N;s:10:"index_name";N;s:8:"oai_name";N;s:11:"description";N;s:9:"documents";N;s:5:"owner";N;s:6:"status";N;s:16:"sys_language_uid";N;} + + 0 + + + 0 + 0 + + collection-with-single-document + + collection-with-single-document + + + 4 + 0 + 0 + 0 + + + + 1103 + 20000 + 1631279509 + 1631279509 + 2 + 0 + 0 + 0 + + a:8:{s:5:"label";N;s:10:"index_name";N;s:8:"oai_name";N;s:11:"description";N;s:9:"documents";N;s:5:"owner";N;s:6:"status";N;s:16:"sys_language_uid";N;} + + 0 + + + 1 + 0 + + Geschichte + + history + + + 3 + 0 + 0 + 0 + + + + 1104 + 20000 + 1631279509 + 1631279509 + 2 + 0 + 0 + 0 + + a:8:{s:5:"label";N;s:10:"index_name";N;s:8:"oai_name";N;s:11:"description";N;s:9:"documents";N;s:5:"owner";N;s:6:"status";N;s:16:"sys_language_uid";N;} + + 0 + + + 1 + 0 + + bildende-kunst + + + + + 4 + 0 + 0 + 0 + + + diff --git a/Tests/Fixtures/Repository/mail.xml b/Tests/Fixtures/Repository/mail.xml new file mode 100644 index 000000000..6cfb51dad --- /dev/null +++ b/Tests/Fixtures/Repository/mail.xml @@ -0,0 +1,39 @@ + + + + 101 + 30000 + 0 + 10 + Mail + Name + + + + 102 + 30000 + 0 + 10 + Mail + Name + + + + 103 + 20000 + 0 + 10 + Mail + Name + + + + 104 + 20000 + 0 + 10 + Mail + Name + + + diff --git a/Tests/Fixtures/Repository/metadata.xml b/Tests/Fixtures/Repository/metadata.xml new file mode 100644 index 000000000..59ed8db30 --- /dev/null +++ b/Tests/Fixtures/Repository/metadata.xml @@ -0,0 +1,229 @@ + + + + 5001 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 32 + + + title + 1 + + + 0 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + + + + 5002 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 31 + + + collection + 1 + + + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 1 + 0 + + + + 5003 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 30 + + + untertitel + 1 + + + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + + + + 5004 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 29 + + + ort + 1 + + + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + + + + 5005 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 30 + + + autor + 1 + + + 0 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + + + + 5006 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 0 + 0 + + 0 + 30 + + + institution + 1 + + + 0 + 1 + 1 + 1 + 0 + 0 + 1 + 1 + 0 + + + + 5101 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 5001 + 5202 + concat(./mods:titleInfo/mods:nonSort," ",./mods:titleInfo/mods:title) + ./mods:titleInfo/mods:title + 0 + + + + 5102 + 20000 + 1638557803 + 1631532810 + 1 + 0 + 5002 + 5202 + ./mods:relatedItem[@type="series"]/mods:titleInfo/mods:title[@lang="ger"] + + 0 + + + + 5201 + 0 + 1638557803 + 1631532810 + 1 + 0 + ALTO + alto + http://www.loc.gov/standards/alto/ns-v2# + Kitodo\Dlf\Format\Alto + + + 5202 + 0 + 1638557803 + 1631532810 + 1 + 0 + MODS + mods + http://www.loc.gov/mods/v3 + Kitodo\Dlf\Format\Mods + + diff --git a/Tests/Fixtures/Repository/token.xml b/Tests/Fixtures/Repository/token.xml new file mode 100644 index 000000000..1d226f25b --- /dev/null +++ b/Tests/Fixtures/Repository/token.xml @@ -0,0 +1,35 @@ + + + + 101 + 20000 + 1631279509 + token101 + Options text 101 + ident1 + + + 102 + 20000 + 1631289509 + token102 + Options text 102 + ident1 + + + 103 + 20000 + 1631279509 + token103 + Options text 103 + ident1 + + + 104 + 20000 + 1631281509 + token104 + Options text 104 + ident1 + + diff --git a/Tests/Functional/Repository/CollectionRepsitoryTest.php b/Tests/Functional/Repository/CollectionRepsitoryTest.php new file mode 100644 index 000000000..0776d7253 --- /dev/null +++ b/Tests/Functional/Repository/CollectionRepsitoryTest.php @@ -0,0 +1,172 @@ +collectionRepository = $this->initializeRepository( + CollectionRepository::class, + 20000 + ); + + $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/collections.xml'); + } + + /** + * + * @group find + */ + public function canFindAllByUids(): void + { + $collections = $this->collectionRepository->findAllByUids([1101, 1102]); + $this->assertNotNull($collections); + $this->assertInstanceOf(QueryResult::class, $collections); + + $collectionsByLabel = []; + foreach ($collections as $collection) { + $collectionsByLabel[$collection->getLabel()] = $collection; + } + + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + } + + /** + * @test + * @group find + */ + public function canGetCollectionForMetadata(): void + { + $collections = $this->collectionRepository->getCollectionForMetadata("20000"); + $this->assertNotNull($collections); + $this->assertInstanceOf(QueryResult::class, $collections); + + $collectionsByLabel = []; + foreach ($collections as $collection) { + $collectionsByLabel[$collection->getLabel()] = $collection; + } + + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel); + } + + /** + * @param $settings + * @return array + */ + protected function findCollectionsBySettings($settings): array + { + $collections = $this->collectionRepository->findCollectionsBySettings($settings); + $this->assertNotNull($collections); + $this->assertInstanceOf(QueryResult::class, $collections); + + $collectionsByLabel = []; + foreach ($collections as $collection) { + $collectionsByLabel[$collection->getLabel()] = $collection; + } + + return $collectionsByLabel; + } + + /** + * @test + * @group find + */ + public function canFindCollectionsBySettings(): void + { + $collectionsByLabel = $this->findCollectionsBySettings(['collections' => '1101, 1102']); + $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings([ + 'index_name' => ['Geschichte', 'collection-with-single-document'], + 'show_userdefined' => true + ]); + $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => true]); + $this->assertEquals(4, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel); + $this->assertEquals( + 'Bildende Kunst, Collection with single document, Geschichte, Musik', + implode(', ', array_keys($collectionsByLabel)) + ); + + $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => false]); + $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings(['hideEmptyOaiNames' => true]); + $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings( + [ + 'hideEmptyOaiNames' => true, + 'show_userdefined' => true + ] + ); + $this->assertEquals(3, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings( + [ + 'hideEmptyOaiNames' => false, + 'show_userdefined' => true + ] + ); + $this->assertEquals(4, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Musik', $collectionsByLabel); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + $this->assertArrayHasKey('Bildende Kunst', $collectionsByLabel); + + $collectionsByLabel = $this->findCollectionsBySettings( + [ + 'collections' => '1101, 1102, 1103, 1104', + 'show_userdefined' => true, + 'hideEmptyOaiNames' => false, + 'index_name' => ['Geschichte', 'collection-with-single-document'] + ] + ); + + $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); + $this->assertArrayHasKey('Geschichte', $collectionsByLabel); + } + + /** + * @test + * @group find + */ + public function canGetIndexNameForSolr(): void + { + $indexName = $this->collectionRepository->getIndexNameForSolr(['show_userdefined' => true], 'history'); + //$indexName->fetchAllAssociativeIndexed(); + } +} diff --git a/Tests/Functional/Repository/MailRepsitoryTest.php b/Tests/Functional/Repository/MailRepsitoryTest.php new file mode 100644 index 000000000..331a0b8e2 --- /dev/null +++ b/Tests/Functional/Repository/MailRepsitoryTest.php @@ -0,0 +1,47 @@ +mailRepository = $this->initializeRepository( + MailRepository::class, + 20000 + ); + + $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/mail.xml'); + } + + /** + * @test + * @group find + */ + public function canFindAllWithPid(): void + { + $mails = $this->mailRepository->findAllWithPid(30000); + $this->assertNotNull($mails); + $this->assertInstanceOf(QueryResult::class, $mails); + + $mailByLabel = []; + foreach ($mails as $mail) { + $mailByLabel[$mail->getLabel()] = $mail; + } + + $this->assertEquals(2, $mails->count()); + $this->assertArrayHasKey('Mail-Label-1', $mailByLabel); + $this->assertArrayHasKey('Mail-Label-2', $mailByLabel); + } +} diff --git a/Tests/Functional/Repository/MetatdataRepsitoryTest.php b/Tests/Functional/Repository/MetatdataRepsitoryTest.php new file mode 100644 index 000000000..c5f756b85 --- /dev/null +++ b/Tests/Functional/Repository/MetatdataRepsitoryTest.php @@ -0,0 +1,84 @@ +metadataRepository = $this->initializeRepository( + MetadataRepository::class, + 20000 + ); + + $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/metadata.xml'); + } + + + /** + * @param $settings + * @return array + */ + protected function findBySettings($settings) + { + $metadata = $this->metadataRepository->findBySettings($settings); + $this->assertNotNull($metadata); + $this->assertInstanceOf(QueryResult::class, $metadata); + + $metadataByLabel = []; + foreach ($metadata as $mdata) { + $metadataByLabel[$mdata->getLabel()] = $mdata; + } + + return $metadataByLabel; + } + + /** + * @test + * @group find + */ + public function canFindBySettings(): void + { + $metadataByLabel = $this->findBySettings([]); + $this->assertEquals(6, sizeof($metadataByLabel)); + $this->assertEquals( + 'Ort, Untertitel, Autor, Institution, Sammlungen, Titel', + implode(', ', array_keys($metadataByLabel)) + ); + + $metadataByLabel = $this->findBySettings(['is_listed' => true]); + $this->assertEquals(3, sizeof($metadataByLabel)); + $this->assertEquals( + 'Autor, Institution, Titel', + implode(', ', array_keys($metadataByLabel)) + ); + + $metadataByLabel = $this->findBySettings(['is_sortable' => true]); + $this->assertEquals(4, sizeof($metadataByLabel)); + $this->assertEquals( + 'Ort, Untertitel, Autor, Titel', + implode(', ', array_keys($metadataByLabel)) + ); + + $metadataByLabel = $this->findBySettings([ + 'is_sortable' => true, + 'is_listed' => true + ]); + $this->assertEquals(2, sizeof($metadataByLabel)); + $this->assertEquals( + 'Autor, Titel', + implode(', ', array_keys($metadataByLabel)) + ); + } +} diff --git a/Tests/Functional/Repository/TokenRepsitoryTest.php b/Tests/Functional/Repository/TokenRepsitoryTest.php new file mode 100644 index 000000000..e87d7fb91 --- /dev/null +++ b/Tests/Functional/Repository/TokenRepsitoryTest.php @@ -0,0 +1,79 @@ +persistenceManager = $this->objectManager->get(PersistenceManager::class); + + $this->tokenRepository = $this->initializeRepository( + TokenRepository::class, + 20000 + ); + } + + public function tearDown(): void + { + parent::tearDown(); + + unlink(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); + } + + /** + * @test + * @group delete + */ + public function deleteExpiredTokens(): void + { + $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Repository/token.xml'); + + $expireTime = 3600; + $i = 1; + foreach ($xml as $node) { + if ($i % 2 == 0) { + $node->tstamp = time() - $expireTime - random_int(10, 3600); + } else { + $node->tstamp = time() - $expireTime + random_int(10, 3600); + } + $i++; + } + + $xml->saveXML(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); + + $this->importDataSet(__DIR__ . '/../../Fixtures/Repository/tokenTemp.xml'); + + $this->tokenRepository->deleteExpiredTokens($expireTime); + + $this->persistenceManager->persistAll(); + + $tokens = $this->tokenRepository->findAll(); + + $this->assertEquals(2, $tokens->count()); + + $tokenUids = []; + foreach ($tokens as $token) { + $tokenUids[$token->getUid()] = $token; + } + + $this->assertArrayHasKey('101', $tokenUids); + $this->assertArrayHasKey('103', $tokenUids); + } +} From f3ec970eddd7f9fc2c0e19dc94bc1756154bea69 Mon Sep 17 00:00:00 2001 From: haogatyp Date: Mon, 30 Jan 2023 12:43:13 +0100 Subject: [PATCH 2/9] Fix unused local variables due to missing test. --- Tests/Fixtures/Repository/collections.xml | 2 +- .../Repository/CollectionRepsitoryTest.php | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Tests/Fixtures/Repository/collections.xml b/Tests/Fixtures/Repository/collections.xml index 3fd2b91fa..56461434e 100644 --- a/Tests/Fixtures/Repository/collections.xml +++ b/Tests/Fixtures/Repository/collections.xml @@ -78,7 +78,7 @@ 0 Geschichte - + GeschichteSearch history diff --git a/Tests/Functional/Repository/CollectionRepsitoryTest.php b/Tests/Functional/Repository/CollectionRepsitoryTest.php index 0776d7253..506af4f95 100644 --- a/Tests/Functional/Repository/CollectionRepsitoryTest.php +++ b/Tests/Functional/Repository/CollectionRepsitoryTest.php @@ -166,7 +166,24 @@ public function canFindCollectionsBySettings(): void */ public function canGetIndexNameForSolr(): void { - $indexName = $this->collectionRepository->getIndexNameForSolr(['show_userdefined' => true], 'history'); - //$indexName->fetchAllAssociativeIndexed(); + $indexName = $this->collectionRepository->getIndexNameForSolr( + ['show_userdefined' => true, 'storagePid' => '20000'], 'history' + ); + $result = $indexName->fetchAllAssociative(); + $this->assertEquals(1, $indexName->rowCount()); + $this->assertEquals('Geschichte', $result[0]['index_name']); + $this->assertEquals('GeschichteSearch', $result[0]['index_query']); + $this->assertEquals('1103', $result[0]['uid']); + + $indexName = $this->collectionRepository->getIndexNameForSolr( + ['show_userdefined' => false, 'storagePid' => '20000'], 'history' + ); + $this->assertEquals(0, $indexName->rowCount()); + + $indexName = $this->collectionRepository->getIndexNameForSolr( + ['show_userdefined' => false, 'storagePid' => '20000'], 'collection-with-single-document' + ); + $this->assertEquals(1, $indexName->rowCount()); + $this->assertEquals('collection-with-single-document', $indexName->fetchOne()); } } From 4bc71f5e3c136b56306944780d8acb1218b5f5e0 Mon Sep 17 00:00:00 2001 From: haogatyp Date: Tue, 31 Jan 2023 13:44:11 +0100 Subject: [PATCH 3/9] Fix typos in test classes. --- ...CollectionRepsitoryTest.php => CollectionRepositoryTest.php} | 2 +- .../{MailRepsitoryTest.php => MailRepositoryTest.php} | 2 +- .../{MetatdataRepsitoryTest.php => MetatdataRepositoryTest.php} | 2 +- .../{TokenRepsitoryTest.php => TokenRepositoryTest.php} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename Tests/Functional/Repository/{CollectionRepsitoryTest.php => CollectionRepositoryTest.php} (99%) rename Tests/Functional/Repository/{MailRepsitoryTest.php => MailRepositoryTest.php} (95%) rename Tests/Functional/Repository/{MetatdataRepsitoryTest.php => MetatdataRepositoryTest.php} (97%) rename Tests/Functional/Repository/{TokenRepsitoryTest.php => TokenRepositoryTest.php} (97%) diff --git a/Tests/Functional/Repository/CollectionRepsitoryTest.php b/Tests/Functional/Repository/CollectionRepositoryTest.php similarity index 99% rename from Tests/Functional/Repository/CollectionRepsitoryTest.php rename to Tests/Functional/Repository/CollectionRepositoryTest.php index 506af4f95..dc8099f2a 100644 --- a/Tests/Functional/Repository/CollectionRepsitoryTest.php +++ b/Tests/Functional/Repository/CollectionRepositoryTest.php @@ -6,7 +6,7 @@ use Kitodo\Dlf\Domain\Repository\CollectionRepository; use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; -class CollectionRepsitoryTest extends FunctionalTestCase +class CollectionRepositoryTest extends FunctionalTestCase { /** * @var CollectionRepository diff --git a/Tests/Functional/Repository/MailRepsitoryTest.php b/Tests/Functional/Repository/MailRepositoryTest.php similarity index 95% rename from Tests/Functional/Repository/MailRepsitoryTest.php rename to Tests/Functional/Repository/MailRepositoryTest.php index 331a0b8e2..a30141867 100644 --- a/Tests/Functional/Repository/MailRepsitoryTest.php +++ b/Tests/Functional/Repository/MailRepositoryTest.php @@ -6,7 +6,7 @@ use Kitodo\Dlf\Domain\Repository\MailRepository; use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; -class MailRepsitoryTest extends FunctionalTestCase +class MailRepositoryTest extends FunctionalTestCase { /** * @var MailRepository diff --git a/Tests/Functional/Repository/MetatdataRepsitoryTest.php b/Tests/Functional/Repository/MetatdataRepositoryTest.php similarity index 97% rename from Tests/Functional/Repository/MetatdataRepsitoryTest.php rename to Tests/Functional/Repository/MetatdataRepositoryTest.php index c5f756b85..fe05e0ea1 100644 --- a/Tests/Functional/Repository/MetatdataRepsitoryTest.php +++ b/Tests/Functional/Repository/MetatdataRepositoryTest.php @@ -6,7 +6,7 @@ use Kitodo\Dlf\Domain\Repository\MetadataRepository; use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; -class MetadataRepsitoryTest extends FunctionalTestCase +class MetadataRepositoryTest extends FunctionalTestCase { /** * @var MetadataRepository diff --git a/Tests/Functional/Repository/TokenRepsitoryTest.php b/Tests/Functional/Repository/TokenRepositoryTest.php similarity index 97% rename from Tests/Functional/Repository/TokenRepsitoryTest.php rename to Tests/Functional/Repository/TokenRepositoryTest.php index e87d7fb91..35971aa9a 100644 --- a/Tests/Functional/Repository/TokenRepsitoryTest.php +++ b/Tests/Functional/Repository/TokenRepositoryTest.php @@ -6,7 +6,7 @@ use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; -class TokenRepsitoryTest extends FunctionalTestCase +class TokenRepositoryTest extends FunctionalTestCase { /** * @var TokenRepository From 81ac81e7fce12a2aa1ae800830f7706341a30a07 Mon Sep 17 00:00:00 2001 From: haogatyp Date: Thu, 2 Feb 2023 15:13:53 +0100 Subject: [PATCH 4/9] Fix invalid index_query in collection test data. --- Tests/Functional/Repository/CollectionRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/Repository/CollectionRepositoryTest.php b/Tests/Functional/Repository/CollectionRepositoryTest.php index dc8099f2a..b90c6244d 100644 --- a/Tests/Functional/Repository/CollectionRepositoryTest.php +++ b/Tests/Functional/Repository/CollectionRepositoryTest.php @@ -172,7 +172,7 @@ public function canGetIndexNameForSolr(): void $result = $indexName->fetchAllAssociative(); $this->assertEquals(1, $indexName->rowCount()); $this->assertEquals('Geschichte', $result[0]['index_name']); - $this->assertEquals('GeschichteSearch', $result[0]['index_query']); + $this->assertEquals('*:*', $result[0]['index_query']); $this->assertEquals('1103', $result[0]['uid']); $indexName = $this->collectionRepository->getIndexNameForSolr( From dc50a33d363c0109992cfede8044968f6d4963dd Mon Sep 17 00:00:00 2001 From: haogatyp Date: Fri, 3 Feb 2023 09:54:15 +0100 Subject: [PATCH 5/9] Fix incorrect value in collection fixture. --- Tests/Fixtures/Repository/collections.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Fixtures/Repository/collections.xml b/Tests/Fixtures/Repository/collections.xml index 56461434e..6e97285cc 100644 --- a/Tests/Fixtures/Repository/collections.xml +++ b/Tests/Fixtures/Repository/collections.xml @@ -78,7 +78,7 @@ 0 Geschichte - GeschichteSearch + *:* history From 3f795a7dd6efe1f5f7d230cfbe04766fa24929c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6hr?= Date: Thu, 26 Oct 2023 08:21:53 +0200 Subject: [PATCH 6/9] Update database --- Tests/Fixtures/Repository/collections.xml | 4 ---- Tests/Fixtures/Repository/metadata.xml | 6 ------ 2 files changed, 10 deletions(-) diff --git a/Tests/Fixtures/Repository/collections.xml b/Tests/Fixtures/Repository/collections.xml index 6e97285cc..cb42c2339 100644 --- a/Tests/Fixtures/Repository/collections.xml +++ b/Tests/Fixtures/Repository/collections.xml @@ -15,7 +15,6 @@ 0 - 0 0 @@ -44,7 +43,6 @@ 0 - 0 0 @@ -73,7 +71,6 @@ 0 - 1 0 @@ -102,7 +99,6 @@ 0 - 1 0 diff --git a/Tests/Fixtures/Repository/metadata.xml b/Tests/Fixtures/Repository/metadata.xml index 59ed8db30..5c012c908 100644 --- a/Tests/Fixtures/Repository/metadata.xml +++ b/Tests/Fixtures/Repository/metadata.xml @@ -12,7 +12,6 @@ 0 32 - title 1 @@ -41,7 +40,6 @@ 0 31 - collection 1 @@ -70,7 +68,6 @@ 0 30 - untertitel 1 @@ -99,7 +96,6 @@ 0 29 - ort 1 @@ -128,7 +124,6 @@ 0 30 - autor 1 @@ -157,7 +152,6 @@ 0 30 - institution 1 From bb18a1d8d3e9430abf09810e2af1791b0fbb10a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6hr?= Date: Thu, 26 Oct 2023 10:37:40 +0200 Subject: [PATCH 7/9] Fix code style --- .../Repository/CollectionRepositoryTest.php | 22 ++++++++++--------- .../Repository/MetatdataRepositoryTest.php | 8 +++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Tests/Functional/Repository/CollectionRepositoryTest.php b/Tests/Functional/Repository/CollectionRepositoryTest.php index b90c6244d..8b7ee79c7 100644 --- a/Tests/Functional/Repository/CollectionRepositoryTest.php +++ b/Tests/Functional/Repository/CollectionRepositoryTest.php @@ -90,20 +90,22 @@ protected function findCollectionsBySettings($settings): array public function canFindCollectionsBySettings(): void { $collectionsByLabel = $this->findCollectionsBySettings(['collections' => '1101, 1102']); - $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertCount(2, $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); - $collectionsByLabel = $this->findCollectionsBySettings([ + $collectionsByLabel = $this->findCollectionsBySettings( + [ 'index_name' => ['Geschichte', 'collection-with-single-document'], 'show_userdefined' => true - ]); - $this->assertEquals(2, sizeof($collectionsByLabel)); + ] + ); + $this->assertCount(2, $collectionsByLabel); $this->assertArrayHasKey('Geschichte', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => true]); - $this->assertEquals(4, sizeof($collectionsByLabel)); + $this->assertCount(4, $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $this->assertArrayHasKey('Geschichte', $collectionsByLabel); @@ -114,12 +116,12 @@ public function canFindCollectionsBySettings(): void ); $collectionsByLabel = $this->findCollectionsBySettings(['show_userdefined' => false]); - $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertCount(2, $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $collectionsByLabel = $this->findCollectionsBySettings(['hideEmptyOaiNames' => true]); - $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertCount(2, $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); @@ -129,7 +131,7 @@ public function canFindCollectionsBySettings(): void 'show_userdefined' => true ] ); - $this->assertEquals(3, sizeof($collectionsByLabel)); + $this->assertCount(3, $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $this->assertArrayHasKey('Geschichte', $collectionsByLabel); @@ -140,7 +142,7 @@ public function canFindCollectionsBySettings(): void 'show_userdefined' => true ] ); - $this->assertEquals(4, sizeof($collectionsByLabel)); + $this->assertCount(4, $collectionsByLabel); $this->assertArrayHasKey('Musik', $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $this->assertArrayHasKey('Geschichte', $collectionsByLabel); @@ -155,7 +157,7 @@ public function canFindCollectionsBySettings(): void ] ); - $this->assertEquals(2, sizeof($collectionsByLabel)); + $this->assertCount(2, $collectionsByLabel); $this->assertArrayHasKey('Collection with single document', $collectionsByLabel); $this->assertArrayHasKey('Geschichte', $collectionsByLabel); } diff --git a/Tests/Functional/Repository/MetatdataRepositoryTest.php b/Tests/Functional/Repository/MetatdataRepositoryTest.php index fe05e0ea1..845b1108c 100644 --- a/Tests/Functional/Repository/MetatdataRepositoryTest.php +++ b/Tests/Functional/Repository/MetatdataRepositoryTest.php @@ -51,21 +51,21 @@ protected function findBySettings($settings) public function canFindBySettings(): void { $metadataByLabel = $this->findBySettings([]); - $this->assertEquals(6, sizeof($metadataByLabel)); + $this->assertCount(6, $metadataByLabel); $this->assertEquals( 'Ort, Untertitel, Autor, Institution, Sammlungen, Titel', implode(', ', array_keys($metadataByLabel)) ); $metadataByLabel = $this->findBySettings(['is_listed' => true]); - $this->assertEquals(3, sizeof($metadataByLabel)); + $this->assertCount(3, $metadataByLabel); $this->assertEquals( 'Autor, Institution, Titel', implode(', ', array_keys($metadataByLabel)) ); $metadataByLabel = $this->findBySettings(['is_sortable' => true]); - $this->assertEquals(4, sizeof($metadataByLabel)); + $this->assertCount(4, $metadataByLabel); $this->assertEquals( 'Ort, Untertitel, Autor, Titel', implode(', ', array_keys($metadataByLabel)) @@ -75,7 +75,7 @@ public function canFindBySettings(): void 'is_sortable' => true, 'is_listed' => true ]); - $this->assertEquals(2, sizeof($metadataByLabel)); + $this->assertCount(2, $metadataByLabel); $this->assertEquals( 'Autor, Titel', implode(', ', array_keys($metadataByLabel)) From 9fe38c797fe925e61e6bd59f1b334e5c7bbf5655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6hr?= Date: Thu, 26 Oct 2023 10:41:37 +0200 Subject: [PATCH 8/9] Add license header --- Tests/Functional/Repository/CollectionRepositoryTest.php | 9 +++++++++ Tests/Functional/Repository/MailRepositoryTest.php | 9 +++++++++ Tests/Functional/Repository/MetatdataRepositoryTest.php | 9 +++++++++ Tests/Functional/Repository/TokenRepositoryTest.php | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/Tests/Functional/Repository/CollectionRepositoryTest.php b/Tests/Functional/Repository/CollectionRepositoryTest.php index 8b7ee79c7..c269cff46 100644 --- a/Tests/Functional/Repository/CollectionRepositoryTest.php +++ b/Tests/Functional/Repository/CollectionRepositoryTest.php @@ -1,4 +1,13 @@ + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ namespace Kitodo\Dlf\Tests\Functional\Repository; diff --git a/Tests/Functional/Repository/MailRepositoryTest.php b/Tests/Functional/Repository/MailRepositoryTest.php index a30141867..5aff084f7 100644 --- a/Tests/Functional/Repository/MailRepositoryTest.php +++ b/Tests/Functional/Repository/MailRepositoryTest.php @@ -1,4 +1,13 @@ + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ namespace Kitodo\Dlf\Tests\Functional\Repository; diff --git a/Tests/Functional/Repository/MetatdataRepositoryTest.php b/Tests/Functional/Repository/MetatdataRepositoryTest.php index 845b1108c..148646a3c 100644 --- a/Tests/Functional/Repository/MetatdataRepositoryTest.php +++ b/Tests/Functional/Repository/MetatdataRepositoryTest.php @@ -1,4 +1,13 @@ + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ namespace Kitodo\Dlf\Tests\Functional\Repository; diff --git a/Tests/Functional/Repository/TokenRepositoryTest.php b/Tests/Functional/Repository/TokenRepositoryTest.php index 35971aa9a..f30957a1e 100644 --- a/Tests/Functional/Repository/TokenRepositoryTest.php +++ b/Tests/Functional/Repository/TokenRepositoryTest.php @@ -1,4 +1,13 @@ + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ namespace Kitodo\Dlf\Tests\Functional\Repository; From ef27570cfe184cade9020f4fb3eeba15c7525a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6hr?= Date: Thu, 26 Oct 2023 13:33:24 +0200 Subject: [PATCH 9/9] Fix code style --- .../Functional/Repository/CollectionRepositoryTest.php | 4 ++-- .../Functional/Repository/MetatdataRepositoryTest.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Tests/Functional/Repository/CollectionRepositoryTest.php b/Tests/Functional/Repository/CollectionRepositoryTest.php index c269cff46..ac7149e6b 100644 --- a/Tests/Functional/Repository/CollectionRepositoryTest.php +++ b/Tests/Functional/Repository/CollectionRepositoryTest.php @@ -105,8 +105,8 @@ public function canFindCollectionsBySettings(): void $collectionsByLabel = $this->findCollectionsBySettings( [ - 'index_name' => ['Geschichte', 'collection-with-single-document'], - 'show_userdefined' => true + 'index_name' => ['Geschichte', 'collection-with-single-document'], + 'show_userdefined' => true ] ); $this->assertCount(2, $collectionsByLabel); diff --git a/Tests/Functional/Repository/MetatdataRepositoryTest.php b/Tests/Functional/Repository/MetatdataRepositoryTest.php index 148646a3c..0e78feec0 100644 --- a/Tests/Functional/Repository/MetatdataRepositoryTest.php +++ b/Tests/Functional/Repository/MetatdataRepositoryTest.php @@ -80,10 +80,12 @@ public function canFindBySettings(): void implode(', ', array_keys($metadataByLabel)) ); - $metadataByLabel = $this->findBySettings([ - 'is_sortable' => true, - 'is_listed' => true - ]); + $metadataByLabel = $this->findBySettings( + [ + 'is_sortable' => true, + 'is_listed' => true + ] + ); $this->assertCount(2, $metadataByLabel); $this->assertEquals( 'Autor, Titel',