diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ConfigTest.php | 109 | ||||
-rw-r--r-- | tests/PluginManagerTest.php | 19 | ||||
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 112 | ||||
-rw-r--r-- | tests/plugins/test/test.meta | 2 |
4 files changed, 242 insertions, 0 deletions
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index adebfcc3..492ddd3b 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php | |||
@@ -174,4 +174,113 @@ class ConfigTest extends PHPUnit_Framework_TestCase | |||
174 | include self::$configFields['config']['CONFIG_FILE']; | 174 | include self::$configFields['config']['CONFIG_FILE']; |
175 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); | 175 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); |
176 | } | 176 | } |
177 | |||
178 | /** | ||
179 | * Test save_plugin_config with valid data. | ||
180 | * | ||
181 | * @throws PluginConfigOrderException | ||
182 | */ | ||
183 | public function testSavePluginConfigValid() | ||
184 | { | ||
185 | $data = array( | ||
186 | 'order_plugin1' => 2, // no plugin related | ||
187 | 'plugin2' => 0, // new - at the end | ||
188 | 'plugin3' => 0, // 2nd | ||
189 | 'order_plugin3' => 8, | ||
190 | 'plugin4' => 0, // 1st | ||
191 | 'order_plugin4' => 5, | ||
192 | ); | ||
193 | |||
194 | $expected = array( | ||
195 | 'plugin3', | ||
196 | 'plugin4', | ||
197 | 'plugin2', | ||
198 | ); | ||
199 | |||
200 | $out = save_plugin_config($data); | ||
201 | $this->assertEquals($expected, $out); | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * Test save_plugin_config with invalid data. | ||
206 | * | ||
207 | * @expectedException PluginConfigOrderException | ||
208 | */ | ||
209 | public function testSavePluginConfigInvalid() | ||
210 | { | ||
211 | $data = array( | ||
212 | 'plugin2' => 0, | ||
213 | 'plugin3' => 0, | ||
214 | 'order_plugin3' => 0, | ||
215 | 'plugin4' => 0, | ||
216 | 'order_plugin4' => 0, | ||
217 | ); | ||
218 | |||
219 | save_plugin_config($data); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * Test save_plugin_config without data. | ||
224 | */ | ||
225 | public function testSavePluginConfigEmpty() | ||
226 | { | ||
227 | $this->assertEquals(array(), save_plugin_config(array())); | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * Test validate_plugin_order with valid data. | ||
232 | */ | ||
233 | public function testValidatePluginOrderValid() | ||
234 | { | ||
235 | $data = array( | ||
236 | 'order_plugin1' => 2, | ||
237 | 'plugin2' => 0, | ||
238 | 'plugin3' => 0, | ||
239 | 'order_plugin3' => 1, | ||
240 | 'plugin4' => 0, | ||
241 | 'order_plugin4' => 5, | ||
242 | ); | ||
243 | |||
244 | $this->assertTrue(validate_plugin_order($data)); | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * Test validate_plugin_order with invalid data. | ||
249 | */ | ||
250 | public function testValidatePluginOrderInvalid() | ||
251 | { | ||
252 | $data = array( | ||
253 | 'order_plugin1' => 2, | ||
254 | 'order_plugin3' => 1, | ||
255 | 'order_plugin4' => 1, | ||
256 | ); | ||
257 | |||
258 | $this->assertFalse(validate_plugin_order($data)); | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * Test load_plugin_parameter_values. | ||
263 | */ | ||
264 | public function testLoadPluginParameterValues() | ||
265 | { | ||
266 | $plugins = array( | ||
267 | 'plugin_name' => array( | ||
268 | 'parameters' => array( | ||
269 | 'param1' => true, | ||
270 | 'param2' => false, | ||
271 | 'param3' => '', | ||
272 | ) | ||
273 | ) | ||
274 | ); | ||
275 | |||
276 | $parameters = array( | ||
277 | 'param1' => 'value1', | ||
278 | 'param2' => 'value2', | ||
279 | ); | ||
280 | |||
281 | $result = load_plugin_parameter_values($plugins, $parameters); | ||
282 | $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']); | ||
283 | $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']); | ||
284 | $this->assertEquals('', $result['plugin_name']['parameters']['param3']); | ||
285 | } | ||
177 | } | 286 | } |
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index df2614b5..348082c7 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php | |||
@@ -63,4 +63,23 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase | |||
63 | 63 | ||
64 | $pluginManager->load(array('nope', 'renope')); | 64 | $pluginManager->load(array('nope', 'renope')); |
65 | } | 65 | } |
66 | |||
67 | /** | ||
68 | * Test plugin metadata loading. | ||
69 | */ | ||
70 | public function testGetPluginsMeta() | ||
71 | { | ||
72 | $pluginManager = PluginManager::getInstance(); | ||
73 | |||
74 | PluginManager::$PLUGINS_PATH = self::$pluginPath; | ||
75 | $pluginManager->load(array(self::$pluginName)); | ||
76 | |||
77 | $expectedParameters = array( | ||
78 | 'pop' => '', | ||
79 | 'hip' => '', | ||
80 | ); | ||
81 | $meta = $pluginManager->getPluginsMeta(); | ||
82 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); | ||
83 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); | ||
84 | } | ||
66 | } \ No newline at end of file | 85 | } \ No newline at end of file |
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php new file mode 100644 index 00000000..455f5ba7 --- /dev/null +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -0,0 +1,112 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * PluginMarkdownTest.php | ||
5 | */ | ||
6 | |||
7 | require_once 'application/Utils.php'; | ||
8 | require_once 'plugins/markdown/markdown.php'; | ||
9 | |||
10 | /** | ||
11 | * Class PlugQrcodeTest | ||
12 | * Unit test for the QR-Code plugin | ||
13 | */ | ||
14 | class PluginMarkdownTest extends PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | /** | ||
17 | * Reset plugin path | ||
18 | */ | ||
19 | function setUp() | ||
20 | { | ||
21 | PluginManager::$PLUGINS_PATH = 'plugins'; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Test render_linklist hook. | ||
26 | * Only check that there is basic markdown rendering. | ||
27 | */ | ||
28 | function testMarkdownLinklist() | ||
29 | { | ||
30 | $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; | ||
31 | $data = array( | ||
32 | 'links' => array( | ||
33 | 0 => array( | ||
34 | 'description' => $markdown, | ||
35 | ), | ||
36 | ), | ||
37 | ); | ||
38 | |||
39 | $data = hook_markdown_render_linklist($data); | ||
40 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); | ||
41 | $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Test render_daily hook. | ||
46 | * Only check that there is basic markdown rendering. | ||
47 | */ | ||
48 | function testMarkdownDaily() | ||
49 | { | ||
50 | $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; | ||
51 | $data = array( | ||
52 | // Columns data | ||
53 | 'cols' => array( | ||
54 | // First, second, third. | ||
55 | 0 => array( | ||
56 | // nth link | ||
57 | 0 => array( | ||
58 | 'formatedDescription' => $markdown, | ||
59 | ), | ||
60 | ), | ||
61 | ), | ||
62 | ); | ||
63 | |||
64 | $data = hook_markdown_render_daily($data); | ||
65 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>')); | ||
66 | $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>')); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * Test reverse_text2clickable(). | ||
71 | */ | ||
72 | function testReverseText2clickable() | ||
73 | { | ||
74 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
75 | $clickableText = text2clickable($text, ''); | ||
76 | $reversedText = reverse_text2clickable($clickableText); | ||
77 | $this->assertEquals($text, $reversedText); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Test reverse_nl2br(). | ||
82 | */ | ||
83 | function testReverseNl2br() | ||
84 | { | ||
85 | $text = 'stuff' . PHP_EOL . 'otherstuff'; | ||
86 | $processedText = nl2br($text); | ||
87 | $reversedText = reverse_nl2br($processedText); | ||
88 | $this->assertEquals($text, $reversedText); | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Test reverse_space2nbsp(). | ||
93 | */ | ||
94 | function testReverseSpace2nbsp() | ||
95 | { | ||
96 | $text = ' stuff' . PHP_EOL . ' otherstuff and another'; | ||
97 | $processedText = space2nbsp($text); | ||
98 | $reversedText = reverse_space2nbsp($processedText); | ||
99 | $this->assertEquals($text, $reversedText); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Test reset_quote_tags() | ||
104 | */ | ||
105 | function testResetQuoteTags() | ||
106 | { | ||
107 | $text = '> quote1'. PHP_EOL . ' > quote2 ' . PHP_EOL . 'noquote'; | ||
108 | $processedText = escape($text); | ||
109 | $reversedText = reset_quote_tags($processedText); | ||
110 | $this->assertEquals($text, $reversedText); | ||
111 | } | ||
112 | } | ||
diff --git a/tests/plugins/test/test.meta b/tests/plugins/test/test.meta new file mode 100644 index 00000000..ab999ed4 --- /dev/null +++ b/tests/plugins/test/test.meta | |||
@@ -0,0 +1,2 @@ | |||
1 | description="test plugin" | ||
2 | parameters="pop;hip" \ No newline at end of file | ||