forked from shaarli/Shaarli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for Router and PluginManager.
- Loading branch information
1 parent
1108fea
commit ffba1ce
Showing
3 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* Plugin tests | ||
*/ | ||
|
||
require_once 'application/Plugin.php'; | ||
|
||
/** | ||
* Unit tests for Plugins | ||
*/ | ||
class PluginTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var string - path to tests plugin | ||
*/ | ||
private static $_PLUGIN_PATH = 'tests/plugins'; | ||
|
||
/** | ||
* @var string - test plugin. | ||
*/ | ||
private static $_PLUGIN_NAME = 'test'; | ||
|
||
/** | ||
* Executed before each test. | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Executed after each test. | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Test plugin loading and hook execution. | ||
* | ||
* @return void | ||
*/ | ||
public function testPlugin() { | ||
PluginManager::$PLUGINS_PATH = self::$_PLUGIN_PATH; | ||
PluginManager::$AUTHORIZED_PLUGINS = array(self::$_PLUGIN_NAME); | ||
PluginManager::load(); | ||
|
||
$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::$AUTHORIZED_PLUGINS = array(); | ||
PluginManager::load(); | ||
|
||
PluginManager::$AUTHORIZED_PLUGINS = array('nope', 'renope'); | ||
PluginManager::load(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
|
||
/** | ||
* Router tests | ||
*/ | ||
|
||
require_once 'application/Router.php'; | ||
|
||
/** | ||
* Unit tests for Router | ||
*/ | ||
class RouterTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Test findPage: login page output. | ||
*/ | ||
public function testFindPageLogin() { | ||
$this->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&stuff2', array(), false)); | ||
$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. | ||
*/ | ||
public function testFindPagePicwall() { | ||
$this->assertEquals(Router::$PAGE_PICWALL, Router::findPage('do=picwall', array(), false)); | ||
$this->assertEquals(Router::$PAGE_PICWALL, Router::findPage('do=picwall', array(), true)); | ||
$this->assertEquals(Router::$PAGE_PICWALL, | ||
Router::findPage('do=picwall&stuff&stuff2', array(), false)); | ||
$this->assertNotEquals(Router::$PAGE_PICWALL, Router::findPage('do=other', array(), false)); | ||
} | ||
|
||
/** | ||
* Test findPage: tagcloud page output. | ||
*/ | ||
public function testFindPageTagcloud() { | ||
$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&stuff2', array(), false)); | ||
$this->assertNotEquals(Router::$PAGE_TAGCLOUD, Router::findPage('do=other', array(), false)); | ||
} | ||
|
||
/** | ||
* Test findPage: linklist page output. | ||
*/ | ||
public function testFindPageLinklist() { | ||
$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. | ||
*/ | ||
public function testFindPageTools() { | ||
$this->assertEquals(Router::$PAGE_TOOLS, Router::findPage('do=tools', array(), true)); | ||
$this->assertEquals(Router::$PAGE_TOOLS, | ||
Router::findPage('do=tools&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageChangepasswd() { | ||
$this->assertEquals(Router::$PAGE_CHANGEPASSWORD, Router::findPage('do=changepasswd', array(), true)); | ||
$this->assertEquals(Router::$PAGE_CHANGEPASSWORD, | ||
Router::findPage('do=changepasswd&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageConfigure() { | ||
$this->assertEquals(Router::$PAGE_CONFIGURE, Router::findPage('do=configure', array(), true)); | ||
$this->assertEquals(Router::$PAGE_CONFIGURE, | ||
Router::findPage('do=configure&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageChangetag() { | ||
$this->assertEquals(Router::$PAGE_CHANGETAG, Router::findPage('do=changetag', array(), true)); | ||
$this->assertEquals(Router::$PAGE_CHANGETAG, | ||
Router::findPage('do=changetag&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageAddlink() { | ||
$this->assertEquals(Router::$PAGE_ADDLINK, Router::findPage('do=addlink', array(), true)); | ||
$this->assertEquals(Router::$PAGE_ADDLINK, | ||
Router::findPage('do=addlink&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageExport() { | ||
$this->assertEquals(Router::$PAGE_EXPORT, Router::findPage('do=export', array(), true)); | ||
$this->assertEquals(Router::$PAGE_EXPORT, | ||
Router::findPage('do=export&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageImport() { | ||
$this->assertEquals(Router::$PAGE_IMPORT, Router::findPage('do=import', array(), true)); | ||
$this->assertEquals(Router::$PAGE_IMPORT, | ||
Router::findPage('do=import&stuff&stuff2', array(), true)); | ||
$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. | ||
*/ | ||
public function testFindPageEditlink() { | ||
$this->assertEquals(Router::$PAGE_EDITLINK, Router::findPage('whatever', 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)); | ||
$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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* Hook for test. | ||
* | ||
* @param array $data - data passed to plugin. | ||
* @return mixed altered data. | ||
*/ | ||
function hook_test_random($data) { | ||
if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') { | ||
$data[1] = 'page test'; | ||
} | ||
else if (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) { | ||
$data[1] = 'loggedin'; | ||
} | ||
else { | ||
$data[1] = $data[0]; | ||
} | ||
|
||
return $data; | ||
} |