From cb2f08fe9124cba0539f0798a6ec1ea78bbdb2d6 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 10 Sep 2013 11:37:23 -0400 Subject: [PATCH] Set up test infrastructure for VuFindConsole module. --- module/VuFind/tests/bootstrap.php | 1 + module/VuFind/tests/phpunit.xml | 3 + .../tests/unit-tests/bootstrap.php | 22 ++++ .../tests/unit-tests/phpunit.xml | 12 ++ .../Mvc/Router/ConsoleRouterTest.php | 105 ++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 module/VuFindConsole/tests/unit-tests/bootstrap.php create mode 100644 module/VuFindConsole/tests/unit-tests/phpunit.xml create mode 100644 module/VuFindConsole/tests/unit-tests/src/VuFindTest/Mvc/Router/ConsoleRouterTest.php diff --git a/module/VuFind/tests/bootstrap.php b/module/VuFind/tests/bootstrap.php index 8080bf762bc..9dba5e9d598 100644 --- a/module/VuFind/tests/bootstrap.php +++ b/module/VuFind/tests/bootstrap.php @@ -37,6 +37,7 @@ if (file_exists('vendor/autoload.php')) { $loader->add('VuFindTest', __DIR__ . '/unit-tests/src'); $loader->add('VuFindTest', __DIR__ . '/../src'); $loader->add('VuFind', __DIR__ . '/../src'); + $loader->add('VuFindConsole', __DIR__ . '/../../VuFindConsole/src'); $loader->add('VuFindHttp', __DIR__ . '/../../VuFindHttp/src'); $loader->add('VuFindSearch', __DIR__ . '/../../VuFindSearch/src'); $loader->add('VuFindTheme', __DIR__ . '/../../VuFindTheme/src'); diff --git a/module/VuFind/tests/phpunit.xml b/module/VuFind/tests/phpunit.xml index adb9a8286d5..fbfdb6ff531 100644 --- a/module/VuFind/tests/phpunit.xml +++ b/module/VuFind/tests/phpunit.xml @@ -1,5 +1,8 @@ <phpunit bootstrap="./bootstrap.php" backupGlobals="false"> <testsuites> + <testsuite name="VuFindConsole"> + <directory>../../VuFindConsole/tests/unit-tests/src</directory> + </testsuite> <testsuite name="VuFindHttp"> <directory>../../VuFindHttp/tests/unit-tests/src</directory> </testsuite> diff --git a/module/VuFindConsole/tests/unit-tests/bootstrap.php b/module/VuFindConsole/tests/unit-tests/bootstrap.php new file mode 100644 index 00000000000..8c386cc5738 --- /dev/null +++ b/module/VuFindConsole/tests/unit-tests/bootstrap.php @@ -0,0 +1,22 @@ +<?php + +/** + * Search subsystem PHPUnit bootstrap. + * + * @author David Maus <maus@hab.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @copyright Copyright (C) Villanova University 2011 + */ + +require_once('Zend/Loader/AutoloaderFactory.php'); +\Zend\Loader\AutoloaderFactory::factory( + array( + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + 'VuFindConsole' => realpath(__DIR__ . '/../../src/VuFindConsole'), + 'VuFindTest' => realpath(__DIR__ . '/src/VuFindTest'), + ), + 'autoregister_zf' => true + ) + ) +); diff --git a/module/VuFindConsole/tests/unit-tests/phpunit.xml b/module/VuFindConsole/tests/unit-tests/phpunit.xml new file mode 100644 index 00000000000..c3eb7bfac23 --- /dev/null +++ b/module/VuFindConsole/tests/unit-tests/phpunit.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<phpunit bootstrap="bootstrap.php" + strict="true"> + <testsuites> + <testsuite name="VuFindConsole"> + <directory>src</directory> + </testsuite> + </testsuites> + <php> + <includePath>../../../../vendor/zendframework/zendframework/library</includePath> + </php> +</phpunit> diff --git a/module/VuFindConsole/tests/unit-tests/src/VuFindTest/Mvc/Router/ConsoleRouterTest.php b/module/VuFindConsole/tests/unit-tests/src/VuFindTest/Mvc/Router/ConsoleRouterTest.php new file mode 100644 index 00000000000..3fc7cbd9754 --- /dev/null +++ b/module/VuFindConsole/tests/unit-tests/src/VuFindTest/Mvc/Router/ConsoleRouterTest.php @@ -0,0 +1,105 @@ +<?php +/** + * ConsoleRouter 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 VuFindTest\Mvc\Router; +use VuFindConsole\Mvc\Router\ConsoleRouter; + +/** + * InjectTemplateListener 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 ConsoleRouterTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test routing. + * + * @return void + */ + public function testRoute() + { + $router = ConsoleRouter::factory(array('pwd' => __DIR__)); + $request = $this->getMock('Zend\Console\Request', array('getScriptName')); + $request->expects($this->any())->method('getScriptName') + ->will($this->returnValue('ConsoleRouterTest.php')); + $result = $router->match($request); + $this->assertEquals($result->getParam('controller'), 'Router'); + $this->assertEquals($result->getParam('action'), 'ConsoleRouterTest'); + } + + /** + * Test addRoute. + * + * @return void + */ + public function testAddRoute() + { + $this->setExpectedException('Exception'); + $router = ConsoleRouter::factory(); + $router->addRoute('fake', 'fake'); + } + + /** + * Test addRoutes. + * + * @return void + */ + public function testAddRoutes() + { + $this->setExpectedException('Exception'); + $router = ConsoleRouter::factory(); + $router->addRoutes(array()); + } + + /** + * Test removeRoute. + * + * @return void + */ + public function testRemoveRoute() + { + $this->setExpectedException('Exception'); + $router = ConsoleRouter::factory(); + $router->removeRoute('fake'); + } + + /** + * Test setRoutes. + * + * @return void + */ + public function testSetRoutes() + { + $this->setExpectedException('Exception'); + $router = ConsoleRouter::factory(); + $router->setRoutes(array()); + } +} \ No newline at end of file -- GitLab