From 0315436caf424e11f1fae29e52805b4fc6cecfc8 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 6 Mar 2018 08:28:33 -0500 Subject: [PATCH] Add tests. --- .../src/VuFindTest/Autocomplete/SolrTest.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/Autocomplete/SolrTest.php diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Autocomplete/SolrTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Autocomplete/SolrTest.php new file mode 100644 index 00000000000..4146167d618 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Autocomplete/SolrTest.php @@ -0,0 +1,116 @@ +<?php +/** + * Solr autocomplete test class. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2018. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +namespace VuFindTest\Autocomplete; + +use VuFind\Autocomplete\Solr; + +/** + * Solr autocomplete test class. + * + * @category VuFind + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +class SolrTest extends \VuFindTest\Unit\TestCase +{ + /** + * Get mock search options. + * + * @return \VuFind\Search\Solr\Options + */ + protected function getMockOptions() + { + return $this->getMockBuilder('VuFind\Search\Solr\Options') + ->disableOriginalConstructor()->getMock(); + } + + /** + * Get mock results plugin manager. + * + * @return \VuFind\Search\Results\PluginManager + */ + protected function getMockResults() + { + $results = $this->getMockBuilder('VuFind\Search\Solr\Results') + ->disableOriginalConstructor() + ->setMethods(['getOptions']) + ->getMock(); + $results->expects($this->any())->method('getOptions') + ->will($this->returnValue($this->getMockOptions())); + return $results; + } + + /** + * Get mock results plugin manager. + * + * @return \VuFind\Search\Results\PluginManager + */ + protected function getMockResultsPluginManager() + { + $rpm = $this->getMockBuilder('VuFind\Search\Results\PluginManager') + ->disableOriginalConstructor() + ->setMethods(['get']) + ->getMock(); + $rpm->expects($this->any())->method('get') + ->will($this->returnValue($this->getMockResults())); + return $rpm; + } + + /** + * Test that configuration is parsed correctly. + * + * @return void + */ + public function testSetConfigDefaults() + { + $solr = new Solr($this->getMockResultsPluginManager()); + $solr->setConfig(''); + $this->assertEquals(null, $this->getProperty($solr, 'handler')); + $this->assertEquals(['title'], $this->getProperty($solr, 'displayField')); + $this->assertEquals(null, $this->getProperty($solr, 'sortField')); + $this->assertEquals([], $this->getProperty($solr, 'filters')); + } + + /** + * Test that configuration is parsed correctly. + * + * @return void + */ + public function testSetConfig() + { + $solr = new Solr($this->getMockResultsPluginManager()); + $solr->setConfig('Handler:Display:Sort:FF1:FV1:FF2:FV2'); + $this->assertEquals('Handler', $this->getProperty($solr, 'handler')); + $this->assertEquals(['Display'], $this->getProperty($solr, 'displayField')); + $this->assertEquals('Sort', $this->getProperty($solr, 'sortField')); + $expected = ['FF1:FV1', 'FF2:FV2']; + $this->assertEquals($expected, $this->getProperty($solr, 'filters')); + } +} -- GitLab