From 7751598eeedac3e6caf9cc3c5de4fa94a2ec8ac0 Mon Sep 17 00:00:00 2001 From: j3nsch Date: Thu, 21 Mar 2024 16:50:25 +0100 Subject: [PATCH] #345 Support multiple PublicationState values in DocumentFinder --- library/Opus/DocumentFinder.php | 10 +++++++--- tests/Opus/DocumentFinderTest.php | 32 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/library/Opus/DocumentFinder.php b/library/Opus/DocumentFinder.php index d32de7df..0bd08933 100644 --- a/library/Opus/DocumentFinder.php +++ b/library/Opus/DocumentFinder.php @@ -696,7 +696,7 @@ public function setSubSelectNotExists($select) } /** - * Only return documents with at leat one file marked as visible in oai. + * Only return documents with at least one file marked as visible in oai. * * @return $this Fluent interface. */ @@ -803,12 +803,16 @@ public function setNotInXmlCache() /** * Add PublicationState constraints to be applied on the result set. * - * @param string $state + * @param string|string[] $state * @return $this Fluent interface. */ public function setPublicationState($state) { - $this->_select->where('d.publication_state = ?', $state); + if (is_array($state)) { + $this->_select->where('d.publication_state IN (?)', $state); + } else { + $this->_select->where('d.publication_state = ?', $state); + } return $this; } } diff --git a/tests/Opus/DocumentFinderTest.php b/tests/Opus/DocumentFinderTest.php index d5ad005a..7348570f 100644 --- a/tests/Opus/DocumentFinderTest.php +++ b/tests/Opus/DocumentFinderTest.php @@ -947,8 +947,40 @@ public function testSetPublicationState() $finder = new DefaultDocumentFinder(); $finder->setPublicationState(PublicationState::SUBMITTED); + $result = $finder->getIds(); $this->assertCount(1, $result); $this->assertContains($docId, $result); } + + public function testSetPublicationStateMultipleValues() + { + $doc = Document::new(); + $doc->setPublicationState(PublicationState::SUBMITTED); + $docId1 = $doc->store(); + + $doc = Document::new(); + $doc->setPublicationState(PublicationState::PUBLISHED); + $docId2 = $doc->store(); + + $doc = Document::new(); + $doc->setPublicationState(PublicationState::ENHANCED); + $doc->store(); + + $finder = new DefaultDocumentFinder(); + + $finder->setPublicationState(PublicationState::SUBMITTED); + $result = $finder->getIds(); + $this->assertCount(1, $result); + $this->assertContains($docId1, $result); + + $finder = new DefaultDocumentFinder(); + + $finder->setPublicationState([PublicationState::SUBMITTED, PublicationState::PUBLISHED]); + + $result = $finder->getIds(); + $this->assertCount(2, $result); + $this->assertContains($docId1, $result); + $this->assertContains($docId2, $result); + } }