From 40c1eeff432f6eaa4a4356f23290c8ce8d9384f6 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 24 Oct 2014 15:10:14 -0400 Subject: [PATCH] Very simple Mink/Zombie.js-based test. --- build.xml | 4 +- .../src/VuFindTest/Unit/MinkTestCase.php | 119 ++++++++++++++++++ .../src/VuFindTest/Mink/BasicTest.php | 54 ++++++++ 3 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 module/VuFind/src/VuFindTest/Unit/MinkTestCase.php create mode 100644 module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php diff --git a/build.xml b/build.xml index 7af6d583120..961ca4d41e3 100644 --- a/build.xml +++ b/build.xml @@ -89,12 +89,12 @@ <!-- PHPUnit --> <target name="phpunit" description="Run tests"> - <exec dir="${srcdir}/module/VuFind/tests" command="NODE_PATH=${nodepath} VUFIND_LOCAL_DIR=${srcdir}/local phpunit -dzend.enable_gc=0 --log-junit ${builddir}/reports/phpunit.xml --coverage-clover ${builddir}/reports/coverage/clover.xml --coverage-html ${builddir}/reports/coverage/" passthru="true" checkreturn="true" /> + <exec dir="${srcdir}/module/VuFind/tests" command="NODE_PATH=${nodepath} VUFIND_LOCAL_DIR=${srcdir}/local VUFIND_URL=${vufindurl} phpunit -dzend.enable_gc=0 --log-junit ${builddir}/reports/phpunit.xml --coverage-clover ${builddir}/reports/coverage/clover.xml --coverage-html ${builddir}/reports/coverage/" passthru="true" checkreturn="true" /> </target> <!-- PHPUnit without logging output --> <target name="phpunitfast" description="Run tests"> - <exec dir="${srcdir}/module/VuFind/tests" command="NODE_PATH=${nodepath} VUFIND_LOCAL_DIR=${srcdir}/local phpunit -dzend.enable_gc=0" passthru="true" checkreturn="true" /> + <exec dir="${srcdir}/module/VuFind/tests" command="NODE_PATH=${nodepath} VUFIND_LOCAL_DIR=${srcdir}/local VUFIND_URL=${vufindurl} phpunit -dzend.enable_gc=0" passthru="true" checkreturn="true" /> </target> <!-- Install and Activate VuFind --> diff --git a/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php new file mode 100644 index 00000000000..109f49a4ece --- /dev/null +++ b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php @@ -0,0 +1,119 @@ +<?php + +/** + * Abstract base class for PHPUnit test cases using Mink. + * + * 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\Unit; +use Behat\Mink\Driver\ZombieDriver, Behat\Mink\Session; + +/** + * Abstract base class for PHPUnit test cases using Mink. + * + * @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 + */ +abstract class MinkTestCase extends TestCase +{ + /** + * Mink driver + * + * @var ZombieDriver + */ + protected static $driver = false; + + /** + * Get the Mink driver, initializing it if necessary. + * + * @return ZombieDriver + */ + protected function getMinkDriver() + { + if (self::$driver === false) { + self::$driver = new ZombieDriver( + new \Behat\Mink\Driver\NodeJS\Server\ZombieServer() + ); + } + return self::$driver; + } + + /** + * Get a Mink session. + * + * @return Session + */ + protected function getMinkSession() + { + return new Session($this->getMinkDriver()); + } + + /** + * Get base URL of running VuFind instance. + * + * @param string $path Relative path to add to base URL. + * + * @return string + */ + protected function getVuFindUrl($path = '') + { + $base = getenv('VUFIND_URL'); + if (empty($base)) { + $base = 'http://localhost/vufind'; + } + return $base . $path; + } + + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI or Zombie.js is unavailable: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); + } + if (strlen(getenv('NODE_PATH')) == 0) { + return $this->markTestSkipped('NODE_PATH setting missing.'); + } + } + + /** + * Standard tear-down. + * + * @return void + */ + public static function tearDownAfterClass() + { + // Stop the Mink driver! + if (self::$driver !== false) { + self::$driver->stop(); + } + } +} diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php new file mode 100644 index 00000000000..1f8017c2bfe --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BasicTest.php @@ -0,0 +1,54 @@ +<?php +/** + * Very simple Mink test class. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2011. + * + * 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://www.vufind.org Main Page + */ +namespace VuFindTest\Mink; + +/** + * Very simple Mink 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://www.vufind.org Main Page + */ +class BasicTest extends \VuFindTest\Unit\MinkTestCase +{ + /** + * Test that the home page is available. + * + * @return void + */ + public function testHomePage() + { + $session = $this->getMinkSession(); + $session->start(); + $session->visit($this->getVuFindUrl()); + $this->assertEquals(200, $session->getStatusCode()); + $this->assertTrue(false !== strstr($session->getPage()->getContent(), 'VuFind')); + } +} -- GitLab