diff options
author | ArthurHoaro <arthur@hoa.ro> | 2021-01-20 14:45:59 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2021-01-20 15:01:29 +0100 |
commit | 9b8c0a4560fa1d87cab1529099b1b4677e92e265 (patch) | |
tree | 330a9b1a42ff7b7f24a76612b57fae63417ef483 /tests | |
parent | 055d97f9a9e67d8ee8ae81bbf59a4b846a145d9f (diff) | |
download | Shaarli-9b8c0a4560fa1d87cab1529099b1b4677e92e265.tar.gz Shaarli-9b8c0a4560fa1d87cab1529099b1b4677e92e265.tar.zst Shaarli-9b8c0a4560fa1d87cab1529099b1b4677e92e265.zip |
Handle pagination through BookmarkService
Handle all search results through SearchResult object.
This is a required step toward implementing a BookmarkService based on SQL database.
Related to #953
Diffstat (limited to 'tests')
7 files changed, 186 insertions, 42 deletions
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index f619aff3..d1af3fb0 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -807,7 +807,7 @@ class BookmarkFileServiceTest extends TestCase | |||
807 | $request = ['searchtags' => $tags]; | 807 | $request = ['searchtags' => $tags]; |
808 | $this->assertEquals( | 808 | $this->assertEquals( |
809 | 2, | 809 | 2, |
810 | count($this->privateLinkDB->search($request, null, true)) | 810 | count($this->privateLinkDB->search($request, null, true)->getBookmarks()) |
811 | ); | 811 | ); |
812 | } | 812 | } |
813 | 813 | ||
@@ -820,7 +820,7 @@ class BookmarkFileServiceTest extends TestCase | |||
820 | $request = ['searchtags' => $tags]; | 820 | $request = ['searchtags' => $tags]; |
821 | $this->assertEquals( | 821 | $this->assertEquals( |
822 | 2, | 822 | 2, |
823 | count($this->privateLinkDB->search($request, null, true)) | 823 | count($this->privateLinkDB->search($request, null, true)->getBookmarks()) |
824 | ); | 824 | ); |
825 | } | 825 | } |
826 | 826 | ||
@@ -834,12 +834,12 @@ class BookmarkFileServiceTest extends TestCase | |||
834 | $request = ['searchtags' => $tags]; | 834 | $request = ['searchtags' => $tags]; |
835 | $this->assertEquals( | 835 | $this->assertEquals( |
836 | 1, | 836 | 1, |
837 | count($this->privateLinkDB->search($request, 'all', true)) | 837 | count($this->privateLinkDB->search($request, 'all', true)->getBookmarks()) |
838 | ); | 838 | ); |
839 | 839 | ||
840 | $this->assertEquals( | 840 | $this->assertEquals( |
841 | 0, | 841 | 0, |
842 | count($this->publicLinkDB->search($request, 'public', true)) | 842 | count($this->publicLinkDB->search($request, 'public', true)->getBookmarks()) |
843 | ); | 843 | ); |
844 | } | 844 | } |
845 | 845 | ||
diff --git a/tests/bookmark/SearchResultTest.php b/tests/bookmark/SearchResultTest.php new file mode 100644 index 00000000..12854c1f --- /dev/null +++ b/tests/bookmark/SearchResultTest.php | |||
@@ -0,0 +1,125 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Bookmark; | ||
6 | |||
7 | use Shaarli\TestCase; | ||
8 | |||
9 | /** | ||
10 | * Test SearchResult class. | ||
11 | */ | ||
12 | class SearchResultTest extends TestCase | ||
13 | { | ||
14 | /** Create a SearchResult without any pagination parameter. */ | ||
15 | public function testResultNoParameters(): void | ||
16 | { | ||
17 | $searchResult = SearchResult::getSearchResult($data = ['a', 'b', 'c', 'd', 'e', 'f']); | ||
18 | |||
19 | static::assertSame($data, $searchResult->getBookmarks()); | ||
20 | static::assertSame(6, $searchResult->getResultCount()); | ||
21 | static::assertSame(6, $searchResult->getTotalCount()); | ||
22 | static::assertSame(null, $searchResult->getLimit()); | ||
23 | static::assertSame(0, $searchResult->getOffset()); | ||
24 | static::assertSame(1, $searchResult->getPage()); | ||
25 | static::assertSame(1, $searchResult->getLastPage()); | ||
26 | static::assertTrue($searchResult->isFirstPage()); | ||
27 | static::assertTrue($searchResult->isLastPage()); | ||
28 | } | ||
29 | |||
30 | /** Create a SearchResult with only an offset parameter */ | ||
31 | public function testResultWithOffset(): void | ||
32 | { | ||
33 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 2); | ||
34 | |||
35 | static::assertSame([2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f'], $searchResult->getBookmarks()); | ||
36 | static::assertSame(4, $searchResult->getResultCount()); | ||
37 | static::assertSame(6, $searchResult->getTotalCount()); | ||
38 | static::assertSame(null, $searchResult->getLimit()); | ||
39 | static::assertSame(2, $searchResult->getOffset()); | ||
40 | static::assertSame(2, $searchResult->getPage()); | ||
41 | static::assertSame(2, $searchResult->getLastPage()); | ||
42 | static::assertFalse($searchResult->isFirstPage()); | ||
43 | static::assertTrue($searchResult->isLastPage()); | ||
44 | } | ||
45 | |||
46 | /** Create a SearchResult with only a limit parameter */ | ||
47 | public function testResultWithLimit(): void | ||
48 | { | ||
49 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 0, 2); | ||
50 | |||
51 | static::assertSame([0 => 'a', 1 => 'b'], $searchResult->getBookmarks()); | ||
52 | static::assertSame(2, $searchResult->getResultCount()); | ||
53 | static::assertSame(6, $searchResult->getTotalCount()); | ||
54 | static::assertSame(2, $searchResult->getLimit()); | ||
55 | static::assertSame(0, $searchResult->getOffset()); | ||
56 | static::assertSame(1, $searchResult->getPage()); | ||
57 | static::assertSame(3, $searchResult->getLastPage()); | ||
58 | static::assertTrue($searchResult->isFirstPage()); | ||
59 | static::assertFalse($searchResult->isLastPage()); | ||
60 | } | ||
61 | |||
62 | /** Create a SearchResult with offset and limit parameters */ | ||
63 | public function testResultWithLimitAndOffset(): void | ||
64 | { | ||
65 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 2, 2); | ||
66 | |||
67 | static::assertSame([2 => 'c', 3 => 'd'], $searchResult->getBookmarks()); | ||
68 | static::assertSame(2, $searchResult->getResultCount()); | ||
69 | static::assertSame(6, $searchResult->getTotalCount()); | ||
70 | static::assertSame(2, $searchResult->getLimit()); | ||
71 | static::assertSame(2, $searchResult->getOffset()); | ||
72 | static::assertSame(2, $searchResult->getPage()); | ||
73 | static::assertSame(3, $searchResult->getLastPage()); | ||
74 | static::assertFalse($searchResult->isFirstPage()); | ||
75 | static::assertFalse($searchResult->isLastPage()); | ||
76 | } | ||
77 | |||
78 | /** Create a SearchResult with offset and limit parameters displaying the last page */ | ||
79 | public function testResultWithLimitAndOffsetLastPage(): void | ||
80 | { | ||
81 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 4, 2); | ||
82 | |||
83 | static::assertSame([4 => 'e', 5 => 'f'], $searchResult->getBookmarks()); | ||
84 | static::assertSame(2, $searchResult->getResultCount()); | ||
85 | static::assertSame(6, $searchResult->getTotalCount()); | ||
86 | static::assertSame(2, $searchResult->getLimit()); | ||
87 | static::assertSame(4, $searchResult->getOffset()); | ||
88 | static::assertSame(3, $searchResult->getPage()); | ||
89 | static::assertSame(3, $searchResult->getLastPage()); | ||
90 | static::assertFalse($searchResult->isFirstPage()); | ||
91 | static::assertTrue($searchResult->isLastPage()); | ||
92 | } | ||
93 | |||
94 | /** Create a SearchResult with offset and limit parameters out of bound (display the last page) */ | ||
95 | public function testResultWithLimitAndOffsetOutOfBounds(): void | ||
96 | { | ||
97 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 12, 2); | ||
98 | |||
99 | static::assertSame([4 => 'e', 5 => 'f'], $searchResult->getBookmarks()); | ||
100 | static::assertSame(2, $searchResult->getResultCount()); | ||
101 | static::assertSame(6, $searchResult->getTotalCount()); | ||
102 | static::assertSame(2, $searchResult->getLimit()); | ||
103 | static::assertSame(-2, $searchResult->getOffset()); | ||
104 | static::assertSame(3, $searchResult->getPage()); | ||
105 | static::assertSame(3, $searchResult->getLastPage()); | ||
106 | static::assertFalse($searchResult->isFirstPage()); | ||
107 | static::assertTrue($searchResult->isLastPage()); | ||
108 | } | ||
109 | |||
110 | /** Create a SearchResult with offset and limit parameters out of bound (no result) */ | ||
111 | public function testResultWithLimitAndOffsetOutOfBoundsNoResult(): void | ||
112 | { | ||
113 | $searchResult = SearchResult::getSearchResult(['a', 'b', 'c', 'd', 'e', 'f'], 12, 2, true); | ||
114 | |||
115 | static::assertSame([], $searchResult->getBookmarks()); | ||
116 | static::assertSame(0, $searchResult->getResultCount()); | ||
117 | static::assertSame(6, $searchResult->getTotalCount()); | ||
118 | static::assertSame(2, $searchResult->getLimit()); | ||
119 | static::assertSame(12, $searchResult->getOffset()); | ||
120 | static::assertSame(7, $searchResult->getPage()); | ||
121 | static::assertSame(3, $searchResult->getLastPage()); | ||
122 | static::assertFalse($searchResult->isFirstPage()); | ||
123 | static::assertFalse($searchResult->isLastPage()); | ||
124 | } | ||
125 | } | ||
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 | ||
7 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\BookmarkFilter; | 8 | use Shaarli\Bookmark\BookmarkFilter; |
9 | use Shaarli\Bookmark\SearchResult; | ||
9 | use Shaarli\Config\ConfigManager; | 10 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Front\Exception\WrongTokenException; | 11 | use Shaarli\Front\Exception\WrongTokenException; |
11 | use Shaarli\Security\SessionManager; | 12 | use 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 | ||
7 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | 8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; |
9 | use Shaarli\Bookmark\SearchResult; | ||
9 | use Shaarli\TestCase; | 10 | use Shaarli\TestCase; |
10 | use Shaarli\Thumbnailer; | 11 | use Shaarli\Thumbnailer; |
11 | use Slim\Http\Request; | 12 | use 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 | ||
7 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | 8 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; |
9 | use Shaarli\Bookmark\SearchResult; | ||
9 | use Shaarli\Config\ConfigManager; | 10 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Security\LoginManager; | 11 | use Shaarli\Security\LoginManager; |
11 | use Shaarli\TestCase; | 12 | use 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); | |||
5 | namespace Shaarli\Front\Controller\Visitor; | 5 | namespace Shaarli\Front\Controller\Visitor; |
6 | 6 | ||
7 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\SearchResult; | ||
8 | use Shaarli\Feed\CachedPage; | 9 | use Shaarli\Feed\CachedPage; |
9 | use Shaarli\TestCase; | 10 | use Shaarli\TestCase; |
10 | use Slim\Http\Request; | 11 | use 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); | |||
5 | namespace Shaarli\Front\Controller\Visitor; | 5 | namespace Shaarli\Front\Controller\Visitor; |
6 | 6 | ||
7 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
8 | use Shaarli\Bookmark\SearchResult; | ||
8 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\Front\Exception\ThumbnailsDisabledException; | 10 | use Shaarli\Front\Exception\ThumbnailsDisabledException; |
10 | use Shaarli\TestCase; | 11 | use 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 | ; |