]>
Commit | Line | Data |
---|---|---|
59404d79 | 1 | <?php |
3c66e564 V |
2 | namespace Shaarli\Config; |
3 | ||
e6cd773f | 4 | use Shaarli\Config\Exception\PluginConfigOrderException; |
59404d79 A |
5 | |
6 | require_once 'application/config/ConfigPlugin.php'; | |
7 | ||
8 | /** | |
9 | * Unitary tests for Shaarli config related functions | |
10 | */ | |
3c66e564 | 11 | class ConfigPluginTest extends \PHPUnit_Framework_TestCase |
59404d79 A |
12 | { |
13 | /** | |
14 | * Test save_plugin_config with valid data. | |
15 | * | |
16 | * @throws PluginConfigOrderException | |
17 | */ | |
18 | public function testSavePluginConfigValid() | |
19 | { | |
20 | $data = array( | |
21 | 'order_plugin1' => 2, // no plugin related | |
22 | 'plugin2' => 0, // new - at the end | |
23 | 'plugin3' => 0, // 2nd | |
24 | 'order_plugin3' => 8, | |
25 | 'plugin4' => 0, // 1st | |
26 | 'order_plugin4' => 5, | |
27 | ); | |
28 | ||
29 | $expected = array( | |
30 | 'plugin3', | |
31 | 'plugin4', | |
32 | 'plugin2', | |
33 | ); | |
34 | ||
35 | $out = save_plugin_config($data); | |
36 | $this->assertEquals($expected, $out); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Test save_plugin_config with invalid data. | |
41 | * | |
e6cd773f | 42 | * @expectedException Shaarli\Config\Exception\PluginConfigOrderException |
59404d79 A |
43 | */ |
44 | public function testSavePluginConfigInvalid() | |
45 | { | |
46 | $data = array( | |
47 | 'plugin2' => 0, | |
48 | 'plugin3' => 0, | |
49 | 'order_plugin3' => 0, | |
50 | 'plugin4' => 0, | |
51 | 'order_plugin4' => 0, | |
52 | ); | |
53 | ||
54 | save_plugin_config($data); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Test save_plugin_config without data. | |
59 | */ | |
60 | public function testSavePluginConfigEmpty() | |
61 | { | |
62 | $this->assertEquals(array(), save_plugin_config(array())); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Test validate_plugin_order with valid data. | |
67 | */ | |
68 | public function testValidatePluginOrderValid() | |
69 | { | |
70 | $data = array( | |
71 | 'order_plugin1' => 2, | |
72 | 'plugin2' => 0, | |
73 | 'plugin3' => 0, | |
74 | 'order_plugin3' => 1, | |
75 | 'plugin4' => 0, | |
76 | 'order_plugin4' => 5, | |
77 | ); | |
78 | ||
79 | $this->assertTrue(validate_plugin_order($data)); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Test validate_plugin_order with invalid data. | |
84 | */ | |
85 | public function testValidatePluginOrderInvalid() | |
86 | { | |
87 | $data = array( | |
88 | 'order_plugin1' => 2, | |
89 | 'order_plugin3' => 1, | |
90 | 'order_plugin4' => 1, | |
91 | ); | |
92 | ||
93 | $this->assertFalse(validate_plugin_order($data)); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Test load_plugin_parameter_values. | |
98 | */ | |
99 | public function testLoadPluginParameterValues() | |
100 | { | |
101 | $plugins = array( | |
102 | 'plugin_name' => array( | |
103 | 'parameters' => array( | |
15170b51 A |
104 | 'param1' => array('value' => true), |
105 | 'param2' => array('value' => false), | |
106 | 'param3' => array('value' => ''), | |
59404d79 A |
107 | ) |
108 | ) | |
109 | ); | |
110 | ||
111 | $parameters = array( | |
112 | 'param1' => 'value1', | |
113 | 'param2' => 'value2', | |
114 | ); | |
115 | ||
116 | $result = load_plugin_parameter_values($plugins, $parameters); | |
15170b51 A |
117 | $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']['value']); |
118 | $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']['value']); | |
119 | $this->assertEquals('', $result['plugin_name']['parameters']['param3']['value']); | |
59404d79 A |
120 | } |
121 | } |