Skip to content

Commit

Permalink
#345 Support multiple PublicationState values in DocumentFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Mar 21, 2024
1 parent dafec6b commit 7751598
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 7 additions & 3 deletions library/Opus/DocumentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
32 changes: 32 additions & 0 deletions tests/Opus/DocumentFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7751598

Please sign in to comment.