]>
Commit | Line | Data |
---|---|---|
bf26e7eb A |
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'; | |
c3dfd899 | 50 | $date = '20161118_100001'; |
bf26e7eb A |
51 | $data = array( |
52 | 'title' => $str, | |
53 | 'links' => array( | |
54 | array( | |
55 | 'url' => $str, | |
c3dfd899 | 56 | 'created' => DateTime::createFromFormat('Ymd_His', $date), |
bf26e7eb A |
57 | ) |
58 | ) | |
59 | ); | |
60 | ||
61 | $data = hook_isso_render_linklist($data, $conf); | |
62 | ||
63 | // data shouldn't be altered | |
64 | $this->assertEquals($str, $data['title']); | |
65 | $this->assertEquals($str, $data['links'][0]['url']); | |
66 | ||
67 | // plugin data | |
68 | $this->assertEquals(1, count($data['plugin_end_zone'])); | |
c3dfd899 | 69 | $this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date)); |
bf26e7eb A |
70 | $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); |
71 | } | |
72 | ||
73 | /** | |
74 | * Test isso plugin when multiple links are displayed (shouldn't be displayed). | |
75 | */ | |
76 | function testIssoMultipleLinks() | |
77 | { | |
78 | $conf = new ConfigManager(''); | |
79 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
80 | ||
81 | $str = 'http://randomstr.com/test'; | |
c3dfd899 A |
82 | $date1 = '20161118_100001'; |
83 | $date2 = '20161118_100002'; | |
bf26e7eb A |
84 | $data = array( |
85 | 'title' => $str, | |
86 | 'links' => array( | |
87 | array( | |
88 | 'url' => $str, | |
c3dfd899 | 89 | 'created' => DateTime::createFromFormat('Ymd_His', $date1), |
bf26e7eb A |
90 | ), |
91 | array( | |
92 | 'url' => $str . '2', | |
c3dfd899 | 93 | 'created' => DateTime::createFromFormat('Ymd_His', $date2), |
bf26e7eb A |
94 | ), |
95 | ) | |
96 | ); | |
97 | ||
98 | $processed = hook_isso_render_linklist($data, $conf); | |
99 | // data shouldn't be altered | |
100 | $this->assertEquals($data, $processed); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Test isso plugin when using search (shouldn't be displayed). | |
105 | */ | |
106 | function testIssoNotDisplayedWhenSearch() | |
107 | { | |
108 | $conf = new ConfigManager(''); | |
109 | $conf->set('plugins.ISSO_SERVER', 'value'); | |
110 | ||
111 | $str = 'http://randomstr.com/test'; | |
c3dfd899 | 112 | $date = '20161118_100001'; |
bf26e7eb A |
113 | $data = array( |
114 | 'title' => $str, | |
115 | 'links' => array( | |
116 | array( | |
117 | 'url' => $str, | |
c3dfd899 | 118 | 'created' => DateTime::createFromFormat('Ymd_His', $date), |
bf26e7eb A |
119 | ) |
120 | ), | |
121 | 'search_term' => $str | |
122 | ); | |
123 | ||
124 | $processed = hook_isso_render_linklist($data, $conf); | |
125 | ||
126 | // data shouldn't be altered | |
127 | $this->assertEquals($data, $processed); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Test isso plugin without server configuration (shouldn't be displayed). | |
132 | */ | |
133 | function testIssoWithoutConf() | |
134 | { | |
135 | $data = 'abc'; | |
136 | $conf = new ConfigManager(''); | |
137 | $processed = hook_isso_render_linklist($data, $conf); | |
138 | $this->assertEquals($data, $processed); | |
139 | } | |
140 | } |