diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/EIT/BackendTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/EIT/BackendTest.php new file mode 100644 index 0000000000000000000000000000000000000000..efb72cdbc895f42d5b08cd44b0d0393c40dd4522 --- /dev/null +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/EIT/BackendTest.php @@ -0,0 +1,109 @@ +<?php + +/** + * Unit tests for EIT backend. + * + * 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 Search + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org + */ + +namespace VuFindTest\Backend\EIT; + +use VuFindSearch\Backend\EIT\Backend; +use VuFindSearch\Backend\EIT\Response\RecordCollectionFactory; +use VuFindSearch\ParamBag; +use VuFindSearch\Query\Query; +use PHPUnit_Framework_TestCase; +use InvalidArgumentException; + +/** + * Unit tests for EIT backend. + * + * @category VuFind2 + * @package Search + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org + */ +class BackendTest extends \VuFindTest\Unit\TestCase +{ + /** + * Test setting a query builder. + * + * @return void + */ + public function testSetQueryBuilder() + { + $qb = new \VuFindSearch\Backend\EIT\QueryBuilder(); + $back = new Backend($this->getConnectorMock(), $this->getRCFactory()); + $back->setQueryBuilder($qb); + $this->assertEquals($qb, $back->getQueryBuilder()); + } + + /** + * Test setting a custom record collection factory. + * + * @return void + */ + public function testConstructorSetters() + { + $fact = $this->getMock('VuFindSearch\Response\RecordCollectionFactoryInterface'); + $conn = $this->getConnectorMock(); + $back = new Backend($conn, $fact); + $this->assertEquals($fact, $back->getRecordCollectionFactory()); + $this->assertEquals($conn, $back->getConnector()); + } + + /// Internal API + + /** + * Return connector mock. + * + * @param array $mock Functions to mock + * + * @return array + */ + protected function getConnectorMock(array $mock = array()) + { + $client = $this->getMock('Zend\Http\Client'); + return $this->getMock( + 'VuFindSearch\Backend\EIT\Connector', $mock, + array('http://fake', $client, 'profile', 'pwd', 'dbs') + ); + } + + /** + * Build a real record collection factory + * + * @return \VuFindSearch\Backend\EIT\Response\XML\RecordCollectionFactory + */ + protected function getRCFactory() + { + $callback = function ($data) { + $driver = new \VuFind\RecordDriver\EIT(); + $driver->setRawData($data); + return $driver; + }; + return new \VuFindSearch\Backend\EIT\Response\XML\RecordCollectionFactory($callback); + } +}