Make tests work
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Mon, 14 Oct 2013 19:22:24 +0000 (21:22 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Fri, 1 Nov 2013 15:20:17 +0000 (16:20 +0100)
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
classes/pltestcase.php
classes/pltestsuite.php
include/test.inc.php
ut/enginetest.php

index 7fc22f1..3f52ca9 100644 (file)
@@ -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
 {
 }
index 6858a55..fa3ccaf 100644 (file)
@@ -20,7 +20,6 @@
  ***************************************************************************/
 
 require_once dirname(__FILE__) . '/../include/test.inc.php';
-require_once 'PHPUnit/Framework.php';
 
 class PlTestSuite
 {
index c29f152..e885cfa 100644 (file)
  *  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);
+        }
     }
 }
 
index 1aeed16..e8132c6 100644 (file)
  ***************************************************************************/
 
 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);