]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/plugins/PluginWallabagTest.php
Merge branch 'master' into v0.12
[github/shaarli/Shaarli.git] / tests / plugins / PluginWallabagTest.php
1 <?php
2 namespace Shaarli\Plugin\Wallabag;
3
4 use Shaarli\Config\ConfigManager;
5 use Shaarli\Plugin\PluginManager;
6
7 require_once 'plugins/wallabag/wallabag.php';
8
9 /**
10 * Class PluginWallabagTest
11 * Unit test for the Wallabag plugin
12 */
13 class PluginWallabagTest extends \Shaarli\TestCase
14 {
15 /**
16 * Reset plugin path
17 */
18 protected function setUp(): void
19 {
20 PluginManager::$PLUGINS_PATH = 'plugins';
21 }
22
23 /**
24 * Test wallabag init without errors.
25 */
26 public function testWallabagInitNoError()
27 {
28 $conf = new ConfigManager('');
29 $conf->set('plugins.WALLABAG_URL', 'value');
30 $errors = wallabag_init($conf);
31 $this->assertEmpty($errors);
32 }
33
34 /**
35 * Test wallabag init with errors.
36 */
37 public function testWallabagInitError()
38 {
39 $conf = new ConfigManager('');
40 $errors = wallabag_init($conf);
41 $this->assertNotEmpty($errors);
42 }
43
44 /**
45 * Test render_linklist hook.
46 */
47 public function testWallabagLinklist()
48 {
49 $conf = new ConfigManager('');
50 $conf->set('plugins.WALLABAG_URL', 'value');
51 $str = 'http://randomstr.com/test';
52 $data = [
53 'title' => $str,
54 'links' => [
55 [
56 'url' => $str,
57 ]
58 ],
59 '_LOGGEDIN_' => true,
60 ];
61
62 $data = hook_wallabag_render_linklist($data, $conf);
63 $link = $data['links'][0];
64 // data shouldn't be altered
65 $this->assertEquals($str, $data['title']);
66 $this->assertEquals($str, $link['url']);
67
68 // plugin data
69 $this->assertEquals(1, count($link['link_plugin']));
70 $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
71 $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
72 }
73
74 /**
75 * Test render_linklist hook while logged out: no change.
76 */
77 public function testWallabagLinklistLoggedOut(): void
78 {
79 $conf = new ConfigManager('');
80 $str = 'http://randomstr.com/test';
81 $data = [
82 'title' => $str,
83 'links' => [
84 [
85 'url' => $str,
86 ]
87 ],
88 '_LOGGEDIN_' => false,
89 ];
90
91 $result = hook_wallabag_render_linklist($data, $conf);
92
93 static::assertSame($data, $result);
94 }
95 }