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