]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/plugins/PluginIssoTest.php
1f545c7d6e4e01c69c3407471839f4334dad8237
[github/shaarli/Shaarli.git] / tests / plugins / PluginIssoTest.php
1 <?php
2
3 require_once 'plugins/isso/isso.php';
4
5 /**
6 * Class PluginIssoTest
7 *
8 * Test the Isso plugin (comment system).
9 */
10 class PluginIssoTest extends PHPUnit_Framework_TestCase
11 {
12 /**
13 * Reset plugin path
14 */
15 function setUp()
16 {
17 PluginManager::$PLUGINS_PATH = 'plugins';
18 }
19
20 /**
21 * Test Isso init without errors.
22 */
23 function testWallabagInitNoError()
24 {
25 $conf = new ConfigManager('');
26 $conf->set('plugins.ISSO_SERVER', 'value');
27 $errors = isso_init($conf);
28 $this->assertEmpty($errors);
29 }
30
31 /**
32 * Test Isso init with errors.
33 */
34 function testWallabagInitError()
35 {
36 $conf = new ConfigManager('');
37 $errors = isso_init($conf);
38 $this->assertNotEmpty($errors);
39 }
40
41 /**
42 * Test render_linklist hook with valid settings to display the comment form.
43 */
44 function testIssoDisplayed()
45 {
46 $conf = new ConfigManager('');
47 $conf->set('plugins.ISSO_SERVER', 'value');
48
49 $str = 'http://randomstr.com/test';
50 $data = array(
51 'title' => $str,
52 'links' => array(
53 array(
54 'url' => $str,
55 'linkdate' => 'abc',
56 )
57 )
58 );
59
60 $data = hook_isso_render_linklist($data, $conf);
61
62 // data shouldn't be altered
63 $this->assertEquals($str, $data['title']);
64 $this->assertEquals($str, $data['links'][0]['url']);
65
66 // plugin data
67 $this->assertEquals(1, count($data['plugin_end_zone']));
68 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc'));
69 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
70 }
71
72 /**
73 * Test isso plugin when multiple links are displayed (shouldn't be displayed).
74 */
75 function testIssoMultipleLinks()
76 {
77 $conf = new ConfigManager('');
78 $conf->set('plugins.ISSO_SERVER', 'value');
79
80 $str = 'http://randomstr.com/test';
81 $data = array(
82 'title' => $str,
83 'links' => array(
84 array(
85 'url' => $str,
86 'linkdate' => 'abc',
87 ),
88 array(
89 'url' => $str . '2',
90 'linkdate' => 'abc2',
91 ),
92 )
93 );
94
95 $processed = hook_isso_render_linklist($data, $conf);
96 // data shouldn't be altered
97 $this->assertEquals($data, $processed);
98 }
99
100 /**
101 * Test isso plugin when using search (shouldn't be displayed).
102 */
103 function testIssoNotDisplayedWhenSearch()
104 {
105 $conf = new ConfigManager('');
106 $conf->set('plugins.ISSO_SERVER', 'value');
107
108 $str = 'http://randomstr.com/test';
109 $data = array(
110 'title' => $str,
111 'links' => array(
112 array(
113 'url' => $str,
114 'linkdate' => 'abc',
115 )
116 ),
117 'search_term' => $str
118 );
119
120 $processed = hook_isso_render_linklist($data, $conf);
121
122 // data shouldn't be altered
123 $this->assertEquals($data, $processed);
124 }
125
126 /**
127 * Test isso plugin without server configuration (shouldn't be displayed).
128 */
129 function testIssoWithoutConf()
130 {
131 $data = 'abc';
132 $conf = new ConfigManager('');
133 $processed = hook_isso_render_linklist($data, $conf);
134 $this->assertEquals($data, $processed);
135 }
136 }