]>
Commit | Line | Data |
---|---|---|
1696f6aa | 1 | <?php |
95854417 V |
2 | namespace Shaarli\Plugin\Wallabag; |
3 | ||
3c66e564 | 4 | use Shaarli\Config\ConfigManager; |
e1850388 | 5 | use Shaarli\Plugin\PluginManager; |
1696f6aa | 6 | |
1696f6aa A |
7 | require_once 'plugins/wallabag/wallabag.php'; |
8 | ||
9 | /** | |
10 | * Class PluginWallabagTest | |
11 | * Unit test for the Wallabag plugin | |
12 | */ | |
a5a9cf23 | 13 | class PluginWallabagTest extends \Shaarli\TestCase |
1696f6aa A |
14 | { |
15 | /** | |
16 | * Reset plugin path | |
17 | */ | |
8f60e120 | 18 | protected function setUp(): void |
1696f6aa A |
19 | { |
20 | PluginManager::$PLUGINS_PATH = 'plugins'; | |
21 | } | |
22 | ||
7fde6de1 A |
23 | /** |
24 | * Test wallabag init without errors. | |
25 | */ | |
93b1fe54 | 26 | public function testWallabagInitNoError() |
7fde6de1 A |
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 | */ | |
93b1fe54 | 37 | public function testWallabagInitError() |
7fde6de1 A |
38 | { |
39 | $conf = new ConfigManager(''); | |
40 | $errors = wallabag_init($conf); | |
41 | $this->assertNotEmpty($errors); | |
42 | } | |
43 | ||
1696f6aa A |
44 | /** |
45 | * Test render_linklist hook. | |
46 | */ | |
93b1fe54 | 47 | public function testWallabagLinklist() |
1696f6aa | 48 | { |
51def0d8 | 49 | $conf = new ConfigManager(''); |
eeea1c3d | 50 | $conf->set('plugins.WALLABAG_URL', 'value'); |
1696f6aa | 51 | $str = 'http://randomstr.com/test'; |
358cb20b | 52 | $data = [ |
1696f6aa | 53 | 'title' => $str, |
358cb20b A |
54 | 'links' => [ |
55 | [ | |
1696f6aa | 56 | 'url' => $str, |
358cb20b A |
57 | ] |
58 | ], | |
59 | '_LOGGEDIN_' => true, | |
60 | ]; | |
1696f6aa | 61 | |
51def0d8 | 62 | $data = hook_wallabag_render_linklist($data, $conf); |
1696f6aa A |
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'])); | |
938d9cce | 70 | $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str))); |
eeea1c3d | 71 | $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL'))); |
1696f6aa | 72 | } |
358cb20b A |
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 | } | |
1696f6aa | 95 | } |