From 6fc14d530369740d27d6bd641369d4f5f5f04080 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 15 Jul 2015 11:42:15 +0200 Subject: Plugin system - CORE see shaarli/Shaarli#275 --- tests/PluginManagerTest.php | 66 ++++++ tests/RouterTest.php | 515 ++++++++++++++++++++++++++++++++++++++++++++ tests/plugins/test/test.php | 21 ++ 3 files changed, 602 insertions(+) create mode 100755 tests/PluginManagerTest.php create mode 100755 tests/RouterTest.php create mode 100755 tests/plugins/test/test.php (limited to 'tests') diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php new file mode 100755 index 00000000..749ce2b5 --- /dev/null +++ b/tests/PluginManagerTest.php @@ -0,0 +1,66 @@ +load(array(self::$_PLUGIN_NAME)); + + $this->assertTrue(function_exists('hook_test_random')); + + $data = array(0 => 'woot'); + $pluginManager->executeHooks('random', $data); + $this->assertEquals('woot', $data[1]); + + $data = array(0 => 'woot'); + $pluginManager->executeHooks('random', $data, array('target' => 'test')); + $this->assertEquals('page test', $data[1]); + + $data = array(0 => 'woot'); + $pluginManager->executeHooks('random', $data, array('loggedin' => true)); + $this->assertEquals('loggedin', $data[1]); + } + + /** + * Test missing plugin loading. + * + * @return void + */ + public function testPluginNotFound() + { + $pluginManager = PluginManager::getInstance(); + + $pluginManager->load(array()); + + $pluginManager->load(array('nope', 'renope')); + } +} \ No newline at end of file diff --git a/tests/RouterTest.php b/tests/RouterTest.php new file mode 100755 index 00000000..8838bc8d --- /dev/null +++ b/tests/RouterTest.php @@ -0,0 +1,515 @@ +assertEquals( + Router::$PAGE_LOGIN, + Router::findPage('do=login', array(), false) + ); + + $this->assertEquals( + Router::$PAGE_LOGIN, + Router::findPage('do=login', array(), 1) + ); + + $this->assertEquals( + Router::$PAGE_LOGIN, + Router::findPage('do=login&stuff', array(), false) + ); + } + + /** + * Test findPage: login page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageLoginInvalid() + { + $this->assertNotEquals( + Router::$PAGE_LOGIN, + Router::findPage('do=login', array(), true) + ); + + $this->assertNotEquals( + Router::$PAGE_LOGIN, + Router::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: picwall page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPagePicwallValid() + { + $this->assertEquals( + Router::$PAGE_PICWALL, + Router::findPage('do=picwall', array(), false) + ); + + $this->assertEquals( + Router::$PAGE_PICWALL, + Router::findPage('do=picwall', array(), true) + ); + } + + /** + * Test findPage: picwall page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPagePicwallInvalid() + { + $this->assertEquals( + Router::$PAGE_PICWALL, + Router::findPage('do=picwall&stuff', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_PICWALL, + Router::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: tagcloud page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageTagcloudValid() + { + $this->assertEquals( + Router::$PAGE_TAGCLOUD, + Router::findPage('do=tagcloud', array(), false) + ); + + $this->assertEquals( + Router::$PAGE_TAGCLOUD, + Router::findPage('do=tagcloud', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_TAGCLOUD, + Router::findPage('do=tagcloud&stuff', array(), false) + ); + } + + /** + * Test findPage: tagcloud page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageTagcloudInvalid() + { + $this->assertNotEquals( + Router::$PAGE_TAGCLOUD, + Router::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: linklist page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageLinklistValid() + { + $this->assertEquals( + Router::$PAGE_LINKLIST, + Router::findPage('', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_LINKLIST, + Router::findPage('whatever', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_LINKLIST, + Router::findPage('whatever', array(), false) + ); + + $this->assertEquals( + Router::$PAGE_LINKLIST, + Router::findPage('do=tools', array(), false) + ); + } + + /** + * Test findPage: tools page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageToolsValid() + { + $this->assertEquals( + Router::$PAGE_TOOLS, + Router::findPage('do=tools', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_TOOLS, + Router::findPage('do=tools&stuff', array(), true) + ); + } + + /** + * Test findPage: tools page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageToolsInvalid() + { + $this->assertNotEquals( + Router::$PAGE_TOOLS, + Router::findPage('do=tools', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_TOOLS, + Router::findPage('do=tools', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_TOOLS, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: changepasswd page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageChangepasswdValid() + { + $this->assertEquals( + Router::$PAGE_CHANGEPASSWORD, + Router::findPage('do=changepasswd', array(), true) + ); + $this->assertEquals( + Router::$PAGE_CHANGEPASSWORD, + Router::findPage('do=changepasswd&stuff', array(), true) + ); + + } + + /** + * Test findPage: changepasswd page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageChangepasswdInvalid() + { + $this->assertNotEquals( + Router::$PAGE_CHANGEPASSWORD, + Router::findPage('do=changepasswd', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_CHANGEPASSWORD, + Router::findPage('do=changepasswd', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_CHANGEPASSWORD, + Router::findPage('do=other', array(), true) + ); + } + /** + * Test findPage: configure page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageConfigureValid() + { + $this->assertEquals( + Router::$PAGE_CONFIGURE, + Router::findPage('do=configure', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_CONFIGURE, + Router::findPage('do=configure&stuff', array(), true) + ); + } + + /** + * Test findPage: configure page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageConfigureInvalid() + { + $this->assertNotEquals( + Router::$PAGE_CONFIGURE, + Router::findPage('do=configure', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_CONFIGURE, + Router::findPage('do=configure', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_CONFIGURE, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: changetag page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageChangetagValid() + { + $this->assertEquals( + Router::$PAGE_CHANGETAG, + Router::findPage('do=changetag', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_CHANGETAG, + Router::findPage('do=changetag&stuff', array(), true) + ); + } + + /** + * Test findPage: changetag page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageChangetagInvalid() + { + $this->assertNotEquals( + Router::$PAGE_CHANGETAG, + Router::findPage('do=changetag', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_CHANGETAG, + Router::findPage('do=changetag', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_CHANGETAG, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: addlink page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageAddlinkValid() + { + $this->assertEquals( + Router::$PAGE_ADDLINK, + Router::findPage('do=addlink', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_ADDLINK, + Router::findPage('do=addlink&stuff', array(), true) + ); + } + + /** + * Test findPage: addlink page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageAddlinkInvalid() + { + $this->assertNotEquals( + Router::$PAGE_ADDLINK, + Router::findPage('do=addlink', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_ADDLINK, + Router::findPage('do=addlink', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_ADDLINK, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: export page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageExportValid() + { + $this->assertEquals( + Router::$PAGE_EXPORT, + Router::findPage('do=export', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_EXPORT, + Router::findPage('do=export&stuff', array(), true) + ); + } + + /** + * Test findPage: export page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageExportInvalid() + { + $this->assertNotEquals( + Router::$PAGE_EXPORT, + Router::findPage('do=export', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_EXPORT, + Router::findPage('do=export', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_EXPORT, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: import page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageImportValid() + { + $this->assertEquals( + Router::$PAGE_IMPORT, + Router::findPage('do=import', array(), true) + ); + + $this->assertEquals( + Router::$PAGE_IMPORT, + Router::findPage('do=import&stuff', array(), true) + ); + } + + /** + * Test findPage: import page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageImportInvalid() + { + $this->assertNotEquals( + Router::$PAGE_IMPORT, + Router::findPage('do=import', array(), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_IMPORT, + Router::findPage('do=import', array(), false) + ); + + $this->assertNotEquals( + Router::$PAGE_IMPORT, + Router::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: editlink page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageEditlinkValid() + { + $this->assertEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array('edit_link' => 1), true) + ); + + $this->assertEquals( + Router::$PAGE_EDITLINK, + Router::findPage('', array('edit_link' => 1), true) + ); + + + $this->assertEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array('post' => 1), true) + ); + + $this->assertEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array('post' => 1, 'edit_link' => 1), true) + ); + } + + /** + * Test findPage: editlink page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageEditlinkInvalid() + { + $this->assertNotEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array('edit_link' => 1), false) + ); + + $this->assertNotEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array('edit_link' => 1), 1) + ); + + $this->assertNotEquals( + Router::$PAGE_EDITLINK, + Router::findPage('whatever', array(), true) + ); + } +} \ No newline at end of file diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php new file mode 100755 index 00000000..3d750c90 --- /dev/null +++ b/tests/plugins/test/test.php @@ -0,0 +1,21 @@ +