From ab67873d1005dac476fb170d5955748f1235b3d6 Mon Sep 17 00:00:00 2001 From: Robert Lange <robert.lange@uni-leipzig.de> Date: Thu, 30 Mar 2023 11:03:34 +0200 Subject: [PATCH] refs #23542 [finc] vf7: fix dds and tests * update to laminas or remove obsolete dependencies for dds * fix unit tests ** set Laminas as namespace ** correct signature for setUp method * fix OpenUrlTest method testValidateParamsEzbFalse by correcting import ** Redi resolver had been removed in finc - caused ReflectionException and made test fail ** corrected namespace ** run test via: docker exec -it de_15_ubl_php_1 sh -c "vendor/bin/phpunit --configuration module/finc/tests/phpunit.xml module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/OpenUrlTest.php --filter testValidateParamsEzbFalse" --- composer.local.0.finc.json | 7 ++---- module/finc/config/dds-form.php | 22 +++++++++--------- .../AjaxHandler/GetUserILLRequestsStats.php | 2 +- .../DocumentDeliveryServiceController.php | 5 ++-- module/finc/src/finc/Exception/DDS.php | 23 +++++++++++++++++-- .../src/finc/View/Helper/Root/OpenUrl.php | 2 +- module/finc/tests/.phpunit.result.cache | 1 + module/finc/tests/bootstrap.php | 6 ++--- .../src/fincTest/ILS/Driver/PAIATest.php | 12 +++++----- .../RecordDriver/SolrBaseTestCase.php | 10 ++++---- .../SolrMarcNewerPreviousTest.php | 4 ++-- .../Helper/Root/ExternalCatalogueLinkTest.php | 2 +- .../documentdeliveryservice/zform.phtml | 14 +++++------ 13 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 module/finc/tests/.phpunit.result.cache diff --git a/composer.local.0.finc.json b/composer.local.0.finc.json index 76e927c42a0..e09509adae4 100644 --- a/composer.local.0.finc.json +++ b/composer.local.0.finc.json @@ -17,11 +17,8 @@ "extra": { "vufind": { "modules": [ - "Zend\\Filter", - "Zend\\Hydrator", - "Zend\\Validator", - "Zend\\Serializer", - "Zend\\InputFilter", + "Laminas\\Filter", + "Laminas\\Validator", "finc" ] } diff --git a/module/finc/config/dds-form.php b/module/finc/config/dds-form.php index 20a0adfeb63..ab191d6f2b6 100644 --- a/module/finc/config/dds-form.php +++ b/module/finc/config/dds-form.php @@ -19,17 +19,17 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 */ -use Zend\Filter\PregReplace; -use Zend\Filter\StringTrim; -use Zend\Form\Element\Email; -use Zend\Form\Element\Select; -use Zend\Form\Element\Submit; -use Zend\Form\Element\Text; -use Zend\Form\Element\Textarea; -use Zend\Validator\EmailAddress; -use Zend\Validator\NotEmpty; -use Zend\Validator\Regex; -use Zend\Validator\StringLength; +use Laminas\Filter\PregReplace; +use Laminas\Filter\StringTrim; +use Laminas\Form\Element\Email; +use Laminas\Form\Element\Select; +use Laminas\Form\Element\Submit; +use Laminas\Form\Element\Text; +use Laminas\Form\Element\Textarea; +use Laminas\Validator\EmailAddress; +use Laminas\Validator\NotEmpty; +use Laminas\Validator\Regex; +use Laminas\Validator\StringLength; return [ 'name' => 'dds-form', diff --git a/module/finc/src/finc/AjaxHandler/GetUserILLRequestsStats.php b/module/finc/src/finc/AjaxHandler/GetUserILLRequestsStats.php index 33c73a42225..f2bdcf292f7 100644 --- a/module/finc/src/finc/AjaxHandler/GetUserILLRequestsStats.php +++ b/module/finc/src/finc/AjaxHandler/GetUserILLRequestsStats.php @@ -25,7 +25,7 @@ */ namespace finc\AjaxHandler; -use Zend\Mvc\Controller\Plugin\Params; +use Laminas\Mvc\Controller\Plugin\Params; /** * AJAX handler to get statistics (e.g. counts) of users interlibrary loans. diff --git a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php index 611f655bc83..8e382176e71 100644 --- a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php +++ b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php @@ -30,12 +30,12 @@ namespace finc\Controller; use finc\Exception\DDS as DDSException; use finc\Mailer\Mailer as Mailer; -use VuFind\Exception\Mail as MailException; use Laminas\Form\Element\Select; use Laminas\Form\Form; use Laminas\Http\PhpEnvironment\Request; use Laminas\Mail\Address as Address; use Laminas\ServiceManager\ServiceLocatorInterface; +use VuFind\Exception\Mail as MailException; /** * Controller for Document Delivery Service @@ -261,8 +261,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase ->send(); if (!$response->isSuccess()) { - if ($response->getContent()) { - $responseArray = $this->parseJsonAsArray($response->getContent()); + if ($response->getContent() && ($responseArray = $this->parseJsonAsArray($response->getContent()))) { if (array_key_exists('error', $responseArray)) { $message = $responseArray['error']; } diff --git a/module/finc/src/finc/Exception/DDS.php b/module/finc/src/finc/Exception/DDS.php index 1a1a0ccb9b8..a3dc6050c8a 100644 --- a/module/finc/src/finc/Exception/DDS.php +++ b/module/finc/src/finc/Exception/DDS.php @@ -26,8 +26,27 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/indexing Wiki */ +namespace finc\Exception; // Manipulate command line to load correct route, then run the main index page: -array_unshift($_SERVER['argv'], array_shift($_SERVER['argv']), 'import', 'import-xsl'); +array_unshift( + $_SERVER['argv'], + array_shift($_SERVER['argv']), + 'import', + 'import-xsl' +); $_SERVER['argc'] += 2; -require_once __DIR__ . '/../public/index.php'; +require_once dirname(__FILE__, 6) . '/public/index.php'; + +/** + * DDS Exception + * + * @category VuFind + * @package Exceptions + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class DDS extends \Exception +{ +} diff --git a/module/finc/src/finc/View/Helper/Root/OpenUrl.php b/module/finc/src/finc/View/Helper/Root/OpenUrl.php index 4edd2e0ce70..8624016ac83 100644 --- a/module/finc/src/finc/View/Helper/Root/OpenUrl.php +++ b/module/finc/src/finc/View/Helper/Root/OpenUrl.php @@ -28,7 +28,7 @@ namespace finc\View\Helper\Root; use finc\Resolver\Driver\Ezb; -use finc\Resolver\Driver\Redi; +use VuFind\Resolver\Driver\Redi; /** * OpenUrl view helper diff --git a/module/finc/tests/.phpunit.result.cache b/module/finc/tests/.phpunit.result.cache new file mode 100644 index 00000000000..be8380b3308 --- /dev/null +++ b/module/finc/tests/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":5538:{a:2:{s:7:"defects";a:1:{s:65:"FincTest\View\Helper\Root\OpenUrlTest::testValidateParamsEzbFalse";i:3;}s:5:"times";a:70:{s:53:"fincTest\Config\SearchSpecsReaderTest::testParentYaml";d:0.442;s:58:"fincTest\Config\SearchSpecsReaderTest::testSearchSpecsRead";d:0.171;s:58:"fincTest\Config\SearchSpecsReaderTest::testMissingFileRead";d:0.001;s:51:"fincTest\Config\SearchSpecsReaderTest::testYamlLoad";d:0.002;s:52:"fincTest\Config\SearchSpecsReaderTest::testYamlMerge";d:0.001;s:50:"VuFindTest\ILS\Driver\PAIATest::testChangePassword";d:0.03;s:40:"VuFindTest\ILS\Driver\PAIATest::testFees";d:0.005;s:41:"VuFindTest\ILS\Driver\PAIATest::testHolds";d:0.004;s:44:"VuFindTest\ILS\Driver\PAIATest::testRequests";d:0.004;s:48:"VuFindTest\ILS\Driver\PAIATest::testTransactions";d:0.008;s:43:"VuFindTest\ILS\Driver\PAIATest::testProfile";d:0.004;s:48:"VuFindTest\ILS\Driver\PAIATest::testValidRequest";d:0.003;s:48:"VuFindTest\ILS\Driver\PAIATest::testRenewDetails";d:0.001;s:45:"VuFindTest\ILS\Driver\PAIATest::testPlaceHold";d:0.004;s:64:"VuFindTest\ILS\Driver\PAIATest::testPlaceStorageRetrievalRequest";d:0.004;s:41:"VuFindTest\ILS\Driver\PAIATest::testRenew";d:0.006;s:56:"VuFindTest\ILS\Driver\PAIATest::testMissingConfiguration";d:0.001;s:66:"VuFindTest\ILS\Driver\PAIAFincTest::testMapOptionsPickupBranchTrue";d:0;s:57:"VuFindTest\ILS\Driver\PAIAFincTest::testMapOptionsNewTrue";d:0;s:79:"VuFindTest\ILS\Driver\PAIAFincTest::testMapOptionsPickupBranchFalseNoConditions";d:0.001;s:81:"VuFindTest\ILS\Driver\PAIAFincTest::testMapOptionsPickupBranchTrueUnknownOptionId";d:0;s:83:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWithoutOptionConfigurationDefined";d:0.004;s:76:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWithoutPaiaResponseOptions";d:0.006;s:69:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsAllowUnknownOptions";d:0.004;s:63:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWrongInstance";d:0.004;s:66:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWithPickUpBranch";d:0.006;s:73:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWithAnotherPickUpBranch";d:0.004;s:81:"VuFindTest\ILS\Driver\PAIAFincTest::testGetMyHoldsWithMultipleOptionsPickUpBranch";d:0.004;s:63:"VuFindTest\ILS\Driver\PAIAFincTest::testgetOptionsReturnsIDTrue";d:0.002;s:68:"VuFindTest\ILS\Driver\PAIAFincTest::testgetOptionsNotOnlyFirstButAll";d:0.002;s:66:"VuFindTest\ILS\Driver\PAIAFincTest::testgetOptionsReturnsLabelTrue";d:0.004;s:67:"VuFindTest\ILS\Driver\PAIAFincTest::testgetOptionsReturnsEmptyArray";d:0.003;s:58:"VuFindTest\ILS\Driver\PAIAFincTest::testCallMapOptionsTrue";d:0.005;s:59:"VuFindTest\ILS\Driver\PAIAFincTest::testCallMapOptionsFalse";d:0.007;s:54:"VuFindTest\ILS\Driver\PAIAFincTest::testChangePassword";d:0.004;s:44:"VuFindTest\ILS\Driver\PAIAFincTest::testFees";d:0.004;s:45:"VuFindTest\ILS\Driver\PAIAFincTest::testHolds";d:0.006;s:48:"VuFindTest\ILS\Driver\PAIAFincTest::testRequests";d:0.004;s:52:"VuFindTest\ILS\Driver\PAIAFincTest::testTransactions";d:0.008;s:47:"VuFindTest\ILS\Driver\PAIAFincTest::testProfile";d:0.005;s:52:"VuFindTest\ILS\Driver\PAIAFincTest::testValidRequest";d:0.003;s:52:"VuFindTest\ILS\Driver\PAIAFincTest::testRenewDetails";d:0.001;s:49:"VuFindTest\ILS\Driver\PAIAFincTest::testPlaceHold";d:0.004;s:68:"VuFindTest\ILS\Driver\PAIAFincTest::testPlaceStorageRetrievalRequest";d:0.009;s:45:"VuFindTest\ILS\Driver\PAIAFincTest::testRenew";d:0.004;s:60:"VuFindTest\ILS\Driver\PAIAFincTest::testMissingConfiguration";d:0;s:64:"fincTest\RecordDriver\SolrMarcNewerPreviousTest::testNewerTitles";d:0.015;s:67:"fincTest\RecordDriver\SolrMarcNewerPreviousTest::testPreviousTitles";d:0.011;s:64:"fincTest\RecordDriver\SolrMarcNewerPreviousTest::testGetUniqueId";d:0;s:65:"FincTest\View\Helper\Root\ExternalCatalogueLinkTest::testGetLinks";d:0.004;s:66:"FincTest\View\Helper\Root\OpenUrlTest::testAddCustomParamsNoParams";d:0.03;s:70:"FincTest\View\Helper\Root\OpenUrlTest::testAddCustomStaticParamsForEzb";d:0.005;s:75:"FincTest\View\Helper\Root\OpenUrlTest::testDONTOverrideExistingParamsForEzb";d:0.005;s:71:"FincTest\View\Helper\Root\OpenUrlTest::testAddCustomStaticParamsForRedi";d:0.005;s:76:"FincTest\View\Helper\Root\OpenUrlTest::testDONTOverrideExistingParamsForRedi";d:0.005;s:71:"FincTest\View\Helper\Root\OpenUrlTest::testAddCustomDynamicParamsForEzb";d:0.005;s:72:"FincTest\View\Helper\Root\OpenUrlTest::testAddCustomDynamicParamsForRedi";d:0.005;s:65:"FincTest\View\Helper\Root\OpenUrlTest::testValidateParamsEzbFalse";d:0.005;s:64:"FincTest\View\Helper\Root\OpenUrlTest::testValidateParamsEzbTrue";d:0.027;s:63:"FincTest\View\Helper\Root\OpenUrlTest::testIsActiveIsIdempotent";d:0.008;s:63:"FincTest\View\Helper\Root\OpenUrlTest::testCheckContextDefaults";d:0.028;s:68:"FincTest\View\Helper\Root\OpenUrlTest::testCheckContextWithOverrides";d:0.005;s:60:"FincTest\View\Helper\Root\OpenUrlTest::testCheckContextNoUrl";d:0.005;s:73:"FincTest\View\Helper\Root\OpenUrlTest::testCheckExcludedRecordsRulesFalse";d:0.003;s:72:"FincTest\View\Helper\Root\OpenUrlTest::testCheckExcludedRecordsRulesTrue";d:0.003;s:93:"FincTest\View\Helper\Root\OpenUrlTest::testCheckExcludedRecordsRulesFalseDueToWildcardFailure";d:0.031;s:74:"FincTest\View\Helper\Root\OpenUrlTest::testCheckSupportedRecordsRulesFalse";d:0.003;s:91:"FincTest\View\Helper\Root\OpenUrlTest::testCheckSupportedRecordsRulesWithWildcardStillFalse";d:0.003;s:73:"FincTest\View\Helper\Root\OpenUrlTest::testCheckSupportedRecordsRulesTrue";d:0.003;s:67:"FincTest\View\Helper\Root\OpenUrlTest::testRecordDriverClassInRules";d:0.005;}}} \ No newline at end of file diff --git a/module/finc/tests/bootstrap.php b/module/finc/tests/bootstrap.php index 62190b89ea0..94a0f709e39 100644 --- a/module/finc/tests/bootstrap.php +++ b/module/finc/tests/bootstrap.php @@ -28,9 +28,9 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.swissbib.org */ -use Zend\Mvc\Service\ServiceManagerConfig; -use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\ArrayUtils; +use Laminas\Mvc\Service\ServiceManagerConfig; +use Laminas\ServiceManager\ServiceManager; +use Laminas\Stdlib\ArrayUtils; /** * Bootstrap diff --git a/module/finc/tests/unit-tests/src/fincTest/ILS/Driver/PAIATest.php b/module/finc/tests/unit-tests/src/fincTest/ILS/Driver/PAIATest.php index 8169a7e9ad0..81b5b2d3c6e 100644 --- a/module/finc/tests/unit-tests/src/fincTest/ILS/Driver/PAIATest.php +++ b/module/finc/tests/unit-tests/src/fincTest/ILS/Driver/PAIATest.php @@ -29,8 +29,8 @@ namespace VuFindTest\ILS\Driver; use finc\ILS\Driver\PAIA as fincPAIA; use InvalidArgumentException; -use Zend\Http\Client\Adapter\Test as TestAdapter; -use Zend\Http\Response as HttpResponse; +use Laminas\Http\Client\Adapter\Test as TestAdapter; +use Laminas\Http\Response as HttpResponse; /** * ILS driver test @@ -622,7 +622,7 @@ class PAIAFincTest extends \VuFindTest\ILS\Driver\PAIATest $paia = $this->getMockBuilder(PAIAMock::class) ->enableProxyingToOriginalMethods() ->setMethods(['mapOptions']) - ->setConstructorArgs([new \VuFind\Date\Converter(), new \Zend\Session\SessionManager()]) + ->setConstructorArgs([new \VuFind\Date\Converter(), new \Laminas\Session\SessionManager()]) ->getMock(); $paia->prepare("fincWithOnePickupBranchOption.json"); @@ -644,7 +644,7 @@ class PAIAFincTest extends \VuFindTest\ILS\Driver\PAIATest $paia = $this->getMockBuilder(PAIAMock::class) ->enableProxyingToOriginalMethods() ->setMethods(['mapOptions']) - ->setConstructorArgs([new \VuFind\Date\Converter(), new \Zend\Session\SessionManager()]) + ->setConstructorArgs([new \VuFind\Date\Converter(), new \Laminas\Session\SessionManager()]) ->getMock(); $paia->prepare("fincWithOnePickupBranchOption.json"); @@ -692,7 +692,7 @@ class PAIAFincTest extends \VuFindTest\ILS\Driver\PAIATest $service->setDefaultAdapter($adapter); $conn = new PAIAMock( new \VuFind\Date\Converter(), - new \Zend\Session\SessionManager() + new \Laminas\Session\SessionManager() ); $conn->setHttpService($service); return $conn; @@ -711,7 +711,7 @@ class PAIAFincTest extends \VuFindTest\ILS\Driver\PAIATest $paia = new fincPAIA( new \VuFind\Date\Converter(), - new \Zend\Session\SessionManager() + new \Laminas\Session\SessionManager() ); return [$method, $paia]; diff --git a/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrBaseTestCase.php b/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrBaseTestCase.php index 6f91fe848c1..037e2161a8f 100644 --- a/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrBaseTestCase.php +++ b/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrBaseTestCase.php @@ -77,7 +77,7 @@ class SolrBaseTestCase extends VuFindTestCase return $decode ? json_decode($content, true) : $content; } - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->driver = $this->getDriverMock(); @@ -89,11 +89,11 @@ class SolrBaseTestCase extends VuFindTestCase * @param array $plugins Custom VuFind plug-ins to register * @param string $theme Theme directory to load from * - * @return \Zend\View\Renderer\PhpRenderer + * @return \Laminas\View\Renderer\PhpRenderer */ protected function getPhpRenderer($plugins = [], $theme = 'finc') { - $resolver = new \Zend\View\Resolver\TemplatePathStack(); + $resolver = new \Laminas\View\Resolver\TemplatePathStack(); // This assumes that all themes will be testing inherit directly // from root with no intermediate themes. Probably safe for most @@ -103,7 +103,7 @@ class SolrBaseTestCase extends VuFindTestCase APPLICATION_PATH . '/themes/' . $theme . '/templates' ] ); - $renderer = new \Zend\View\Renderer\PhpRenderer(); + $renderer = new \Laminas\View\Renderer\PhpRenderer(); $renderer->setResolver($resolver); if (!empty($plugins)) { $pluginManager = $renderer->getHelperPluginManager(); @@ -125,7 +125,7 @@ class SolrBaseTestCase extends VuFindTestCase protected function getPlugins($id) { $record = new RecordViewHelperMock($this->driver); - $serverUrl = $this->createMock(\Zend\View\Helper\ServerUrl::class); + $serverUrl = $this->createMock(\Laminas\View\Helper\ServerUrl::class); /*TODO: should be called only once*/ $serverUrl->expects(/*$this->once()*/$this->any())->method('__invoke') ->will($this->returnValue('http://localhost:11100/')); diff --git a/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrMarcNewerPreviousTest.php b/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrMarcNewerPreviousTest.php index 391787e5905..179dcb9d88d 100644 --- a/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrMarcNewerPreviousTest.php +++ b/module/finc/tests/unit-tests/src/fincTest/RecordDriver/SolrMarcNewerPreviousTest.php @@ -28,7 +28,7 @@ namespace fincTest\RecordDriver; use finc\RecordDriver\SolrMarcFinc as SolrMarcFincDriver; use finc\RecordDriver\SolrMarcFincTrait; -use Zend\Session\Container; +use Laminas\Session\Container; /** * SolrMarcNewerPreviousTest @@ -46,7 +46,7 @@ class SolrMarcNewerPreviousTest extends SolrBaseTestCase * * @return void */ - public function setUp() + public function setUp(): void { $this->initialize('misc/0002795235.json'); } diff --git a/module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/ExternalCatalogueLinkTest.php b/module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/ExternalCatalogueLinkTest.php index 1d903092376..9d25782bf0c 100644 --- a/module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/ExternalCatalogueLinkTest.php +++ b/module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/ExternalCatalogueLinkTest.php @@ -29,7 +29,7 @@ namespace FincTest\View\Helper\Root; use finc\View\Helper\Root\ExternalCatalogueLink; -use Zend\Config\Config; +use Laminas\Config\Config; /** * External Catalogue Link Test Class diff --git a/themes/finc/templates/documentdeliveryservice/zform.phtml b/themes/finc/templates/documentdeliveryservice/zform.phtml index 185a9fc5ee1..2c5ed553f27 100644 --- a/themes/finc/templates/documentdeliveryservice/zform.phtml +++ b/themes/finc/templates/documentdeliveryservice/zform.phtml @@ -20,13 +20,13 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 */ -use \Laminas\Form\Element; -use \Laminas\Form\Element\Submit; -use \Laminas\Form\Form; -use \Laminas\Form\View\Helper\FormElementErrors; -use \Laminas\Form\View\Helper\FormLabel; -use \Laminas\Form\View\Helper\FormSelect; -use \Laminas\Form\View\Helper\FormSubmit; +use Laminas\Form\Element; +use Laminas\Form\Element\Submit; +use Laminas\Form\Form; +use Laminas\Form\View\Helper\FormElementErrors; +use Laminas\Form\View\Helper\FormLabel; +use Laminas\Form\View\Helper\FormSelect; +use Laminas\Form\View\Helper\FormSubmit; /** @var Form $form */ /** @var FormLabel $formLabel */ -- GitLab