From 41e571e3c1546e3288eb386bdd1f2863bcbb95be Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 17 Apr 2010 22:19:03 +0200 Subject: [PATCH] Add basic tests of the platal engine. Signed-off-by: Florent Bruneau --- classes/platal.php | 2 +- ut/enginetest.php | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 ut/enginetest.php diff --git a/classes/platal.php b/classes/platal.php index 6943174..c23fb53 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -107,7 +107,7 @@ class PlStdHook extends PlHook class PlWikiHook extends PlHook { - public function __construct($callback, $auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH) + public function __construct($auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH) { parent::__construct($auth, $perms, $type); } diff --git a/ut/enginetest.php b/ut/enginetest.php new file mode 100644 index 0000000..414588b --- /dev/null +++ b/ut/enginetest.php @@ -0,0 +1,140 @@ +assertEquals($res, $hook->call($page, $args)); + } + + + public static function dispatchProvider() + { + return array( + array('blih-', 'test', 'test'), + array('blih-', 'test', 'test/'), + array('blih-machin', 'test', 'test/machin'), + array('blih-machin-truc', 'test', 'test/machin/truc'), + + array('blih-hiboo', 'test', 'test/hiboo'), + array('foo', 'test/coucou', 'test/coucou'), + array('foo-', 'test/coucou', 'test/coucou/'), + array('foo-blah', 'test/coucou', 'test/coucou/blah'), + array('foo-blah', 'test/coucou', 'test/coucou/blah/truc') + ); + } + + /** + * @dataProvider dispatchProvider + */ + 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'))); + + $page = new TestPage(); + $p = split('/', $path); + list($hook, $matched, $remain, $aliased) = $tree->findChild($p); + $matched = join('/', $matched); + $this->assertEquals($expmatched, $matched); + array_unshift($remain, $matched); + $this->assertEquals($res, $hook->call($page, $remain)); + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> -- 2.1.4