MyShaarli/tests/config/ConfigPluginTest.php
VirtualTam 3c66e56435 application: introduce the Shaarli\Config namespace
Namespaces have been introduced with the REST API, and should be generalized
to the whole codebase to manage object scope and benefit from autoloading.

See:
- https://secure.php.net/manual/en/language.namespaces.php
- http://www.php-fig.org/psr/psr-4/

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
2017-03-04 17:07:52 +01:00

123 lines
3.1 KiB
PHP

<?php
namespace Shaarli\Config;
/**
* Config' tests
*/
require_once 'application/config/ConfigPlugin.php';
/**
* Unitary tests for Shaarli config related functions
*/
class ConfigPluginTest extends \PHPUnit_Framework_TestCase
{
/**
* Test save_plugin_config with valid data.
*
* @throws PluginConfigOrderException
*/
public function testSavePluginConfigValid()
{
$data = array(
'order_plugin1' => 2, // no plugin related
'plugin2' => 0, // new - at the end
'plugin3' => 0, // 2nd
'order_plugin3' => 8,
'plugin4' => 0, // 1st
'order_plugin4' => 5,
);
$expected = array(
'plugin3',
'plugin4',
'plugin2',
);
$out = save_plugin_config($data);
$this->assertEquals($expected, $out);
}
/**
* Test save_plugin_config with invalid data.
*
* @expectedException Shaarli\Config\PluginConfigOrderException
*/
public function testSavePluginConfigInvalid()
{
$data = array(
'plugin2' => 0,
'plugin3' => 0,
'order_plugin3' => 0,
'plugin4' => 0,
'order_plugin4' => 0,
);
save_plugin_config($data);
}
/**
* Test save_plugin_config without data.
*/
public function testSavePluginConfigEmpty()
{
$this->assertEquals(array(), save_plugin_config(array()));
}
/**
* Test validate_plugin_order with valid data.
*/
public function testValidatePluginOrderValid()
{
$data = array(
'order_plugin1' => 2,
'plugin2' => 0,
'plugin3' => 0,
'order_plugin3' => 1,
'plugin4' => 0,
'order_plugin4' => 5,
);
$this->assertTrue(validate_plugin_order($data));
}
/**
* Test validate_plugin_order with invalid data.
*/
public function testValidatePluginOrderInvalid()
{
$data = array(
'order_plugin1' => 2,
'order_plugin3' => 1,
'order_plugin4' => 1,
);
$this->assertFalse(validate_plugin_order($data));
}
/**
* Test load_plugin_parameter_values.
*/
public function testLoadPluginParameterValues()
{
$plugins = array(
'plugin_name' => array(
'parameters' => array(
'param1' => array('value' => true),
'param2' => array('value' => false),
'param3' => array('value' => ''),
)
)
);
$parameters = array(
'param1' => 'value1',
'param2' => 'value2',
);
$result = load_plugin_parameter_values($plugins, $parameters);
$this->assertEquals('value1', $result['plugin_name']['parameters']['param1']['value']);
$this->assertEquals('value2', $result['plugin_name']['parameters']['param2']['value']);
$this->assertEquals('', $result['plugin_name']['parameters']['param3']['value']);
}
}