diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PluginManagerTest.php | 44 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFileServiceTest.php | 18 | ||||
-rw-r--r-- | tests/bookmark/BookmarkInitializerTest.php | 70 | ||||
-rw-r--r-- | tests/front/controller/admin/PluginsControllerTest.php | 5 | ||||
-rw-r--r-- | tests/plugins/test/test.php | 3 |
5 files changed, 94 insertions, 46 deletions
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index a5d5dbe9..3018999c 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php | |||
@@ -41,17 +41,31 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase | |||
41 | 41 | ||
42 | $this->assertTrue(function_exists('hook_test_random')); | 42 | $this->assertTrue(function_exists('hook_test_random')); |
43 | 43 | ||
44 | $data = array(0 => 'woot'); | 44 | $data = [0 => 'woot']; |
45 | $this->pluginManager->executeHooks('random', $data); | 45 | $this->pluginManager->executeHooks('random', $data); |
46 | $this->assertEquals('woot', $data[1]); | ||
47 | 46 | ||
48 | $data = array(0 => 'woot'); | 47 | static::assertCount(2, $data); |
48 | static::assertSame('woot', $data[1]); | ||
49 | |||
50 | $data = [0 => 'woot']; | ||
49 | $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); | 51 | $this->pluginManager->executeHooks('random', $data, array('target' => 'test')); |
50 | $this->assertEquals('page test', $data[1]); | ||
51 | 52 | ||
52 | $data = array(0 => 'woot'); | 53 | static::assertCount(2, $data); |
54 | static::assertSame('page test', $data[1]); | ||
55 | |||
56 | $data = [0 => 'woot']; | ||
53 | $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); | 57 | $this->pluginManager->executeHooks('random', $data, array('loggedin' => true)); |
54 | $this->assertEquals('loggedin', $data[1]); | 58 | |
59 | static::assertCount(2, $data); | ||
60 | static::assertEquals('loggedin', $data[1]); | ||
61 | |||
62 | $data = [0 => 'woot']; | ||
63 | $this->pluginManager->executeHooks('random', $data, array('loggedin' => null)); | ||
64 | |||
65 | static::assertCount(3, $data); | ||
66 | static::assertEquals('loggedin', $data[1]); | ||
67 | static::assertArrayHasKey(2, $data); | ||
68 | static::assertNull($data[2]); | ||
55 | } | 69 | } |
56 | 70 | ||
57 | /** | 71 | /** |
@@ -78,8 +92,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase | |||
78 | */ | 92 | */ |
79 | public function testPluginNotFound(): void | 93 | public function testPluginNotFound(): void |
80 | { | 94 | { |
81 | $this->pluginManager->load(array()); | 95 | $this->pluginManager->load([]); |
82 | $this->pluginManager->load(array('nope', 'renope')); | 96 | $this->pluginManager->load(['nope', 'renope']); |
83 | $this->addToAssertionCount(1); | 97 | $this->addToAssertionCount(1); |
84 | } | 98 | } |
85 | 99 | ||
@@ -89,18 +103,18 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase | |||
89 | public function testGetPluginsMeta(): void | 103 | public function testGetPluginsMeta(): void |
90 | { | 104 | { |
91 | PluginManager::$PLUGINS_PATH = self::$pluginPath; | 105 | PluginManager::$PLUGINS_PATH = self::$pluginPath; |
92 | $this->pluginManager->load(array(self::$pluginName)); | 106 | $this->pluginManager->load([self::$pluginName]); |
93 | 107 | ||
94 | $expectedParameters = array( | 108 | $expectedParameters = [ |
95 | 'pop' => array( | 109 | 'pop' => [ |
96 | 'value' => '', | 110 | 'value' => '', |
97 | 'desc' => 'pop description', | 111 | 'desc' => 'pop description', |
98 | ), | 112 | ], |
99 | 'hip' => array( | 113 | 'hip' => [ |
100 | 'value' => '', | 114 | 'value' => '', |
101 | 'desc' => '', | 115 | 'desc' => '', |
102 | ), | 116 | ], |
103 | ); | 117 | ]; |
104 | $meta = $this->pluginManager->getPluginsMeta(); | 118 | $meta = $this->pluginManager->getPluginsMeta(); |
105 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); | 119 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); |
106 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); | 120 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); |
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index c59fd443..a4ec1013 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -615,14 +615,18 @@ class BookmarkFileServiceTest extends TestCase | |||
615 | { | 615 | { |
616 | $dbSize = $this->privateLinkDB->count(); | 616 | $dbSize = $this->privateLinkDB->count(); |
617 | $this->privateLinkDB->initialize(); | 617 | $this->privateLinkDB->initialize(); |
618 | $this->assertEquals($dbSize + 2, $this->privateLinkDB->count()); | 618 | $this->assertEquals($dbSize + 3, $this->privateLinkDB->count()); |
619 | $this->assertEquals( | 619 | $this->assertStringStartsWith( |
620 | 'My secret stuff... - Pastebin.com', | 620 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
621 | $this->privateLinkDB->get(43)->getTitle() | 621 | $this->privateLinkDB->get(43)->getDescription() |
622 | ); | 622 | ); |
623 | $this->assertEquals( | 623 | $this->assertStringStartsWith( |
624 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 624 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
625 | $this->privateLinkDB->get(44)->getTitle() | 625 | $this->privateLinkDB->get(44)->getDescription() |
626 | ); | ||
627 | $this->assertStringStartsWith( | ||
628 | 'Welcome to Shaarli!', | ||
629 | $this->privateLinkDB->get(45)->getDescription() | ||
626 | ); | 630 | ); |
627 | } | 631 | } |
628 | 632 | ||
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 3906cc7f..454269bb 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php | |||
@@ -37,7 +37,7 @@ class BookmarkInitializerTest extends TestCase | |||
37 | /** | 37 | /** |
38 | * Initialize an empty BookmarkFileService | 38 | * Initialize an empty BookmarkFileService |
39 | */ | 39 | */ |
40 | public function setUp() | 40 | public function setUp(): void |
41 | { | 41 | { |
42 | if (file_exists(self::$testDatastore)) { | 42 | if (file_exists(self::$testDatastore)) { |
43 | unlink(self::$testDatastore); | 43 | unlink(self::$testDatastore); |
@@ -64,17 +64,26 @@ class BookmarkInitializerTest extends TestCase | |||
64 | 64 | ||
65 | $this->initializer->initialize(); | 65 | $this->initializer->initialize(); |
66 | 66 | ||
67 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); | 67 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); |
68 | |||
68 | $bookmark = $this->bookmarkService->get(43); | 69 | $bookmark = $this->bookmarkService->get(43); |
69 | $this->assertEquals(43, $bookmark->getId()); | 70 | $this->assertStringStartsWith( |
70 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 71 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
72 | $bookmark->getDescription() | ||
73 | ); | ||
71 | $this->assertTrue($bookmark->isPrivate()); | 74 | $this->assertTrue($bookmark->isPrivate()); |
72 | 75 | ||
73 | $bookmark = $this->bookmarkService->get(44); | 76 | $bookmark = $this->bookmarkService->get(44); |
74 | $this->assertEquals(44, $bookmark->getId()); | 77 | $this->assertStringStartsWith( |
75 | $this->assertEquals( | 78 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
76 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 79 | $bookmark->getDescription() |
77 | $bookmark->getTitle() | 80 | ); |
81 | $this->assertTrue($bookmark->isPrivate()); | ||
82 | |||
83 | $bookmark = $this->bookmarkService->get(45); | ||
84 | $this->assertStringStartsWith( | ||
85 | 'Welcome to Shaarli!', | ||
86 | $bookmark->getDescription() | ||
78 | ); | 87 | ); |
79 | $this->assertFalse($bookmark->isPrivate()); | 88 | $this->assertFalse($bookmark->isPrivate()); |
80 | 89 | ||
@@ -82,17 +91,26 @@ class BookmarkInitializerTest extends TestCase | |||
82 | 91 | ||
83 | // Reload from file | 92 | // Reload from file |
84 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 93 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
85 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); | 94 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); |
95 | |||
86 | $bookmark = $this->bookmarkService->get(43); | 96 | $bookmark = $this->bookmarkService->get(43); |
87 | $this->assertEquals(43, $bookmark->getId()); | 97 | $this->assertStringStartsWith( |
88 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 98 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
99 | $bookmark->getDescription() | ||
100 | ); | ||
89 | $this->assertTrue($bookmark->isPrivate()); | 101 | $this->assertTrue($bookmark->isPrivate()); |
90 | 102 | ||
91 | $bookmark = $this->bookmarkService->get(44); | 103 | $bookmark = $this->bookmarkService->get(44); |
92 | $this->assertEquals(44, $bookmark->getId()); | 104 | $this->assertStringStartsWith( |
93 | $this->assertEquals( | 105 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
94 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 106 | $bookmark->getDescription() |
95 | $bookmark->getTitle() | 107 | ); |
108 | $this->assertTrue($bookmark->isPrivate()); | ||
109 | |||
110 | $bookmark = $this->bookmarkService->get(45); | ||
111 | $this->assertStringStartsWith( | ||
112 | 'Welcome to Shaarli!', | ||
113 | $bookmark->getDescription() | ||
96 | ); | 114 | ); |
97 | $this->assertFalse($bookmark->isPrivate()); | 115 | $this->assertFalse($bookmark->isPrivate()); |
98 | } | 116 | } |
@@ -107,17 +125,25 @@ class BookmarkInitializerTest extends TestCase | |||
107 | 125 | ||
108 | $this->initializer->initialize(); | 126 | $this->initializer->initialize(); |
109 | 127 | ||
110 | $this->assertEquals(2, $this->bookmarkService->count()); | 128 | $this->assertEquals(3, $this->bookmarkService->count()); |
111 | $bookmark = $this->bookmarkService->get(0); | 129 | $bookmark = $this->bookmarkService->get(0); |
112 | $this->assertEquals(0, $bookmark->getId()); | 130 | $this->assertStringStartsWith( |
113 | $this->assertEquals('My secret stuff... - Pastebin.com', $bookmark->getTitle()); | 131 | 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', |
132 | $bookmark->getDescription() | ||
133 | ); | ||
114 | $this->assertTrue($bookmark->isPrivate()); | 134 | $this->assertTrue($bookmark->isPrivate()); |
115 | 135 | ||
116 | $bookmark = $this->bookmarkService->get(1); | 136 | $bookmark = $this->bookmarkService->get(1); |
117 | $this->assertEquals(1, $bookmark->getId()); | 137 | $this->assertStringStartsWith( |
118 | $this->assertEquals( | 138 | 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', |
119 | 'The personal, minimalist, super-fast, database free, bookmarking service', | 139 | $bookmark->getDescription() |
120 | $bookmark->getTitle() | 140 | ); |
141 | $this->assertTrue($bookmark->isPrivate()); | ||
142 | |||
143 | $bookmark = $this->bookmarkService->get(2); | ||
144 | $this->assertStringStartsWith( | ||
145 | 'Welcome to Shaarli!', | ||
146 | $bookmark->getDescription() | ||
121 | ); | 147 | ); |
122 | $this->assertFalse($bookmark->isPrivate()); | 148 | $this->assertFalse($bookmark->isPrivate()); |
123 | } | 149 | } |
diff --git a/tests/front/controller/admin/PluginsControllerTest.php b/tests/front/controller/admin/PluginsControllerTest.php index 5b59285c..9526474c 100644 --- a/tests/front/controller/admin/PluginsControllerTest.php +++ b/tests/front/controller/admin/PluginsControllerTest.php | |||
@@ -32,7 +32,7 @@ class PluginsControllerTest extends TestCase | |||
32 | array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES); | 32 | array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES); |
33 | } | 33 | } |
34 | 34 | ||
35 | public function tearDown() | 35 | public function tearDown(): void |
36 | { | 36 | { |
37 | $path = __DIR__ . '/folder'; | 37 | $path = __DIR__ . '/folder'; |
38 | array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES); | 38 | array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES); |
@@ -125,6 +125,7 @@ class PluginsControllerTest extends TestCase | |||
125 | 'parameters_form' => true, | 125 | 'parameters_form' => true, |
126 | 'parameter1' => 'blip', | 126 | 'parameter1' => 'blip', |
127 | 'parameter2' => 'blop', | 127 | 'parameter2' => 'blop', |
128 | 'token' => 'this parameter should not be saved' | ||
128 | ]; | 129 | ]; |
129 | 130 | ||
130 | $request = $this->createMock(Request::class); | 131 | $request = $this->createMock(Request::class); |
@@ -143,7 +144,7 @@ class PluginsControllerTest extends TestCase | |||
143 | ->with('save_plugin_parameters', $parameters) | 144 | ->with('save_plugin_parameters', $parameters) |
144 | ; | 145 | ; |
145 | $this->container->conf | 146 | $this->container->conf |
146 | ->expects(static::atLeastOnce()) | 147 | ->expects(static::exactly(2)) |
147 | ->method('set') | 148 | ->method('set') |
148 | ->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop']) | 149 | ->withConsecutive(['plugins.parameter1', 'blip'], ['plugins.parameter2', 'blop']) |
149 | ; | 150 | ; |
diff --git a/tests/plugins/test/test.php b/tests/plugins/test/test.php index ae5032dd..03be4f4e 100644 --- a/tests/plugins/test/test.php +++ b/tests/plugins/test/test.php | |||
@@ -13,6 +13,9 @@ function hook_test_random($data) | |||
13 | $data[1] = 'page test'; | 13 | $data[1] = 'page test'; |
14 | } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) { | 14 | } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) { |
15 | $data[1] = 'loggedin'; | 15 | $data[1] = 'loggedin'; |
16 | } elseif (array_key_exists('_LOGGEDIN_', $data)) { | ||
17 | $data[1] = 'loggedin'; | ||
18 | $data[2] = $data['_LOGGEDIN_']; | ||
16 | } else { | 19 | } else { |
17 | $data[1] = $data[0]; | 20 | $data[1] = $data[0]; |
18 | } | 21 | } |