diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/FolioTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/FolioTest.php
index cad97629d00..92afbb6adf4 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/FolioTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/FolioTest.php
@@ -703,16 +703,13 @@ public function testGetProxiedUsers(): void
}
/**
- * Test getHolding with HRID-based lookup
+ * Get expected result of get-holding fixture (shared by multiple tests).
*
- * @return void
+ * @return array
*/
- public function testGetHoldingWithHridLookup(): void
+ protected function getExpectedGetHoldingResult(): array
{
- $driverConfig = $this->defaultDriverConfig;
- $driverConfig['IDs']['type'] = 'hrid';
- $this->createConnector("get-holding", $driverConfig);
- $expected = [
+ return [
[
'callnumber_prefix' => '',
'callnumber' => 'PS2394 .M643 1883',
@@ -737,7 +734,19 @@ public function testGetHoldingWithHridLookup(): void
'addLink' => true,
],
];
- $this->assertEquals($expected, $this->driver->getHolding("foo"));
+ }
+
+ /**
+ * Test getHolding with HRID-based lookup
+ *
+ * @return void
+ */
+ public function testGetHoldingWithHridLookup(): void
+ {
+ $driverConfig = $this->defaultDriverConfig;
+ $driverConfig['IDs']['type'] = 'hrid';
+ $this->createConnector("get-holding", $driverConfig);
+ $this->assertEquals($this->getExpectedGetHoldingResult(), $this->driver->getHolding("foo"));
}
/**
@@ -752,34 +761,7 @@ public function testGetStatuses(): void
$driverConfig = $this->defaultDriverConfig;
$driverConfig['IDs']['type'] = 'hrid';
$this->createConnector("get-holding", $driverConfig);
- $expected = [
- [
- [
- 'callnumber_prefix' => '',
- 'callnumber' => 'PS2394 .M643 1883',
- 'id' => 'foo',
- 'item_id' => 'itemid',
- 'holding_id' => 'holdingid',
- 'number' => 1,
- 'enumchron' => '',
- 'barcode' => 'barcode-test',
- 'status' => 'Available',
- 'duedate' => '',
- 'availability' => true,
- 'is_holdable' => true,
- 'holdings_notes' => null,
- 'item_notes' => null,
- 'summary' => ["foo", "bar baz"],
- 'supplements' => [],
- 'indexes' => [],
- 'location' => 'Special Collections',
- 'location_code' => 'DCOC',
- 'reserve' => 'TODO',
- 'addLink' => true,
- ],
- ],
- ];
- $this->assertEquals($expected, $this->driver->getStatuses(["foo"]));
+ $this->assertEquals([$this->getExpectedGetHoldingResult()], $this->driver->getStatuses(["foo"]));
}
/**
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/RandomRecommendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/RandomRecommendTest.php
index 9cc33711b54..b0410434fb5 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/RandomRecommendTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/RandomRecommendTest.php
@@ -229,11 +229,13 @@ public function testCanInitialiseInDisregardMode()
}
/**
- * Test minimum result limit feature
+ * Get a module configured to return results.
*
- * @return void
+ * @param string $recConfig Recommendation module configuration
+ *
+ * @return Random
*/
- public function testWillReturnEmptyForMinimumResultLimit()
+ protected function getConfiguredModule($recConfig): Random
{
$service = $this->getMockBuilder(\VuFindSearch\Service::class)
->disableOriginalConstructor()->getMock();
@@ -273,9 +275,20 @@ public function testWillReturnEmptyForMinimumResultLimit()
->with($this->callback($checkCommand))
->will($this->returnValue($commandObj));
- $recommend->setConfig("Solr:10:mixed:retain:20:facet1:value1:facet2:value2");
+ $recommend->setConfig($recConfig);
$recommend->init($params, $request);
$recommend->process($results);
+ return $recommend;
+ }
+
+ /**
+ * Test minimum result limit feature
+ *
+ * @return void
+ */
+ public function testWillReturnEmptyForMinimumResultLimit()
+ {
+ $recommend = $this->getConfiguredModule("Solr:10:mixed:retain:20:facet1:value1:facet2:value2");
$output = $recommend->getResults();
$this->assertEmpty($output);
}
@@ -287,49 +300,9 @@ public function testWillReturnEmptyForMinimumResultLimit()
*/
public function testWillReturnResults()
{
- $service = $this->getMockBuilder(\VuFindSearch\Service::class)
- ->disableOriginalConstructor()->getMock();
- $paramManager = $this->createMock(\VuFind\Search\Params\PluginManager::class);
- $recommend = new Random($service, $paramManager);
- $records = ["1", "2", "3", "4", "5"];
-
- // Use Solr since some Base components are abstract:
- $results = $this->getSolrResults();
- $params = $results->getParams();
- $query = $this->unserializeFixture('query');
- $params->setBasicSearch($query->getString(), $query->getHandler());
- $request = $this->createMock(\Laminas\Stdlib\Parameters::class);
-
- $results = $this->getMockBuilder(\VuFindSearch\Response\RecordCollectionInterface::class)
- ->getMock();
-
- $results->expects($this->once())->method('getRecords')
- ->will($this->returnValue($records));
-
- $commandObj = $this->getMockBuilder(\VuFindSearch\Command\AbstractBase::class)
- ->disableOriginalConstructor()
- ->getMock();
- $commandObj->expects($this->once())->method('getResult')
- ->will($this->returnValue($results));
-
- $checkCommand = function ($command) {
- return $command::class === \VuFindSearch\Command\RandomCommand::class
- && $command->getTargetIdentifier() === "Solr"
- && $command->getArguments()[0]->getAllTerms() === "john smith"
- && $command->getArguments()[1] === 10
- && $command->getArguments()[2]->getArrayCopy() === ['spellcheck' => ['true'],
- 'fq' => ['facet1:"value1"',
- 'facet2:"value2"'], 'hl' => ["false"]];
- };
- $service->expects($this->once())->method('invoke')
- ->with($this->callback($checkCommand))
- ->will($this->returnValue($commandObj));
-
- $recommend->setConfig("Solr:10:mixed:retain:0:facet1:value1:facet2:value2");
- $recommend->init($params, $request);
- $recommend->process($results);
+ $recommend = $this->getConfiguredModule("Solr:10:mixed:retain:0:facet1:value1:facet2:value2");
$output = $recommend->getResults();
- $this->assertEquals($records, $output);
+ $this->assertEquals(["1", "2", "3", "4", "5"], $output);
}
/**
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Resolver/Driver/AlmaTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Resolver/Driver/AlmaTest.php
index c0897391b77..3d28a8cdec4 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Resolver/Driver/AlmaTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Resolver/Driver/AlmaTest.php
@@ -78,17 +78,14 @@ class AlmaTest extends \PHPUnit\Framework\TestCase
];
/**
- * Test
+ * Support method for testParseLinks and testParseLinksWithoutIgnoredFiltering.
*
- * @return void
+ * @param bool $filterSet Should we filter the results for testParseLinksWithoutIgnoredFiltering?
+ *
+ * @return array
*/
- public function testParseLinks()
+ protected function getExpectedParsedLinks($filterSet = false): array
{
- $conn = $this->createConnector('alma.xml');
-
- $openUrl = "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004";
- $result = $conn->parseLinks($conn->fetchLinks($openUrl));
-
$testResult = [
[
'title' => 'Unpaywall',
@@ -170,7 +167,9 @@ public function testParseLinks()
'authentication' => '',
'service_type' => 'getWebService',
],
- [
+ ];
+ if (!$filterSet) {
+ $testResult[] = [
'title' => 'ProQuest Safari Tech Books Online',
'coverage' => '',
'access' => 'limited',
@@ -179,10 +178,22 @@ public function testParseLinks()
'notes' => '',
'authentication' => '',
'service_type' => 'getFullTxt',
- ],
- ];
+ ];
+ }
+ return $testResult;
+ }
- $this->assertEquals($testResult, $result);
+ /**
+ * Test
+ *
+ * @return void
+ */
+ public function testParseLinks()
+ {
+ $conn = $this->createConnector('alma.xml');
+ $openUrl = "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004";
+ $result = $conn->parseLinks($conn->fetchLinks($openUrl));
+ $this->assertEquals($this->getExpectedParsedLinks(), $result);
}
/**
@@ -193,94 +204,9 @@ public function testParseLinks()
public function testParseLinksWithoutIgnoredFiltering()
{
$conn = $this->createConnector('alma.xml', ['ignoredFilterReasons' => '']);
-
$openUrl = "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004";
$result = $conn->parseLinks($conn->fetchLinks($openUrl));
-
- $testResult = [
- [
- 'title' => 'Unpaywall',
- 'coverage' => '',
- 'access' => 'open',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=1',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'Ebook override',
- 'coverage' => 'Available from 2019',
- 'access' => 'limited',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861830000561&institutionId=561&customerId=550',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'ebrary Academic Complete Subscription UKI Edition',
- 'coverage' => '',
- 'access' => 'limited',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861800000561&institutionId=561&customerId=550',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'ebrary Science & Technology Subscription',
- 'coverage' => '',
- 'access' => 'limited',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861790000561&institutionId=561&customerId=550',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'EBSCOhost Academic eBook Collection (North America)',
- 'coverage' => '',
- 'access' => 'open',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861770000561&institutionId=561&customerId=550',
- 'notes' => 'notessssssssssss SERVICE LEVEL PUBLIC NOTE',
- 'authentication' => 'collection level auth SERVICE LEVEL AUTHE NOTE',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'EBSCOhost eBook Community College Collection',
- 'coverage' => '',
- 'access' => 'limited',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861780000561&institutionId=561&customerId=550',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getHolding',
- ],
- [
- 'title' => 'Elsevier ScienceDirect Books',
- 'coverage' => '',
- 'access' => 'limited',
- 'href' => 'https://na01.alma.exlibrisgroup.com/view/action/uresolver.do'
- . '?operation=resolveService&package_service_id=5687861820000561&institutionId=561&customerId=550',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getFullTxt',
- ],
- [
- 'title' => 'Request Assistance for this Resource!',
- 'coverage' => '',
- 'access' => '',
- 'href' => 'https://www.google.com/search?Testingrft.oclcnum=437189463'
- . '&q=Fundamental+Data+Compression&rft.archive=9942811800561',
- 'notes' => '',
- 'authentication' => '',
- 'service_type' => 'getWebService',
- ],
- ];
-
- $this->assertEquals($testResult, $result);
+ $this->assertEquals($this->getExpectedParsedLinks(true), $result);
}
/**
diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/WorldCat/ConnectorTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/WorldCat/ConnectorTest.php
index af6617b68cf..12487c0d51c 100644
--- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/WorldCat/ConnectorTest.php
+++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/WorldCat/ConnectorTest.php
@@ -44,22 +44,22 @@
class ConnectorTest extends \PHPUnit\Framework\TestCase
{
/**
- * Test "get holdings"
+ * Get a connector with a mock HTTP client.
*
- * @return void
+ * @param string $expectedUri URI expected by client.
+ * @param string $body Response body returned by client.
+ *
+ * @return Connector
*/
- public function testGetHoldings()
+ protected function getConnectorWithMockClient($expectedUri, $body = 'bar'): Connector
{
$client = $this->createMock(\Laminas\Http\Client::class);
$connector = new Connector('key', $client);
$client->expects($this->once())->method('setMethod')
->with($this->equalTo('POST'))
->will($this->returnValue($client));
- $expectedUri = 'http://www.worldcat.org/webservices/catalog/content/libraries/baz'
- . '?wskey=key&servicelevel=full&frbrGrouping=on';
$client->expects($this->once())->method('setUri')
->with($this->equalTo($expectedUri));
- $body = 'bar';
$response = $this->createMock(\Laminas\Http\Response::class);
$response->expects($this->once())->method('getBody')
->will($this->returnValue($body));
@@ -67,6 +67,19 @@ public function testGetHoldings()
->will($this->returnValue(true));
$client->expects($this->once())->method('send')
->will($this->returnValue($response));
+ return $connector;
+ }
+
+ /**
+ * Test "get holdings"
+ *
+ * @return void
+ */
+ public function testGetHoldings()
+ {
+ $expectedUri = 'http://www.worldcat.org/webservices/catalog/content/libraries/baz'
+ . '?wskey=key&servicelevel=full&frbrGrouping=on';
+ $connector = $this->getConnectorWithMockClient($expectedUri);
$final = $connector->getHoldings('baz');
$this->assertEquals('bar', (string)$final);
}
@@ -102,22 +115,9 @@ public function testGetHoldingsHttpFailure()
*/
public function testGetRecord()
{
- $client = $this->createMock(\Laminas\Http\Client::class);
- $connector = new Connector('key', $client);
- $client->expects($this->once())->method('setMethod')
- ->with($this->equalTo('POST'))
- ->will($this->returnValue($client));
$expectedUri = 'http://www.worldcat.org/webservices/catalog/content/baz?servicelevel=full&wskey=key';
- $client->expects($this->once())->method('setUri')
- ->with($this->equalTo($expectedUri));
$body = 'bar';
- $response = $this->createMock(\Laminas\Http\Response::class);
- $response->expects($this->once())->method('getBody')
- ->will($this->returnValue($body));
- $response->expects($this->any())->method('isSuccess')
- ->will($this->returnValue(true));
- $client->expects($this->once())->method('send')
- ->will($this->returnValue($response));
+ $connector = $this->getConnectorWithMockClient($expectedUri, $body);
$final = $connector->getRecord('baz');
$this->assertEquals($body, $final['docs'][0]);
}
@@ -129,22 +129,9 @@ public function testGetRecord()
*/
public function testGetRecordWithError()
{
- $client = $this->createMock(\Laminas\Http\Client::class);
- $connector = new Connector('key', $client);
- $client->expects($this->once())->method('setMethod')
- ->with($this->equalTo('POST'))
- ->will($this->returnValue($client));
$expectedUri = 'http://www.worldcat.org/webservices/catalog/content/baz?servicelevel=full&wskey=key';
- $client->expects($this->once())->method('setUri')
- ->with($this->equalTo($expectedUri));
$body = 'bad';
- $response = $this->createMock(\Laminas\Http\Response::class);
- $response->expects($this->once())->method('getBody')
- ->will($this->returnValue($body));
- $response->expects($this->any())->method('isSuccess')
- ->will($this->returnValue(true));
- $client->expects($this->once())->method('send')
- ->will($this->returnValue($response));
+ $connector = $this->getConnectorWithMockClient($expectedUri, $body);
$final = $connector->getRecord('baz');
$this->assertEquals([], $final['docs']);
}
@@ -156,24 +143,11 @@ public function testGetRecordWithError()
*/
public function testSearch()
{
- $client = $this->createMock(\Laminas\Http\Client::class);
- $connector = new Connector('key', $client);
- $client->expects($this->once())->method('setMethod')
- ->with($this->equalTo('POST'))
- ->will($this->returnValue($client));
$expectedUri = 'http://www.worldcat.org/webservices/catalog/search/sru?version=1.1&x=y'
. '&startRecord=0&maximumRecords=20&servicelevel=full&wskey=key';
- $client->expects($this->once())->method('setUri')
- ->with($this->equalTo($expectedUri));
$body = ',1bar'
. '';
- $response = $this->createMock(\Laminas\Http\Response::class);
- $response->expects($this->once())->method('getBody')
- ->will($this->returnValue($body));
- $response->expects($this->any())->method('isSuccess')
- ->will($this->returnValue(true));
- $client->expects($this->once())->method('send')
- ->will($this->returnValue($response));
+ $connector = $this->getConnectorWithMockClient($expectedUri, $body);
$final = $connector->search(new ParamBag(['x' => 'y']), 0, 20);
$this->assertEquals('bar', $final['docs'][0]);
$this->assertEquals(1, $final['total']);