]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | namespace Shaarli\Plugin\Addlink; | |
3 | ||
4 | use Shaarli\Plugin\PluginManager; | |
5 | use Shaarli\Render\TemplatePage; | |
6 | ||
7 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; | |
8 | ||
9 | /** | |
10 | * Unit test for the Addlink toolbar plugin | |
11 | */ | |
12 | class PluginAddlinkTest extends \Shaarli\TestCase | |
13 | { | |
14 | /** | |
15 | * Reset plugin path. | |
16 | */ | |
17 | protected function setUp(): void | |
18 | { | |
19 | PluginManager::$PLUGINS_PATH = 'plugins'; | |
20 | } | |
21 | ||
22 | /** | |
23 | * Test render_header hook while logged in. | |
24 | */ | |
25 | public function testAddlinkHeaderLoggedIn() | |
26 | { | |
27 | $str = 'stuff'; | |
28 | $data = array($str => $str); | |
29 | $data['_PAGE_'] = TemplatePage::LINKLIST; | |
30 | $data['_LOGGEDIN_'] = true; | |
31 | $data['_BASE_PATH_'] = '/subfolder'; | |
32 | ||
33 | $data = hook_addlink_toolbar_render_header($data); | |
34 | $this->assertEquals($str, $data[$str]); | |
35 | $this->assertEquals(1, count($data['fields_toolbar'])); | |
36 | ||
37 | $data = array($str => $str); | |
38 | $data['_PAGE_'] = $str; | |
39 | $data['_LOGGEDIN_'] = true; | |
40 | $data['_BASE_PATH_'] = '/subfolder'; | |
41 | ||
42 | $data = hook_addlink_toolbar_render_header($data); | |
43 | $this->assertEquals($str, $data[$str]); | |
44 | $this->assertArrayNotHasKey('fields_toolbar', $data); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Test render_header hook while logged out. | |
49 | */ | |
50 | public function testAddlinkHeaderLoggedOut() | |
51 | { | |
52 | $str = 'stuff'; | |
53 | $data = array($str => $str); | |
54 | $data['_PAGE_'] = TemplatePage::LINKLIST; | |
55 | $data['_LOGGEDIN_'] = false; | |
56 | $data['_BASE_PATH_'] = '/subfolder'; | |
57 | ||
58 | $data = hook_addlink_toolbar_render_header($data); | |
59 | $this->assertEquals($str, $data[$str]); | |
60 | $this->assertArrayNotHasKey('fields_toolbar', $data); | |
61 | } | |
62 | } |