diff options
Diffstat (limited to 'tests/plugins/PluginIssoTest.php')
-rw-r--r-- | tests/plugins/PluginIssoTest.php | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php new file mode 100644 index 00000000..6b7904dd --- /dev/null +++ b/tests/plugins/PluginIssoTest.php | |||
@@ -0,0 +1,151 @@ | |||
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 | $date = '20161118_100001'; | ||
51 | $data = array( | ||
52 | 'title' => $str, | ||
53 | 'links' => array( | ||
54 | array( | ||
55 | 'id' => 12, | ||
56 | 'url' => $str, | ||
57 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), | ||
58 | ) | ||
59 | ) | ||
60 | ); | ||
61 | |||
62 | $data = hook_isso_render_linklist($data, $conf); | ||
63 | |||
64 | // data shouldn't be altered | ||
65 | $this->assertEquals($str, $data['title']); | ||
66 | $this->assertEquals($str, $data['links'][0]['url']); | ||
67 | |||
68 | // plugin data | ||
69 | $this->assertEquals(1, count($data['plugin_end_zone'])); | ||
70 | $this->assertNotFalse(strpos( | ||
71 | $data['plugin_end_zone'][0], | ||
72 | 'data-isso-id="'. $data['links'][0]['id'] .'"' | ||
73 | )); | ||
74 | $this->assertNotFalse(strpos( | ||
75 | $data['plugin_end_zone'][0], | ||
76 | 'data-title="'. $data['links'][0]['id'] .'"' | ||
77 | )); | ||
78 | $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * Test isso plugin when multiple links are displayed (shouldn't be displayed). | ||
83 | */ | ||
84 | function testIssoMultipleLinks() | ||
85 | { | ||
86 | $conf = new ConfigManager(''); | ||
87 | $conf->set('plugins.ISSO_SERVER', 'value'); | ||
88 | |||
89 | $str = 'http://randomstr.com/test'; | ||
90 | $date1 = '20161118_100001'; | ||
91 | $date2 = '20161118_100002'; | ||
92 | $data = array( | ||
93 | 'title' => $str, | ||
94 | 'links' => array( | ||
95 | array( | ||
96 | 'id' => 12, | ||
97 | 'url' => $str, | ||
98 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), | ||
99 | ), | ||
100 | array( | ||
101 | 'id' => 13, | ||
102 | 'url' => $str . '2', | ||
103 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), | ||
104 | ), | ||
105 | ) | ||
106 | ); | ||
107 | |||
108 | $processed = hook_isso_render_linklist($data, $conf); | ||
109 | // data shouldn't be altered | ||
110 | $this->assertEquals($data, $processed); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * Test isso plugin when using search (shouldn't be displayed). | ||
115 | */ | ||
116 | function testIssoNotDisplayedWhenSearch() | ||
117 | { | ||
118 | $conf = new ConfigManager(''); | ||
119 | $conf->set('plugins.ISSO_SERVER', 'value'); | ||
120 | |||
121 | $str = 'http://randomstr.com/test'; | ||
122 | $date = '20161118_100001'; | ||
123 | $data = array( | ||
124 | 'title' => $str, | ||
125 | 'links' => array( | ||
126 | array( | ||
127 | 'id' => 12, | ||
128 | 'url' => $str, | ||
129 | 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), | ||
130 | ) | ||
131 | ), | ||
132 | 'search_term' => $str | ||
133 | ); | ||
134 | |||
135 | $processed = hook_isso_render_linklist($data, $conf); | ||
136 | |||
137 | // data shouldn't be altered | ||
138 | $this->assertEquals($data, $processed); | ||
139 | } | ||
140 | |||
141 | /** | ||
142 | * Test isso plugin without server configuration (shouldn't be displayed). | ||
143 | */ | ||
144 | function testIssoWithoutConf() | ||
145 | { | ||
146 | $data = 'abc'; | ||
147 | $conf = new ConfigManager(''); | ||
148 | $processed = hook_isso_render_linklist($data, $conf); | ||
149 | $this->assertEquals($data, $processed); | ||
150 | } | ||
151 | } | ||