diff --git a/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/EzbTest.php b/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/EzbTest.php new file mode 100644 index 0000000000000000000000000000000000000000..999e23fd14369d7f19b6145d39d2bc2d0d485954 --- /dev/null +++ b/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/EzbTest.php @@ -0,0 +1,102 @@ +<?php +/** + * Finc Resolver Ezb Test Class + * + * PHP version 5 + * + * Copyright (C) Leipzig University Library 2017. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * @category Finc + * @package Tests + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +namespace FincTest\Resolver\Driver\Root; + +use finc\Resolver\Driver\Ezb; +use Zend\Http\Client\Adapter\Test as TestAdapter; + +/** + * Finc Resolver Redi Test Class + * + * @category Finc + * @package Tests + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +class EzbTest extends \VuFindTest\Resolver\Driver\EzbTest +{ + protected $adapter; + + protected $client; + + protected function initEmpty() + { + $this->adapter = new TestAdapter(); + $this->client = new \Zend\Http\Client(); + $this->client->setAdapter($this->adapter); + } + + protected function getInstance($baseUrl = false) + { + $this->initEmpty(); + return $ezb = new Ezb( + $baseUrl !== false ? (object)['url' => $baseUrl] : (object)$this->openUrlConfig['OpenURL'], + $this->client + ); + } + + public function testGetResolverUrl() + { + $openUrl = "x=1&y=2"; + $this->assertEquals( + "{$this->openUrlConfig['OpenURL']['url']}?$openUrl", + $this->getInstance()->getResolverUrl($openUrl) + ); + } + + public function testGetResolverUrlWithQuestionMarkInBaseUrl() + { + $baseUrl = "{$this->openUrlConfig['OpenURL']['url']}?site=xyz"; + $openUrl = "x=1&y=2"; + $this->assertEquals("$baseUrl&$openUrl", $this->getInstance($baseUrl)->getResolverUrl($openUrl)); + } + + public function testGetResolverUrlNoParams() + { + $this->assertEquals($this->openUrlConfig['OpenURL']['url'], $this->getInstance()->getResolverUrl("")); + } + + public function testEmptyBaseUrlException() + { + $this->expectException(\Zend\Config\Exception\InvalidArgumentException::class); + $this->getInstance("")->getResolverUrl("xyz"); + } + + public function testRemoveLeadingConnectorFromOpenUrl() + { + $baseUrl = "http://services.dnb.de/fize-service/gvr/full.xml"; + $openUrl = "&x=1&y=2"; + $this->assertEquals( + "http://services.dnb.de/fize-service/gvr/full.xml?x=1&y=2", + $this->getInstance($baseUrl)->getResolverUrl($openUrl) + ); + + $openUrl = "?x=1&y=2"; + $this->assertEquals( + "http://services.dnb.de/fize-service/gvr/full.xml?x=1&y=2", + $this->getInstance($baseUrl)->getResolverUrl($openUrl) + ); + } +} diff --git a/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/RediTest.php b/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/RediTest.php new file mode 100644 index 0000000000000000000000000000000000000000..35b8388a75b767f81e912a091a0b3126de08852c --- /dev/null +++ b/module/finc/tests/unit-tests/src/fincTest/Resolver/Driver/RediTest.php @@ -0,0 +1,95 @@ +<?php +/** + * Finc Resolver Redi Test Class + * + * PHP version 5 + * + * Copyright (C) Leipzig University Library 2017. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * @category Finc + * @package Tests + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +namespace FincTest\Resolver\Driver\Root; + +use finc\Resolver\Driver\Redi; +use Zend\Http\Client\Adapter\Test as TestAdapter; + +/** + * Finc Resolver Redi Test Class + * + * @category Finc + * @package Tests + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +class RediTest extends \VuFindTest\Resolver\Driver\RediTest +{ + protected $adapter; + + protected $client; + + protected function initEmpty() + { + $this->adapter = new TestAdapter(); + $this->client = new \Zend\Http\Client(); + $this->client->setAdapter($this->adapter); + } + + protected function getInstance($baseUrl = false) + { + $this->initEmpty(); + return $redi = new Redi( + $baseUrl !== false ? $baseUrl : $this->openUrlConfig['OpenURL']['url'], + $this->client + ); + } + + public function testGetResolverUrl() + { + $openUrl = "x=1&y=2"; + $this->assertEquals( + "{$this->openUrlConfig['OpenURL']['url']}?$openUrl", + $this->getInstance()->getResolverUrl($openUrl) + ); + } + + public function testGetResolverUrlWithQuestionMarkInBaseUrl() + { + $baseUrl = "{$this->openUrlConfig['OpenURL']['url']}?site=xyz"; + $openUrl = "x=1&y=2"; + $this->assertEquals("$baseUrl&$openUrl", $this->getInstance($baseUrl)->getResolverUrl($openUrl)); + } + + public function testGetResolverUrlNoParams() + { + $this->assertEquals($this->openUrlConfig['OpenURL']['url'], $this->getInstance()->getResolverUrl("")); + } + + public function testGetResolverUrlWHZ() + { + $openUrl = "rl_site=whz&issn=1941-9511"; + $this->assertEquals( + "http://www.redi-bw.de/links/whz?rl_site=whz&rl_site=whz&issn=1941-9511", + $this->getInstance("http://www.redi-bw.de/links/whz?rl_site=whz")->getResolverUrl($openUrl) + ); + } + + public function testEmptyBaseUrlException() + { + $this->expectException(\Zend\Config\Exception\InvalidArgumentException::class); + $this->getInstance("")->getResolverUrl(""); + } +}