]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | use Shaarli\Config\ConfigManager; | |
3 | use Shaarli\Plugin\PluginManager; | |
4 | ||
5 | /** | |
6 | * PluginWallabagTest.php.php | |
7 | */ | |
8 | ||
9 | require_once 'plugins/wallabag/wallabag.php'; | |
10 | ||
11 | /** | |
12 | * Class PluginWallabagTest | |
13 | * Unit test for the Wallabag plugin | |
14 | */ | |
15 | class PluginWallabagTest extends \PHPUnit\Framework\TestCase | |
16 | { | |
17 | /** | |
18 | * Reset plugin path | |
19 | */ | |
20 | public function setUp() | |
21 | { | |
22 | PluginManager::$PLUGINS_PATH = 'plugins'; | |
23 | } | |
24 | ||
25 | /** | |
26 | * Test wallabag init without errors. | |
27 | */ | |
28 | public function testWallabagInitNoError() | |
29 | { | |
30 | $conf = new ConfigManager(''); | |
31 | $conf->set('plugins.WALLABAG_URL', 'value'); | |
32 | $errors = wallabag_init($conf); | |
33 | $this->assertEmpty($errors); | |
34 | } | |
35 | ||
36 | /** | |
37 | * Test wallabag init with errors. | |
38 | */ | |
39 | public function testWallabagInitError() | |
40 | { | |
41 | $conf = new ConfigManager(''); | |
42 | $errors = wallabag_init($conf); | |
43 | $this->assertNotEmpty($errors); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Test render_linklist hook. | |
48 | */ | |
49 | public function testWallabagLinklist() | |
50 | { | |
51 | $conf = new ConfigManager(''); | |
52 | $conf->set('plugins.WALLABAG_URL', 'value'); | |
53 | $str = 'http://randomstr.com/test'; | |
54 | $data = array( | |
55 | 'title' => $str, | |
56 | 'links' => array( | |
57 | array( | |
58 | 'url' => $str, | |
59 | ) | |
60 | ) | |
61 | ); | |
62 | ||
63 | $data = hook_wallabag_render_linklist($data, $conf); | |
64 | $link = $data['links'][0]; | |
65 | // data shouldn't be altered | |
66 | $this->assertEquals($str, $data['title']); | |
67 | $this->assertEquals($str, $link['url']); | |
68 | ||
69 | // plugin data | |
70 | $this->assertEquals(1, count($link['link_plugin'])); | |
71 | $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str))); | |
72 | $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL'))); | |
73 | } | |
74 | } |