diff --git a/module/VuDL/src/VuDL/Connection/Solr.php b/module/VuDL/src/VuDL/Connection/Solr.php index 966121630bd38faf7a2aa0a099500ab696fa4366..0152c6c2e3e29c71ec890bec819ad1d6db4fcced 100644 --- a/module/VuDL/src/VuDL/Connection/Solr.php +++ b/module/VuDL/src/VuDL/Connection/Solr.php @@ -274,6 +274,7 @@ class Solr extends AbstractBase } // Get info on our record $parents = $data->response->docs[0]; + var_dump($this->getRootId()); if ($current != $this->getRootId()) { foreach ($parents->hierarchy_parent_id as $i=>$cid) { array_push($queue, $cid); diff --git a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/ManagerTest.php b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/ManagerTest.php index ae8ac18036fa6a1f78df09a69f07b03e8564c06c..ac0843fef5b34dcf2e25f0427f1af16867a09e97 100644 --- a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/ManagerTest.php +++ b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/ManagerTest.php @@ -43,6 +43,7 @@ class ManagerTest extends \VuFindTest\Unit\TestCase { return new \VuDL\Connection\Manager(array('First', 'Second'), new FakeServiceLocator()); } + public function testManager() { $subject = $this->getTestSubject(); diff --git a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php new file mode 100644 index 0000000000000000000000000000000000000000..bebff74701e8594610750273465818710651a0d2 --- /dev/null +++ b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php @@ -0,0 +1,239 @@ +<?php +/** + * VuDL Solr Manager Test Class + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +namespace VuDLTest; + +/** + * VuDL Solr Manager Test Class + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +class SolrTest extends \VuFindTest\Unit\TestCase +{ + + public function testAllWithMock() + { + $subject = new \VuDL\Connection\Solr( + $this->getServiceManager()->get('VuFind\Config')->get('config'), + new FakeBackend( + array( + '{"response":{"numFound":0}}', + '{"response":{"numFound":1,"docs":[{"modeltype_str_mv":["123456789012CLASS_ONE","123456789012CLASS_TWO"]}]}}', + + false, + //'{"response":{"docs":[{"author":"1,2"}]}}', + //'{"response":{"docs":[{"author":"1,2"}]}}', + + '{"response":{"numFound":0}}', + '{"response":{"numFound":1,"docs":[{"dc_title_str":"LABEL"}]}}', + + '{"response":{"numFound":0}}', + '{"response":{"numFound":1,"docs":[{"id":"ID", "hierarchy_top_title":"TOP"}]}}', + + false, + '{"response":{"numFound":1,"docs":[{"fgs.lastModifiedDate":["DATE"]}]}}', + + '{"response":{"numFound":0}}', + '{"response":{"numFound":1,"docs":[{"id":"ID1"},{"id":"ID2"}]}}', + + '{"response":{"numFound":0}}', + '{"response":{"numFound":1,"docs":[{"hierarchy_parent_id":["id2"],"hierarchy_parent_title":["title2"]}]}}', + '{"response":{"numFound":1,"docs":[{"hierarchy_parent_id":["id1"],"hierarchy_parent_title":["title1"]}]}}', + '{"response":{"numFound":1,"docs":[{"hierarchy_parent_id":[]}]}}', + ) + ) + ); + + $this->assertEquals(null, $subject->getClasses('id')); + $this->assertEquals(array("CLASS_ONE", "CLASS_TWO"), $subject->getClasses('id')); + + $this->assertEquals(null, $subject->getDetails('id', false)); + // Test for exception later + //$this->assertEquals(array("author"=>"1,2"), $subject->getDetails('id', false)); + //var_dump($subject->getDetails('id', true)); + //$this->assertEquals(array("author"=>array("1", "2")), $subject->getDetails('id', true)); + + $this->assertEquals(null, $subject->getLabel('id')); + $this->assertEquals("LABEL", $subject->getLabel('id')); + + $this->assertEquals(array(), $subject->getMemberList('root')); + $this->assertEquals(array(array('id'=>'ID','title'=>'TOP')), $subject->getMemberList('root')); + + $this->assertEquals(null, $subject->getModDate('id')); + $this->assertEquals("DATE", $subject->getModDate('id')); + + $this->assertEquals(null, $subject->getOrderedMembers('id')); + $this->assertEquals(array("ID1", "ID2"), $subject->getOrderedMembers('id', array('fake_filter'))); + + $this->assertEquals(null, $subject->getParentList('id1')); + $this->assertEquals(array(array('id1'=>'title1','id2'=>'title2')), $subject->getParentList('id1')); + $this->assertEquals(array(array('id1'=>'title1','id2'=>'title2')), $subject->getParentList('id1')); // Cache test + } + + /** + * Returns an array of classes for this object + * + * @param string $id record id + * + * @return array + */ + protected function getClassesTest($id) + { + } + + /** + * Get details from Solr + * + * @param string $id ID to look up + * @param boolean $format Run result through formatDetails? + * + * @return array + * @throws \Exception + */ + protected function getDetailsTest($id, $format) + { + } + + /** + * Get an item's label + * + * @param string $id Record's id + * + * @return string + */ + protected function getLabelTest($id) + { + } + + /** + * Tuple call to return and parse a list of members... + * + * @param string $root ...for this id + * + * @return array of members in order + */ + protected function getMemberListTest($root) + { + } + + /** + * Get the last modified date from Solr + * + * @param string $id ID to look up + * + * @return array + * @throws \Exception + */ + protected function getModDateTest($id) + { + } + + /** + * Returns file contents of the structmap, our most common call + * + * @param string $id record id + * @param array $extra_sort extra fields to sort on + * + * @return string $id + */ + protected function getOrderedMembersTest($id, $extra_sort = array()) + { + } + + /** + * Tuple call to return and parse a list of parents... + * + * @param string $id ...for this id + * + * @return array of parents in order from top-down + */ + protected function getParentListTest($id) + { + } + + /** + * Get copyright URL and compare it to special cases from VuDL.ini + * + * @param array $id record id + * @param array $setLicenses ids are strings to match urls to, + * the values are abbreviations. Parsed in details.phtml later. + * + * @return array + */ + protected function getCopyrightTest($id, $setLicenses) + { + } +} + +class FakeBackend +{ + protected $returnList; + + public function __construct($returns) + { + $this->returnList = $returns; + } + + public function getConnector() + { + return new FakeSolr($this->returnList); + } +} + +class FakeSolr +{ + protected $callNumber = 0; + protected $returnList; + + public function __construct($returns) + { + $this->returnList = $returns; + } + + public function getMap() + { + return new FakeMap(); + } + + public function search() + { + var_dump($this->returnList[$this->callNumber]); + return $this->returnList[$this->callNumber++]; + } +} + +class FakeMap +{ + public function __call($method, $args) + { + return new \ArrayObject(); + } +} \ No newline at end of file