From 19b4fbeab87ef3cf9a93ed947f9ddb57a1037c81 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 8 Oct 2014 11:39:37 -0400
Subject: [PATCH] Added test.

---
 .../VuFind/tests/fixtures/misc/testbug1.json  |  1 +
 .../VuFindTest/RecordDriver/SolrMarcTest.php  | 54 +++++++++++++++----
 2 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 module/VuFind/tests/fixtures/misc/testbug1.json

diff --git a/module/VuFind/tests/fixtures/misc/testbug1.json b/module/VuFind/tests/fixtures/misc/testbug1.json
new file mode 100644
index 00000000000..332f8499dab
--- /dev/null
+++ b/module/VuFind/tests/fixtures/misc/testbug1.json
@@ -0,0 +1 @@
+{"responseHeader":{"status":0,"QTime":3,"params":{"fl":"*,score","q":"id:\"000105196\"\n\n","hl.simple.pre":"{{{{START_HILITE}}}}","hl.simple.post":"{{{{END_HILITE}}}}","json.nl":"arrarr","hl.fl":"*","wt":"json","hl":"true"}},"response":{"numFound":1,"start":0,"maxScore":3.8332133,"docs":[{"physical":["V."],"issn":["0041-7084"],"illustrated":"Illustrated","dewey-tens":["510 - Mathematics"],"collection":["Catalog"],"publisher":["Zanichelli,"],"id":"000105196","title":"Bollettino della Unione matematica italiana.","spellingShingle":["Bollettino della Unione matematica italiana."],"dewey-hundreds":["500 - Science"],"spelling":["Unione matematica italiana","Bollettino della Unione matematica italiana.","Bologna : Zanichelli, 1922-1975.","V.","1948- Trimestrale","Bimestrale","1922-1975 ACNP","Ha come supplemento: Notiziario della Unione matematica italiana","Matematica Periodici.","Bollettino della Unione matematica italiana A 000343528","Bollettino della Unione matematica B 000343529","Bollettino della Unione matematica italiana 000394898"],"dateSpan":["1922-1975"],"author2":["Unione matematica italiana"],"author2Str":["Unione matematica italiana"],"publishDate":["1922"],"recordtype":"marc","institution":["MyInstitution"],"title_new":["Bollettino della Unione matematica italiana","Bollettino della Unione matematica"],"building":["Library A"],"title_auth":"Bollettino della Unione matematica italiana.","dewey-sort":"510.50000000","dewey-sort-browse":["510.50000000"],"format":["Journal"],"title_short":"Bollettino della Unione matematica italiana.","title_sort":"bollettino della unione matematica italiana","dewey-full":["510.5"],"dewey-ones":["510 - Mathematics"],"fullrecord":"01238casaa22003491u 4500001001000000005001700010007000300027008004100030022001400071040006800085041000800153044000700161082001500168110003100183245004900214260003900263300000700302310002300309321001500332362002000347500006900367653002700436785006200463785005300525785005900578952002000637952001300657958004400670FMT000700714TYP000900721Z30015800730#30;000105196#30;20130506112555.0#30;ta#30;030826u19221975it|b| p|||||| |   ||ita |#30;  #31;a0041-7084#30;  #31;aUniversità Roma Tre. Sistema bibliotecario d'Ateneo#31;bita#31;eRiCA#30;0 #31;aita#30;  #31;aIT#30;  #31;a510.5#31;221.#30;2 #31;aUnione matematica italiana#30;10#31;aBollettino della Unione matematica italiana.#30;  #31;aBologna :#31;bZanichelli,#31;c1922-1975.#30;  #31;aV.#30; 1#31;a1948-#31;bTrimestrale#30; 1#31;aBimestrale#30;  #31;a1922-1975#31;zACNP#30;  #31;aHa come supplemento: Notiziario della Unione matematica italiana#30;  #31;aMatematica#31;aPeriodici.#30;01#31;tBollettino della Unione matematica italiana#31;iA#31;w000343528#30;01#31;tBollettino della Unione matematica#31;iB#31;w000343529#30;08#31;tBollettino della Unione matematica italiana#31;w000394898#30;  #31;aSCT#31;hMatematica#30;  #31;aSCT#31;eSCT#30;  #31;aTOR#31;b1948-1964;1968-1975.#31;tD#31;u2013#31;zCHI#30;  #31;aSE#30;  #31;aSE00#30; 2#31;lCAB01#31;lCAB01#31;mISSUE#31;1TOR#31;aBAST sede Torri#31;5105196-10#31;4MTM#31;820060724#31;a1948#31;f98#31;fSolo consultazione#31;hSerie 3 A.1948 V.3 n.1-3#31;i19960705#31;j19960705#31;k20060724#30;#29;","marc_error":["Minor Error  : Subfield tag is an invalid uppercase character, changing it to lower case. --- [ Z30 : L ]","Minor Error  : Subfield tag is an invalid uppercase character, changing it to lower case. --- [ Z30 : A ]","Minor Error  : Subfield tag is an invalid uppercase character, changing it to lower case. --- [ Z30 : F ]"],"language":["Italian"],"title_full":"Bollettino della Unione matematica italiana.","title_fullStr":"Bollettino della Unione matematica italiana.","title_full_unstemmed":"Bollettino della Unione matematica italiana.","dewey-raw":["510.5"],"_version_":1481401674999267328,"score":3.8332133}]},"highlighting":{"000105196":{"id":["{{{{START_HILITE}}}}000105196{{{{END_HILITE}}}}"]}}}
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/RecordDriver/SolrMarcTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/RecordDriver/SolrMarcTest.php
index 04fe494fdf2..0a7918018b7 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/RecordDriver/SolrMarcTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/RecordDriver/SolrMarcTest.php
@@ -43,22 +43,39 @@ class SolrMarcTest extends \VuFindTest\Unit\TestCase
 {
     /**
      * Test a record that used to be known to cause problems because of the way
-     * series name was handled (the old "Bug2" test from VuFind 1.x).
+     * its linking fields are set up.
+     *
+     * Note: while Bug2 below is named for consistency with VuFind 1.x, this is
+     * named Bug1 simply to fill the gap. It's related to a problem that was
+     * discovered later. See VUFIND-1034 in JIRA.
      *
      * @return void
      */
-    public function testBug2()
+    public function testBug1()
     {
-        $fixture = json_decode(
-            file_get_contents(
-                realpath(
-                    VUFIND_PHPUNIT_MODULE_PATH . '/fixtures/misc/testbug2.json'
-                )
-            ),
-            true
+        $configArr = array('Record' => array('marc_links' => '760,765,770,772,774,773,775,777,780,785'));
+        $config = new \Zend\Config\Config($configArr);
+        $record = new \VuFind\RecordDriver\SolrMarc($config);
+        $fixture = $this->loadRecordFixture('testbug1.json');
+        $record->setRawData($fixture['response']['docs'][0]);
+        $expected = array(
+            array('title' => 'note_785_1', 'value' => 'Bollettino della Unione matematica italiana', 'link' => array('type' => 'bib', 'value' => '000343528')),
+            array('title' => 'note_785_1', 'value' => 'Bollettino della Unione matematica', 'link' => array('type' => 'bib', 'value' => '000343529')),
+            array('title' => 'note_785_8', 'value' => 'Bollettino della Unione matematica italiana', 'link' => array('type' => 'bib', 'value' => '000394898')),
         );
+        $this->assertEquals($expected, $record->getAllRecordLinks());
+    }
 
+    /**
+     * Test a record that used to be known to cause problems because of the way
+     * series name was handled (the old "Bug2" test from VuFind 1.x).
+     *
+     * @return void
+     */
+    public function testBug2()
+    {
         $record = new \VuFind\RecordDriver\SolrMarc();
+        $fixture = $this->loadRecordFixture('testbug2.json');
         $record->setRawData($fixture['response']['docs'][0]);
 
         $this->assertEquals(
@@ -75,4 +92,23 @@ class SolrMarcTest extends \VuFindTest\Unit\TestCase
         );
         $this->assertEquals('2, pt. 1.', $series[0]['number']);
     }
+
+    /**
+     * Load a fixture file.
+     *
+     * @param string $file File to load from fixture directory.
+     *
+     * @return array
+     */
+    protected function loadRecordFixture($file)
+    {
+        return json_decode(
+            file_get_contents(
+                realpath(
+                    VUFIND_PHPUNIT_MODULE_PATH . '/fixtures/misc/' . $file
+                )
+            ),
+            true
+        );
+    }
 }
\ No newline at end of file
-- 
GitLab