From 535db776ee0008917fd06a4aa2a4783696b43ac3 Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Mon, 14 Oct 2013 21:22:24 +0200 Subject: [PATCH] Make tests work Signed-off-by: Nicolas Iooss --- classes/pltestcase.php | 2 -- classes/pltestsuite.php | 1 - include/test.inc.php | 13 ++++++++---- ut/enginetest.php | 55 +++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/classes/pltestcase.php b/classes/pltestcase.php index 7fc22f1..3f52ca9 100644 --- a/classes/pltestcase.php +++ b/classes/pltestcase.php @@ -19,8 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -require_once 'PHPUnit/Framework.php'; - abstract class PlTestCase extends PHPUnit_Framework_TestCase { } diff --git a/classes/pltestsuite.php b/classes/pltestsuite.php index 6858a55..fa3ccaf 100644 --- a/classes/pltestsuite.php +++ b/classes/pltestsuite.php @@ -20,7 +20,6 @@ ***************************************************************************/ require_once dirname(__FILE__) . '/../include/test.inc.php'; -require_once 'PHPUnit/Framework.php'; class PlTestSuite { diff --git a/include/test.inc.php b/include/test.inc.php index c29f152..e885cfa 100644 --- a/include/test.inc.php +++ b/include/test.inc.php @@ -19,16 +19,21 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +// Include test.inc.php from a parent project, if it exists $testinclude = dirname(__FILE__) . '/../../include/test.inc.php'; if (file_exists($testinclude)) { require_once $testinclude; } else { require_once dirname(__FILE__) . '/platal.inc.php'; - require_once 'PHPUnit/Framework.php'; - function __autoload($class) - { - pl_autoload($class); + if (function_exists('spl_autoload_register')) { + spl_autoload_register('pl_autoload'); + } else { + // Use non-SPL autoloading as a fallback for PHP < 5.1.2 + function __autoload($class) + { + pl_autoload($class); + } } } diff --git a/ut/enginetest.php b/ut/enginetest.php index 1aeed16..e8132c6 100644 --- a/ut/enginetest.php +++ b/ut/enginetest.php @@ -20,7 +20,48 @@ ***************************************************************************/ require_once dirname(__FILE__) . '/../include/test.inc.php'; -__autoload('platal'); + +class TestPlatal extends Platal +{ + public function force_login(PlPage $page) { + throw new Exception('Force login called in a test'); + } +} +class TestSession extends PlSession +{ + protected function doAuth($level) { + throw new Exception('Not implemented test method'); + } + + protected function makePerms($perms, $is_admin) { + throw new Exception('Not implemented test method'); + } + + protected function startSessionAs($user, $level) { + throw new Exception('Not implemented test method'); + } + + public function loggedLevel() { + return AUTH_MDP; + } + + public function startAvailableAuth() { + return true; + } + + public function sureLevel() { + return AUTH_MDP; + } + + public function tokenAuth($login, $token) { + throw new Exception('Not implemented test method'); + } +} +define('PL_GLOBALS_CLASS', 'PlGlobals'); +define('PL_SESSION_CLASS', 'TestSession'); +define('PL_PAGE_CLASS', 'PlPage'); +define('PL_LOGGER_CLASS', 'PlLogger'); +new TestPlatal(); class TestPage extends PlPage { @@ -120,11 +161,13 @@ class EngineTest extends PlTestCase public function testDispatch($res, $expmatched, $path) { $tree = new PlHookTree(); - $tree->addChild(array('test'), new PlStdHook(array('EngineTest', 'blihCallback'))); - $tree->addChild(array('test1'), new PlStdHook(array('EngineTest', 'blahCallback'))); - $tree->addChild(array('tes'), new PlStdHook(array('EngineTest', 'blahCallback'))); - $tree->addChild(array('test', 'coucou'), new PlStdHook(array('EngineTest', 'fooCallback'))); - $tree->addChild(array('test', 'hook'), new PlStdHook(array('EngineTest', 'barCallback'))); + $tree->addChildren(array( + 'test' => new PlStdHook(array('EngineTest', 'blihCallback')), + 'test1' => new PlStdHook(array('EngineTest', 'blahCallback')), + 'tes' => new PlStdHook(array('EngineTest', 'blahCallback')), + 'test/coucou' => new PlStdHook(array('EngineTest', 'fooCallback')), + 'test/hook' => new PlStdHook(array('EngineTest', 'barCallback')) + )); $page = new TestPage(); $p = explode('/', $path); -- 2.1.4