From d9eeea47a9889bde93eb61a13af64eba7d2cf4e3 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 2 Feb 2015 09:56:17 -0500
Subject: [PATCH] Improved test coverage.

---
 .../Search/Solr/MultiIndexListenerTest.php    | 49 +++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/MultiIndexListenerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/MultiIndexListenerTest.php
index abd5e5862aa..13c8dd0d5fc 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/MultiIndexListenerTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/MultiIndexListenerTest.php
@@ -77,7 +77,8 @@ class MultiIndexListenerTest extends TestCase
                         array('or', '~')
                     )
                 )
-            )
+            ),
+            'FilterQuery' => 'format:Book',
         )
     );
 
@@ -150,6 +151,47 @@ class MultiIndexListenerTest extends TestCase
         $this->assertEquals(array('field_1', 'field_2'), $facets);
     }
 
+    /**
+     * Test that loading a record overrides the shard settings.
+     *
+     * @return void
+     */
+    public function testAllShardsUsedForRecordRetrieval()
+    {
+        $params   = new ParamBag(
+            array(
+                'shards' => array(self::$shards['b'], self::$shards['c']),
+            )
+        );
+        $event    = new Event(
+            'pre', $this->backend,
+            array('params' => $params, 'context' => 'retrieve')
+        );
+        $this->listener->onSearchPre($event);
+
+        $shards = $params->get('shards');
+        $this->assertEquals(
+            array(implode(',', array(self::$shards['a'], self::$shards['b'], self::$shards['c']))),
+            $shards
+        );
+    }
+
+    /**
+     * Test attaching listener.
+     *
+     * @return void
+     */
+    public function testAttach()
+    {
+        $mock = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
+        $mock->expects($this->once())->method('attach')->with(
+            $this->equalTo('VuFind\Search'),
+            $this->equalTo('pre'),
+            $this->equalTo(array($this->listener, 'onSearchPre'))
+        );
+        $this->listener->attach($mock);
+    }
+
     /**
      * Apply strip to empty specs.
      *
@@ -193,7 +235,8 @@ class MultiIndexListenerTest extends TestCase
                                   array('onephrase', 300)
                               )
                           )
-                      )
+                      ),
+                      'FilterQuery' => 'format:Book',
                   )
             ),
             $specs
@@ -209,7 +252,7 @@ class MultiIndexListenerTest extends TestCase
     {
         $specs = $this->callMethod($this->listener, 'getSearchSpecs', array(array('A', 'B', 'C', 'D', 'E')));
         $this->assertEquals(
-            array('test' => array('QueryFields' => array())),
+            array('test' => array('QueryFields' => array(), 'FilterQuery' => 'format:Book')),
             $specs
         );
     }
-- 
GitLab