From 12aae2d3c5bf062b392849b131a8101ce357ee21 Mon Sep 17 00:00:00 2001
From: Robert Lange <robert.lange@uni-leipzig.de>
Date: Fri, 13 Aug 2021 16:20:21 +0200
Subject: [PATCH] refs #20476 [finc] remove deprecated method
 getExternalAccessLinks from record view helper

* also delete obsolete sample configuration from config.ini
* fix and update test for ExternalCatalogueLink
** use record_id instead of ppn
** fix mocking expactations
** use test by calling: docker exec -it [your_favorite_vufind_folder]_php_1 sh -c "vendor/bin/phpunit --configuration module/finc/tests/phpunit.xml module/finc/tests/unit-tests/src/fincTest/View/Helper/Root/ExternalCatalogueLinkTest.php"
---
 local/config/vufind/config.ini                | 11 ---
 .../finc/src/finc/View/Helper/Root/Record.php | 68 -------------------
 .../externallink/testexternallink1.json       |  2 +-
 .../Helper/Root/ExternalCatalogueLinkTest.php | 31 +++++----
 4 files changed, 19 insertions(+), 93 deletions(-)

diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini
index 1fac69a4f0f..c4f84f2d911 100644
--- a/local/config/vufind/config.ini
+++ b/local/config/vufind/config.ini
@@ -1565,17 +1565,6 @@ nbn[pattern] = "^urn:nbn:"
 nbn[search]  = "urn:nbn:"
 nbn[replace] = "http://nbn-resolving.de/urn:nbn:"
 
-; This section defines urls to match with record entries of external ILS.
-; - The url pattern is defined as value with %s replacement placeholder.
-; - The variable name indicates which identifier should be taken as replacement.
-;   Currently possibles values are _id_ for unique solr id (finc.id) and _ppn_ as
-;   record id of data other provider.
-; - The variable key indicates the institution for those replacement should be take
-;   place.
-[ExternalAccess]
-; ppn[DE-D13] = "http://webopac.skd.museum/libero/WebopacOpenURL.cls?ACTION=DISPLAY&RID=%s"
-; id[DE-14] = "http://katalogbeta.slub-dresden.de/id/%s/"
-
 ; *****************
 ; * EOF finc
 ; *****************
diff --git a/module/finc/src/finc/View/Helper/Root/Record.php b/module/finc/src/finc/View/Helper/Root/Record.php
index 63545be5c92..340f8980884 100644
--- a/module/finc/src/finc/View/Helper/Root/Record.php
+++ b/module/finc/src/finc/View/Helper/Root/Record.php
@@ -183,74 +183,6 @@ class Record extends \VuFind\View\Helper\Root\Record
             $this->config->Content->showStyleBasedIcons : false;
     }
 
-    /**
-     * Get external access links to other ILS defined by config setting.
-     *
-     * @return     array     Associative array.
-     * @throws     Exception Value of source ids has to be numeric.
-     * @deprecated Deprecated due to View Helper ExternalCatalogueLink->getLinks()
-     * @see        https://projekte.ub.uni-leipzig.de/issues/10543
-     */
-    public function getExternalAccessLinks()
-    {
-        $i = -1; // iterator of extUrls
-        $extUrls = [];
-
-        // if configuration empty return unprocessed
-        if (!isset($this->config->ExternalAccess)
-            || count($this->config->ExternalAccess) == 0
-        ) {
-            return [];
-        }
-        // if institutions empty return unprocessed
-        $institutions = $this->driver->tryMethod('getInstitutions');
-        if (!isset($institutions) || count($institutions) == 0) {
-            return [];
-        }
-        foreach ($this->config->ExternalAccess as $recordType => $accessUrl) {
-            $replaceId = null;
-            // get identifier of record id type
-            switch ($recordType) {
-                case "id":
-                    $replaceId = $this->driver->getUniqueID();
-                    break;
-                case "ppn":
-                    $replaceId = $this->driver->tryMethod('getRID');
-                    break;
-                default:
-                    $replaceId = null;
-            }
-            foreach ($accessUrl as $institution => $urlPattern) {
-                // source_id filter
-                if (is_array($urlPattern)) {
-                    foreach ($urlPattern as $source_id => $pattern) {
-                        $urlPattern = $pattern;
-                        $sids = explode(',', $source_id);
-                        if (!array_product(array_map('is_numeric', $sids))) {
-                            throw new Exception(
-                                'Value of source ids has to be numeric.'
-                            );
-                        }
-                        $sourceID = $this->driver->tryMethod('getSourceID');
-                        $replaceId = (isset($sourceID)
-                            && true === in_array($sourceID, $sids))
-                            ? $replaceId : null;
-                        break;
-                    }
-                }
-
-                // institution filter
-                if (true === in_array($institution, $institutions)
-                    && !empty($replaceId)
-                ) {
-                    $extUrls[++$i]['desc'] = $institution;
-                    $extUrls[$i]['url'] = sprintf($urlPattern, $replaceId);
-                }
-            }
-        }
-        return $extUrls;
-    }
-
     /**
      * Render the link of the specified type.
      *
diff --git a/module/finc/tests/fixtures/externallink/testexternallink1.json b/module/finc/tests/fixtures/externallink/testexternallink1.json
index a003aa32340..d54c4d9d20c 100644
--- a/module/finc/tests/fixtures/externallink/testexternallink1.json
+++ b/module/finc/tests/fixtures/externallink/testexternallink1.json
@@ -1,5 +1,5 @@
 {
-  "ppn": {
+  "record_id": {
     "DE-540": [{
       "pattern": "http://194.94.197.6/libero/WebopacOpenURL.cls?ACTION=DISPLAY&LANG=DE&RID=%s"
     }],
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 5a2559ae84f..1d903092376 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
@@ -57,9 +57,13 @@ class ExternalCatalogueLinkTest extends \VuFindTest\Unit\ViewHelperTestCase
             = $this->getExternalCatalogueLink(
                 [],
                 $this->getFixture('testexternallink1.json', 'externallink')
-            )->__invoke($this->getMockDriver());
+            )->__invoke($this->getMockDriver(
+            'VuFind\RecordDriver\SolrDefault',
+            '0008964455',
+            '265768233',
+            '22',
+            ['DE-14', 'DE-D13']));
 
-        $links = $externalCatalogue->getLinks();
         $expectedArray = [
             [
                 "desc" => "DE-D13",
@@ -70,7 +74,8 @@ class ExternalCatalogueLinkTest extends \VuFindTest\Unit\ViewHelperTestCase
                 "url" => "http://katalogbeta.slub-dresden.de/id/0008964455/"
             ]
         ];
-        $this->assertEquals(json_encode($expectedArray), json_encode($links));
+        $this->assertEquals(json_encode($expectedArray), json_encode($externalCatalogue->getLinks()));
+
         $externalCatalogue
             = $this->getExternalCatalogueLink(
                 [],
@@ -84,14 +89,13 @@ class ExternalCatalogueLinkTest extends \VuFindTest\Unit\ViewHelperTestCase
                     ['DE-D13', 'DE-540']
                 )
             );
-        $links = $externalCatalogue->getLinks();
         $expectedArray = [
             [
                 "desc" => "DE-540",
                 "url" => "http://194.94.197.6/libero/WebopacOpenURL.cls?ACTION=DISPLAY&LANG=DE&RID=265768233"
             ]
         ];
-        $this->assertEquals(json_encode($expectedArray), json_encode($links));
+        $this->assertEquals(json_encode($expectedArray), json_encode($externalCatalogue->getLinks()));
         // @codingStandardsIgnoreEnd
     }
 
@@ -108,10 +112,10 @@ class ExternalCatalogueLinkTest extends \VuFindTest\Unit\ViewHelperTestCase
      */
     protected function getMockDriver(
         $class = 'VuFind\RecordDriver\SolrDefault',
-        $id = '0008964455',
-        $record_id = '265768233',
-        $source_id = "0",
-        $institutions = ["DE-14", "DE-D13"]
+        $id,
+        $record_id,
+        $source_id,
+        $institutions
     ) {
         $driver = $this->getMockBuilder($class)
             ->setMethods(['getUniqueID', 'getSourceID', 'tryMethod'])
@@ -124,14 +128,15 @@ class ExternalCatalogueLinkTest extends \VuFindTest\Unit\ViewHelperTestCase
             ->method('tryMethod')
             ->withConsecutive(
                 [$this->equalTo('getInstitutions')],
-                [$this->equalTo('getRID')],
-                [$this->equalTo('getPpn')],
-                [$this->equalTo('getSourceID')]
+                [$this->equalTo('getField'), $this->equalTo(['record_id'])],
+                [$this->equalTo('getSourceID')],
+                [$this->equalTo('getField'), $this->equalTo(['id'])]
             )
             ->willReturnOnConsecutiveCalls(
                 $this->returnValue($institutions),
                 $this->returnValue($record_id),
-                $this->returnValue($source_id)
+                $this->returnValue($source_id),
+                $this->returnValue($id)
             );
         return $driver;
     }
-- 
GitLab