Unit tests for Router and PluginManager.
This commit is contained in:
parent
567967fdf9
commit
d06265fb57
4 changed files with 184 additions and 184 deletions
74
tests/ConfigTest.php
Executable file → Normal file
74
tests/ConfigTest.php
Executable file → Normal file
|
@ -11,14 +11,14 @@
|
||||||
class ConfigTest extends PHPUnit_Framework_TestCase
|
class ConfigTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
// Configuration input set.
|
// Configuration input set.
|
||||||
private static $_configFields;
|
private static $configFields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executed before each test.
|
* Executed before each test.
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
self::$_configFields = array(
|
self::$configFields = array(
|
||||||
'login' => 'login',
|
'login' => 'login',
|
||||||
'hash' => 'hash',
|
'hash' => 'hash',
|
||||||
'salt' => 'salt',
|
'salt' => 'salt',
|
||||||
|
@ -44,8 +44,8 @@ public function setUp()
|
||||||
*/
|
*/
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (is_file(self::$_configFields['config']['CONFIG_FILE'])) {
|
if (is_file(self::$configFields['config']['CONFIG_FILE'])) {
|
||||||
unlink(self::$_configFields['config']['CONFIG_FILE']);
|
unlink(self::$configFields['config']['CONFIG_FILE']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,20 +54,20 @@ public function tearDown()
|
||||||
*/
|
*/
|
||||||
public function testWriteConfig()
|
public function testWriteConfig()
|
||||||
{
|
{
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
|
|
||||||
include self::$_configFields['config']['CONFIG_FILE'];
|
include self::$configFields['config']['CONFIG_FILE'];
|
||||||
$this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
|
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
|
||||||
$this->assertEquals(self::$_configFields['hash'], $GLOBALS['hash']);
|
$this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']);
|
||||||
$this->assertEquals(self::$_configFields['salt'], $GLOBALS['salt']);
|
$this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']);
|
||||||
$this->assertEquals(self::$_configFields['timezone'], $GLOBALS['timezone']);
|
$this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']);
|
||||||
$this->assertEquals(self::$_configFields['title'], $GLOBALS['title']);
|
$this->assertEquals(self::$configFields['title'], $GLOBALS['title']);
|
||||||
$this->assertEquals(self::$_configFields['titleLink'], $GLOBALS['titleLink']);
|
$this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']);
|
||||||
$this->assertEquals(self::$_configFields['redirector'], $GLOBALS['redirector']);
|
$this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']);
|
||||||
$this->assertEquals(self::$_configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
|
$this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
|
||||||
$this->assertEquals(self::$_configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
|
$this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
|
||||||
$this->assertEquals(self::$_configFields['config']['config1'], $GLOBALS['config']['config1']);
|
$this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']);
|
||||||
$this->assertEquals(self::$_configFields['config']['config2'], $GLOBALS['config']['config2']);
|
$this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,14 +79,14 @@ public function testWriteConfig()
|
||||||
*/
|
*/
|
||||||
public function testWriteConfigFieldUpdate()
|
public function testWriteConfigFieldUpdate()
|
||||||
{
|
{
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
self::$_configFields['title'] = 'ok';
|
self::$configFields['title'] = 'ok';
|
||||||
self::$_configFields['config']['config1'] = 'ok';
|
self::$configFields['config']['config1'] = 'ok';
|
||||||
self::$_configFields['config']['config_new'] = 'ok';
|
self::$configFields['config']['config_new'] = 'ok';
|
||||||
self::$_configFields['new'] = 'should not be saved';
|
self::$configFields['new'] = 'should not be saved';
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
|
|
||||||
include self::$_configFields['config']['CONFIG_FILE'];
|
include self::$configFields['config']['CONFIG_FILE'];
|
||||||
$this->assertEquals('ok', $GLOBALS['title']);
|
$this->assertEquals('ok', $GLOBALS['title']);
|
||||||
$this->assertEquals('ok', $GLOBALS['config']['config1']);
|
$this->assertEquals('ok', $GLOBALS['config']['config1']);
|
||||||
$this->assertEquals('ok', $GLOBALS['config']['config_new']);
|
$this->assertEquals('ok', $GLOBALS['config']['config_new']);
|
||||||
|
@ -110,8 +110,8 @@ public function testWriteConfigEmpty()
|
||||||
*/
|
*/
|
||||||
public function testWriteConfigMissingField()
|
public function testWriteConfigMissingField()
|
||||||
{
|
{
|
||||||
unset(self::$_configFields['login']);
|
unset(self::$configFields['login']);
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +119,7 @@ public function testWriteConfigMissingField()
|
||||||
*/
|
*/
|
||||||
public function testWriteConfigLoggedOutNoFile()
|
public function testWriteConfigLoggedOutNoFile()
|
||||||
{
|
{
|
||||||
writeConfig(self::$_configFields, false);
|
writeConfig(self::$configFields, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,8 +129,8 @@ public function testWriteConfigLoggedOutNoFile()
|
||||||
*/
|
*/
|
||||||
public function testWriteConfigLoggedOutWithFile()
|
public function testWriteConfigLoggedOutWithFile()
|
||||||
{
|
{
|
||||||
file_put_contents(self::$_configFields['config']['CONFIG_FILE'], '');
|
file_put_contents(self::$configFields['config']['CONFIG_FILE'], '');
|
||||||
writeConfig(self::$_configFields, false);
|
writeConfig(self::$configFields, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,8 +143,8 @@ public function testWriteConfigLoggedOutWithFile()
|
||||||
public function testMergeDeprecatedConfig()
|
public function testMergeDeprecatedConfig()
|
||||||
{
|
{
|
||||||
// init
|
// init
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
$configCopy = self::$_configFields;
|
$configCopy = self::$configFields;
|
||||||
$invert = !$configCopy['privateLinkByDefault'];
|
$invert = !$configCopy['privateLinkByDefault'];
|
||||||
$configCopy['privateLinkByDefault'] = $invert;
|
$configCopy['privateLinkByDefault'] = $invert;
|
||||||
|
|
||||||
|
@ -155,10 +155,10 @@ public function testMergeDeprecatedConfig()
|
||||||
$this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
|
$this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
|
||||||
|
|
||||||
// merge configs
|
// merge configs
|
||||||
mergeDeprecatedConfig(self::$_configFields, true);
|
mergeDeprecatedConfig(self::$configFields, true);
|
||||||
|
|
||||||
// make sure updated field is changed
|
// make sure updated field is changed
|
||||||
include self::$_configFields['config']['CONFIG_FILE'];
|
include self::$configFields['config']['CONFIG_FILE'];
|
||||||
$this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
|
$this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
|
||||||
$this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
|
$this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
|
||||||
}
|
}
|
||||||
|
@ -168,10 +168,10 @@ public function testMergeDeprecatedConfig()
|
||||||
*/
|
*/
|
||||||
public function testMergeDeprecatedConfigNoFile()
|
public function testMergeDeprecatedConfigNoFile()
|
||||||
{
|
{
|
||||||
writeConfig(self::$_configFields, true);
|
writeConfig(self::$configFields, true);
|
||||||
mergeDeprecatedConfig(self::$_configFields, true);
|
mergeDeprecatedConfig(self::$configFields, true);
|
||||||
|
|
||||||
include self::$_configFields['config']['CONFIG_FILE'];
|
include self::$configFields['config']['CONFIG_FILE'];
|
||||||
$this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
|
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
tests/PluginManagerTest.php
Executable file → Normal file
12
tests/PluginManagerTest.php
Executable file → Normal file
|
@ -13,15 +13,15 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Path to tests plugin.
|
* Path to tests plugin.
|
||||||
* @var string $_PLUGIN_PATH
|
* @var string $pluginPath
|
||||||
*/
|
*/
|
||||||
private static $_PLUGIN_PATH = 'tests/plugins';
|
private static $pluginPath = 'tests/plugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test plugin.
|
* Test plugin.
|
||||||
* @var string $_PLUGIN_NAME
|
* @var string $pluginName
|
||||||
*/
|
*/
|
||||||
private static $_PLUGIN_NAME = 'test';
|
private static $pluginName = 'test';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test plugin loading and hook execution.
|
* Test plugin loading and hook execution.
|
||||||
|
@ -32,8 +32,8 @@ public function testPlugin()
|
||||||
{
|
{
|
||||||
$pluginManager = PluginManager::getInstance();
|
$pluginManager = PluginManager::getInstance();
|
||||||
|
|
||||||
PluginManager::$PLUGINS_PATH = self::$_PLUGIN_PATH;
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||||
$pluginManager->load(array(self::$_PLUGIN_NAME));
|
$pluginManager->load(array(self::$pluginName));
|
||||||
|
|
||||||
$this->assertTrue(function_exists('hook_test_random'));
|
$this->assertTrue(function_exists('hook_test_random'));
|
||||||
|
|
||||||
|
|
0
tests/RouterTest.php
Executable file → Normal file
0
tests/RouterTest.php
Executable file → Normal file
0
tests/plugins/test/test.php
Executable file → Normal file
0
tests/plugins/test/test.php
Executable file → Normal file
Loading…
Reference in a new issue