aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php')
-rw-r--r--tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php68
1 files changed, 47 insertions, 21 deletions
diff --git a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
index dabcd60d..f7a68226 100644
--- a/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
+++ b/tests/front/controller/admin/ManageShaareControllerTest/SaveBookmarkTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest; 5namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
6 6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
9use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper; 9use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
@@ -12,6 +11,7 @@ use Shaarli\Front\Controller\Admin\ManageShaareController;
12use Shaarli\Front\Exception\WrongTokenException; 11use Shaarli\Front\Exception\WrongTokenException;
13use Shaarli\Http\HttpAccess; 12use Shaarli\Http\HttpAccess;
14use Shaarli\Security\SessionManager; 13use Shaarli\Security\SessionManager;
14use Shaarli\TestCase;
15use Shaarli\Thumbnailer; 15use Shaarli\Thumbnailer;
16use Slim\Http\Request; 16use Slim\Http\Request;
17use Slim\Http\Response; 17use Slim\Http\Response;
@@ -43,7 +43,7 @@ class SaveBookmarkTest extends TestCase
43 'lf_description' => 'Provided description.', 43 'lf_description' => 'Provided description.',
44 'lf_tags' => 'abc def', 44 'lf_tags' => 'abc def',
45 'lf_private' => '1', 45 'lf_private' => '1',
46 'returnurl' => 'http://shaarli.tld/subfolder/admin/add-shaare' 46 'returnurl' => 'http://shaarli/subfolder/admin/add-shaare'
47 ]; 47 ];
48 48
49 $request = $this->createMock(Request::class); 49 $request = $this->createMock(Request::class);
@@ -88,17 +88,18 @@ class SaveBookmarkTest extends TestCase
88 88
89 // Make sure that PluginManager hook is triggered 89 // Make sure that PluginManager hook is triggered
90 $this->container->pluginManager 90 $this->container->pluginManager
91 ->expects(static::at(0)) 91 ->expects(static::atLeastOnce())
92 ->method('executeHooks') 92 ->method('executeHooks')
93 ->withConsecutive(['save_link'])
93 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { 94 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
94 static::assertSame('save_link', $hook); 95 if ('save_link' === $hook) {
95 96 static::assertSame($id, $data['id']);
96 static::assertSame($id, $data['id']); 97 static::assertSame($parameters['lf_url'], $data['url']);
97 static::assertSame($parameters['lf_url'], $data['url']); 98 static::assertSame($parameters['lf_title'], $data['title']);
98 static::assertSame($parameters['lf_title'], $data['title']); 99 static::assertSame($parameters['lf_description'], $data['description']);
99 static::assertSame($parameters['lf_description'], $data['description']); 100 static::assertSame($parameters['lf_tags'], $data['tags']);
100 static::assertSame($parameters['lf_tags'], $data['tags']); 101 static::assertTrue($data['private']);
101 static::assertTrue($data['private']); 102 }
102 103
103 return $data; 104 return $data;
104 }) 105 })
@@ -124,7 +125,7 @@ class SaveBookmarkTest extends TestCase
124 'lf_description' => 'Provided description.', 125 'lf_description' => 'Provided description.',
125 'lf_tags' => 'abc def', 126 'lf_tags' => 'abc def',
126 'lf_private' => '1', 127 'lf_private' => '1',
127 'returnurl' => 'http://shaarli.tld/subfolder/?page=2' 128 'returnurl' => 'http://shaarli/subfolder/?page=2'
128 ]; 129 ];
129 130
130 $request = $this->createMock(Request::class); 131 $request = $this->createMock(Request::class);
@@ -174,17 +175,18 @@ class SaveBookmarkTest extends TestCase
174 175
175 // Make sure that PluginManager hook is triggered 176 // Make sure that PluginManager hook is triggered
176 $this->container->pluginManager 177 $this->container->pluginManager
177 ->expects(static::at(0)) 178 ->expects(static::atLeastOnce())
178 ->method('executeHooks') 179 ->method('executeHooks')
180 ->withConsecutive(['save_link'])
179 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array { 181 ->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
180 static::assertSame('save_link', $hook); 182 if ('save_link' === $hook) {
181 183 static::assertSame($id, $data['id']);
182 static::assertSame($id, $data['id']); 184 static::assertSame($parameters['lf_url'], $data['url']);
183 static::assertSame($parameters['lf_url'], $data['url']); 185 static::assertSame($parameters['lf_title'], $data['title']);
184 static::assertSame($parameters['lf_title'], $data['title']); 186 static::assertSame($parameters['lf_description'], $data['description']);
185 static::assertSame($parameters['lf_description'], $data['description']); 187 static::assertSame($parameters['lf_tags'], $data['tags']);
186 static::assertSame($parameters['lf_tags'], $data['tags']); 188 static::assertTrue($data['private']);
187 static::assertTrue($data['private']); 189 }
188 190
189 return $data; 191 return $data;
190 }) 192 })
@@ -239,6 +241,30 @@ class SaveBookmarkTest extends TestCase
239 } 241 }
240 242
241 /** 243 /**
244 * Test save a bookmark - with ID #0
245 */
246 public function testSaveBookmarkWithIdZero(): void
247 {
248 $parameters = ['lf_id' => '0'];
249
250 $request = $this->createMock(Request::class);
251 $request
252 ->method('getParam')
253 ->willReturnCallback(function (string $key) use ($parameters): ?string {
254 return $parameters[$key] ?? null;
255 })
256 ;
257 $response = new Response();
258
259 $this->container->bookmarkService->expects(static::once())->method('exists')->with(0)->willReturn(true);
260 $this->container->bookmarkService->expects(static::once())->method('get')->with(0)->willReturn(new Bookmark());
261
262 $result = $this->controller->save($request, $response);
263
264 static::assertSame(302, $result->getStatusCode());
265 }
266
267 /**
242 * Change the password with a wrong existing password 268 * Change the password with a wrong existing password
243 */ 269 */
244 public function testSaveBookmarkFromBookmarklet(): void 270 public function testSaveBookmarkFromBookmarklet(): void