aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-02-04 10:57:44 +0100
committerGitHub <noreply@github.com>2021-02-04 10:57:44 +0100
commit8997ae6c8e24286f7d47981eaf905e80d2481c10 (patch)
tree9906b122998ca4420af68b1bb110033b99f7d8bf /tests/front/controller
parent11edc143b42a7be09c0c9dc02730c83e8cbb73c2 (diff)
parent9b8c0a4560fa1d87cab1529099b1b4677e92e265 (diff)
downloadShaarli-8997ae6c8e24286f7d47981eaf905e80d2481c10.tar.gz
Shaarli-8997ae6c8e24286f7d47981eaf905e80d2481c10.tar.zst
Shaarli-8997ae6c8e24286f7d47981eaf905e80d2481c10.zip
Merge pull request #1697 from ArthurHoaro/feature/pagination
Handle pagination through BookmarkService
Diffstat (limited to 'tests/front/controller')
-rw-r--r--tests/front/controller/admin/ManageTagControllerTest.php9
-rw-r--r--tests/front/controller/admin/ThumbnailsControllerTest.php5
-rw-r--r--tests/front/controller/visitor/BookmarkListControllerTest.php29
-rw-r--r--tests/front/controller/visitor/DailyControllerTest.php45
-rw-r--r--tests/front/controller/visitor/PictureWallControllerTest.php7
5 files changed, 57 insertions, 38 deletions
diff --git a/tests/front/controller/admin/ManageTagControllerTest.php b/tests/front/controller/admin/ManageTagControllerTest.php
index af6f273f..56a64cbb 100644
--- a/tests/front/controller/admin/ManageTagControllerTest.php
+++ b/tests/front/controller/admin/ManageTagControllerTest.php
@@ -6,6 +6,7 @@ namespace Shaarli\Front\Controller\Admin;
6 6
7use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\BookmarkFilter; 8use Shaarli\Bookmark\BookmarkFilter;
9use Shaarli\Bookmark\SearchResult;
9use Shaarli\Config\ConfigManager; 10use Shaarli\Config\ConfigManager;
10use Shaarli\Front\Exception\WrongTokenException; 11use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
@@ -100,11 +101,11 @@ class ManageTagControllerTest extends TestCase
100 ->expects(static::once()) 101 ->expects(static::once())
101 ->method('search') 102 ->method('search')
102 ->with(['searchtags' => 'old-tag'], BookmarkFilter::$ALL, true) 103 ->with(['searchtags' => 'old-tag'], BookmarkFilter::$ALL, true)
103 ->willReturnCallback(function () use ($bookmark1, $bookmark2): array { 104 ->willReturnCallback(function () use ($bookmark1, $bookmark2): SearchResult {
104 $bookmark1->expects(static::once())->method('renameTag')->with('old-tag', 'new-tag'); 105 $bookmark1->expects(static::once())->method('renameTag')->with('old-tag', 'new-tag');
105 $bookmark2->expects(static::once())->method('renameTag')->with('old-tag', 'new-tag'); 106 $bookmark2->expects(static::once())->method('renameTag')->with('old-tag', 'new-tag');
106 107
107 return [$bookmark1, $bookmark2]; 108 return SearchResult::getSearchResult([$bookmark1, $bookmark2]);
108 }) 109 })
109 ; 110 ;
110 $this->container->bookmarkService 111 $this->container->bookmarkService
@@ -153,11 +154,11 @@ class ManageTagControllerTest extends TestCase
153 ->expects(static::once()) 154 ->expects(static::once())
154 ->method('search') 155 ->method('search')
155 ->with(['searchtags' => 'old-tag'], BookmarkFilter::$ALL, true) 156 ->with(['searchtags' => 'old-tag'], BookmarkFilter::$ALL, true)
156 ->willReturnCallback(function () use ($bookmark1, $bookmark2): array { 157 ->willReturnCallback(function () use ($bookmark1, $bookmark2): SearchResult {
157 $bookmark1->expects(static::once())->method('deleteTag')->with('old-tag'); 158 $bookmark1->expects(static::once())->method('deleteTag')->with('old-tag');
158 $bookmark2->expects(static::once())->method('deleteTag')->with('old-tag'); 159 $bookmark2->expects(static::once())->method('deleteTag')->with('old-tag');
159 160
160 return [$bookmark1, $bookmark2]; 161 return SearchResult::getSearchResult([$bookmark1, $bookmark2]);
161 }) 162 })
162 ; 163 ;
163 $this->container->bookmarkService 164 $this->container->bookmarkService
diff --git a/tests/front/controller/admin/ThumbnailsControllerTest.php b/tests/front/controller/admin/ThumbnailsControllerTest.php
index e5749654..0c9b63c3 100644
--- a/tests/front/controller/admin/ThumbnailsControllerTest.php
+++ b/tests/front/controller/admin/ThumbnailsControllerTest.php
@@ -6,6 +6,7 @@ namespace Shaarli\Front\Controller\Admin;
6 6
7use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
9use Shaarli\Bookmark\SearchResult;
9use Shaarli\TestCase; 10use Shaarli\TestCase;
10use Shaarli\Thumbnailer; 11use Shaarli\Thumbnailer;
11use Slim\Http\Request; 12use Slim\Http\Request;
@@ -40,12 +41,12 @@ class ThumbnailsControllerTest extends TestCase
40 $this->container->bookmarkService 41 $this->container->bookmarkService
41 ->expects(static::once()) 42 ->expects(static::once())
42 ->method('search') 43 ->method('search')
43 ->willReturn([ 44 ->willReturn(SearchResult::getSearchResult([
44 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), 45 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
45 (new Bookmark())->setId(2)->setUrl('?abcdef')->setTitle('Note 1'), 46 (new Bookmark())->setId(2)->setUrl('?abcdef')->setTitle('Note 1'),
46 (new Bookmark())->setId(3)->setUrl('http://url2.tld')->setTitle('Title 2'), 47 (new Bookmark())->setId(3)->setUrl('http://url2.tld')->setTitle('Title 2'),
47 (new Bookmark())->setId(4)->setUrl('ftp://domain.tld', ['ftp'])->setTitle('FTP'), 48 (new Bookmark())->setId(4)->setUrl('ftp://domain.tld', ['ftp'])->setTitle('FTP'),
48 ]) 49 ]))
49 ; 50 ;
50 51
51 $result = $this->controller->index($request, $response); 52 $result = $this->controller->index($request, $response);
diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php
index dec938f2..0fbab9d4 100644
--- a/tests/front/controller/visitor/BookmarkListControllerTest.php
+++ b/tests/front/controller/visitor/BookmarkListControllerTest.php
@@ -6,6 +6,7 @@ namespace Shaarli\Front\Controller\Visitor;
6 6
7use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 8use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
9use Shaarli\Bookmark\SearchResult;
9use Shaarli\Config\ConfigManager; 10use Shaarli\Config\ConfigManager;
10use Shaarli\Security\LoginManager; 11use Shaarli\Security\LoginManager;
11use Shaarli\TestCase; 12use Shaarli\TestCase;
@@ -45,13 +46,15 @@ class BookmarkListControllerTest extends TestCase
45 ['searchtags' => '', 'searchterm' => ''], 46 ['searchtags' => '', 'searchterm' => ''],
46 null, 47 null,
47 false, 48 false,
48 false 49 false,
50 false,
51 ['offset' => 0, 'limit' => 2]
49 ) 52 )
50 ->willReturn([ 53 ->willReturn(SearchResult::getSearchResult([
51 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), 54 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
52 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), 55 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'),
53 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), 56 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'),
54 ] 57 ], 0, 2)
55 ); 58 );
56 59
57 $this->container->sessionManager 60 $this->container->sessionManager
@@ -119,13 +122,15 @@ class BookmarkListControllerTest extends TestCase
119 ['searchtags' => '', 'searchterm' => ''], 122 ['searchtags' => '', 'searchterm' => ''],
120 null, 123 null,
121 false, 124 false,
122 false 125 false,
126 false,
127 ['offset' => 2, 'limit' => 2]
123 ) 128 )
124 ->willReturn([ 129 ->willReturn(SearchResult::getSearchResult([
125 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), 130 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
126 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), 131 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'),
127 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), 132 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'),
128 ]) 133 ], 2, 2))
129 ; 134 ;
130 135
131 $this->container->sessionManager 136 $this->container->sessionManager
@@ -207,13 +212,15 @@ class BookmarkListControllerTest extends TestCase
207 ['searchtags' => 'abc@def', 'searchterm' => 'ghi jkl'], 212 ['searchtags' => 'abc@def', 'searchterm' => 'ghi jkl'],
208 'private', 213 'private',
209 false, 214 false,
210 true 215 true,
216 false,
217 ['offset' => 0, 'limit' => 2]
211 ) 218 )
212 ->willReturn([ 219 ->willReturn(SearchResult::getSearchResult([
213 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), 220 (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
214 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), 221 (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'),
215 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), 222 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'),
216 ]) 223 ], 0, 2))
217 ; 224 ;
218 225
219 $result = $this->controller->index($request, $response); 226 $result = $this->controller->index($request, $response);
@@ -358,13 +365,13 @@ class BookmarkListControllerTest extends TestCase
358 $this->container->bookmarkService 365 $this->container->bookmarkService
359 ->expects(static::once()) 366 ->expects(static::once())
360 ->method('search') 367 ->method('search')
361 ->willReturn([ 368 ->willReturn(SearchResult::getSearchResult([
362 (new Bookmark())->setId(1)->setUrl('https://url1.tld')->setTitle('Title 1')->setThumbnail(false), 369 (new Bookmark())->setId(1)->setUrl('https://url1.tld')->setTitle('Title 1')->setThumbnail(false),
363 $b1 = (new Bookmark())->setId(2)->setUrl('https://url2.tld')->setTitle('Title 2'), 370 $b1 = (new Bookmark())->setId(2)->setUrl('https://url2.tld')->setTitle('Title 2'),
364 (new Bookmark())->setId(3)->setUrl('https://url3.tld')->setTitle('Title 3')->setThumbnail(false), 371 (new Bookmark())->setId(3)->setUrl('https://url3.tld')->setTitle('Title 3')->setThumbnail(false),
365 $b2 = (new Bookmark())->setId(2)->setUrl('https://url4.tld')->setTitle('Title 4'), 372 $b2 = (new Bookmark())->setId(2)->setUrl('https://url4.tld')->setTitle('Title 4'),
366 (new Bookmark())->setId(2)->setUrl('ftp://url5.tld', ['ftp'])->setTitle('Title 5'), 373 (new Bookmark())->setId(2)->setUrl('ftp://url5.tld', ['ftp'])->setTitle('Title 5'),
367 ]) 374 ]))
368 ; 375 ;
369 $this->container->bookmarkService 376 $this->container->bookmarkService
370 ->expects(static::exactly(2)) 377 ->expects(static::exactly(2))
diff --git a/tests/front/controller/visitor/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php
index 70fbce54..821ba321 100644
--- a/tests/front/controller/visitor/DailyControllerTest.php
+++ b/tests/front/controller/visitor/DailyControllerTest.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\SearchResult;
8use Shaarli\Feed\CachedPage; 9use Shaarli\Feed\CachedPage;
9use Shaarli\TestCase; 10use Shaarli\TestCase;
10use Slim\Http\Request; 11use Slim\Http\Request;
@@ -347,13 +348,15 @@ class DailyControllerTest extends TestCase
347 $request = $this->createMock(Request::class); 348 $request = $this->createMock(Request::class);
348 $response = new Response(); 349 $response = new Response();
349 350
350 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn([ 351 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn(
351 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'), 352 SearchResult::getSearchResult([
352 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'), 353 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'),
353 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'), 354 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'),
354 (new Bookmark())->setId(4)->setCreated($dates[2])->setUrl('http://domain.tld/4'), 355 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'),
355 (new Bookmark())->setId(5)->setCreated($dates[3])->setUrl('http://domain.tld/5'), 356 (new Bookmark())->setId(4)->setCreated($dates[2])->setUrl('http://domain.tld/4'),
356 ]); 357 (new Bookmark())->setId(5)->setCreated($dates[3])->setUrl('http://domain.tld/5'),
358 ])
359 );
357 360
358 $this->container->pageCacheManager 361 $this->container->pageCacheManager
359 ->expects(static::once()) 362 ->expects(static::once())
@@ -454,7 +457,9 @@ class DailyControllerTest extends TestCase
454 $request = $this->createMock(Request::class); 457 $request = $this->createMock(Request::class);
455 $response = new Response(); 458 $response = new Response();
456 459
457 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn([]); 460 $this->container->bookmarkService
461 ->expects(static::once())->method('search')
462 ->willReturn(SearchResult::getSearchResult([]));
458 463
459 // Save RainTPL assigned variables 464 // Save RainTPL assigned variables
460 $assignedVariables = []; 465 $assignedVariables = [];
@@ -613,11 +618,13 @@ class DailyControllerTest extends TestCase
613 }); 618 });
614 $response = new Response(); 619 $response = new Response();
615 620
616 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn([ 621 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn(
617 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'), 622 SearchResult::getSearchResult([
618 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'), 623 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'),
619 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'), 624 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'),
620 ]); 625 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'),
626 ])
627 );
621 628
622 // Save RainTPL assigned variables 629 // Save RainTPL assigned variables
623 $assignedVariables = []; 630 $assignedVariables = [];
@@ -674,11 +681,13 @@ class DailyControllerTest extends TestCase
674 }); 681 });
675 $response = new Response(); 682 $response = new Response();
676 683
677 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn([ 684 $this->container->bookmarkService->expects(static::once())->method('search')->willReturn(
678 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'), 685 SearchResult::getSearchResult([
679 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'), 686 (new Bookmark())->setId(1)->setCreated($dates[0])->setUrl('http://domain.tld/1'),
680 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'), 687 (new Bookmark())->setId(2)->setCreated($dates[1])->setUrl('http://domain.tld/2'),
681 ]); 688 (new Bookmark())->setId(3)->setCreated($dates[1])->setUrl('http://domain.tld/3'),
689 ])
690 );
682 691
683 // Save RainTPL assigned variables 692 // Save RainTPL assigned variables
684 $assignedVariables = []; 693 $assignedVariables = [];
diff --git a/tests/front/controller/visitor/PictureWallControllerTest.php b/tests/front/controller/visitor/PictureWallControllerTest.php
index b868231d..429e99a2 100644
--- a/tests/front/controller/visitor/PictureWallControllerTest.php
+++ b/tests/front/controller/visitor/PictureWallControllerTest.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use Shaarli\Bookmark\Bookmark; 7use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\SearchResult;
8use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
9use Shaarli\Front\Exception\ThumbnailsDisabledException; 10use Shaarli\Front\Exception\ThumbnailsDisabledException;
10use Shaarli\TestCase; 11use Shaarli\TestCase;
@@ -50,17 +51,17 @@ class PictureWallControllerTest extends TestCase
50 $this->container->bookmarkService 51 $this->container->bookmarkService
51 ->expects(static::once()) 52 ->expects(static::once())
52 ->method('search') 53 ->method('search')
53 ->willReturnCallback(function (array $parameters, ?string $visibility): array { 54 ->willReturnCallback(function (array $parameters, ?string $visibility): SearchResult {
54 // Visibility is set through the container, not the call 55 // Visibility is set through the container, not the call
55 static::assertNull($visibility); 56 static::assertNull($visibility);
56 57
57 // No query parameters 58 // No query parameters
58 if (count($parameters) === 0) { 59 if (count($parameters) === 0) {
59 return [ 60 return SearchResult::getSearchResult([
60 (new Bookmark())->setId(1)->setUrl('http://url.tld')->setThumbnail('thumb1'), 61 (new Bookmark())->setId(1)->setUrl('http://url.tld')->setThumbnail('thumb1'),
61 (new Bookmark())->setId(2)->setUrl('http://url2.tld'), 62 (new Bookmark())->setId(2)->setUrl('http://url2.tld'),
62 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setThumbnail('thumb2'), 63 (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setThumbnail('thumb2'),
63 ]; 64 ]);
64 } 65 }
65 }) 66 })
66 ; 67 ;