diff options
Diffstat (limited to 'tests/front/controller/PictureWallControllerTest.php')
-rw-r--r-- | tests/front/controller/PictureWallControllerTest.php | 65 |
1 files changed, 5 insertions, 60 deletions
diff --git a/tests/front/controller/PictureWallControllerTest.php b/tests/front/controller/PictureWallControllerTest.php index 63802abd..8160bb38 100644 --- a/tests/front/controller/PictureWallControllerTest.php +++ b/tests/front/controller/PictureWallControllerTest.php | |||
@@ -6,31 +6,23 @@ namespace Shaarli\Front\Controller; | |||
6 | 6 | ||
7 | use PHPUnit\Framework\TestCase; | 7 | use PHPUnit\Framework\TestCase; |
8 | use Shaarli\Bookmark\Bookmark; | 8 | use Shaarli\Bookmark\Bookmark; |
9 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
10 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
11 | use Shaarli\Container\ShaarliContainer; | ||
12 | use Shaarli\Formatter\BookmarkFormatter; | ||
13 | use Shaarli\Formatter\BookmarkRawFormatter; | ||
14 | use Shaarli\Formatter\FormatterFactory; | ||
15 | use Shaarli\Front\Exception\ThumbnailsDisabledException; | 10 | use Shaarli\Front\Exception\ThumbnailsDisabledException; |
16 | use Shaarli\Plugin\PluginManager; | ||
17 | use Shaarli\Render\PageBuilder; | ||
18 | use Shaarli\Security\LoginManager; | ||
19 | use Shaarli\Thumbnailer; | 11 | use Shaarli\Thumbnailer; |
20 | use Slim\Http\Request; | 12 | use Slim\Http\Request; |
21 | use Slim\Http\Response; | 13 | use Slim\Http\Response; |
22 | 14 | ||
23 | class PictureWallControllerTest extends TestCase | 15 | class PictureWallControllerTest extends TestCase |
24 | { | 16 | { |
25 | /** @var ShaarliContainer */ | 17 | use FrontControllerMockHelper; |
26 | protected $container; | ||
27 | 18 | ||
28 | /** @var PictureWallController */ | 19 | /** @var PictureWallController */ |
29 | protected $controller; | 20 | protected $controller; |
30 | 21 | ||
31 | public function setUp(): void | 22 | public function setUp(): void |
32 | { | 23 | { |
33 | $this->container = $this->createMock(ShaarliContainer::class); | 24 | $this->createContainer(); |
25 | |||
34 | $this->controller = new PictureWallController($this->container); | 26 | $this->controller = new PictureWallController($this->container); |
35 | } | 27 | } |
36 | 28 | ||
@@ -43,6 +35,7 @@ class PictureWallControllerTest extends TestCase | |||
43 | $response = new Response(); | 35 | $response = new Response(); |
44 | 36 | ||
45 | // ConfigManager: thumbnails are enabled | 37 | // ConfigManager: thumbnails are enabled |
38 | $this->container->conf = $this->createMock(ConfigManager::class); | ||
46 | $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) { | 39 | $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) { |
47 | if ($parameter === 'thumbnails.mode') { | 40 | if ($parameter === 'thumbnails.mode') { |
48 | return Thumbnailer::MODE_COMMON; | 41 | return Thumbnailer::MODE_COMMON; |
@@ -53,15 +46,7 @@ class PictureWallControllerTest extends TestCase | |||
53 | 46 | ||
54 | // Save RainTPL assigned variables | 47 | // Save RainTPL assigned variables |
55 | $assignedVariables = []; | 48 | $assignedVariables = []; |
56 | $this->container->pageBuilder | 49 | $this->assignTemplateVars($assignedVariables); |
57 | ->expects(static::atLeastOnce()) | ||
58 | ->method('assign') | ||
59 | ->willReturnCallback(function ($key, $value) use (&$assignedVariables) { | ||
60 | $assignedVariables[$key] = $value; | ||
61 | |||
62 | return $this; | ||
63 | }) | ||
64 | ; | ||
65 | 50 | ||
66 | // Links dataset: 2 links with thumbnails | 51 | // Links dataset: 2 links with thumbnails |
67 | $this->container->bookmarkService | 52 | $this->container->bookmarkService |
@@ -137,44 +122,4 @@ class PictureWallControllerTest extends TestCase | |||
137 | 122 | ||
138 | $this->controller->index($request, $response); | 123 | $this->controller->index($request, $response); |
139 | } | 124 | } |
140 | |||
141 | protected function createValidContainerMockSet(): void | ||
142 | { | ||
143 | $loginManager = $this->createMock(LoginManager::class); | ||
144 | $this->container->loginManager = $loginManager; | ||
145 | |||
146 | // Config | ||
147 | $conf = $this->createMock(ConfigManager::class); | ||
148 | $this->container->conf = $conf; | ||
149 | |||
150 | // PageBuilder | ||
151 | $pageBuilder = $this->createMock(PageBuilder::class); | ||
152 | $pageBuilder | ||
153 | ->method('render') | ||
154 | ->willReturnCallback(function (string $template): string { | ||
155 | return $template; | ||
156 | }) | ||
157 | ; | ||
158 | $this->container->pageBuilder = $pageBuilder; | ||
159 | |||
160 | // Plugin Manager | ||
161 | $pluginManager = $this->createMock(PluginManager::class); | ||
162 | $this->container->pluginManager = $pluginManager; | ||
163 | |||
164 | // BookmarkService | ||
165 | $bookmarkService = $this->createMock(BookmarkServiceInterface::class); | ||
166 | $this->container->bookmarkService = $bookmarkService; | ||
167 | |||
168 | // Formatter | ||
169 | $formatterFactory = $this->createMock(FormatterFactory::class); | ||
170 | $formatterFactory | ||
171 | ->method('getFormatter') | ||
172 | ->willReturnCallback(function (string $type): BookmarkFormatter { | ||
173 | if ($type === 'raw') { | ||
174 | return new BookmarkRawFormatter($this->container->conf, true); | ||
175 | } | ||
176 | }) | ||
177 | ; | ||
178 | $this->container->formatterFactory = $formatterFactory; | ||
179 | } | ||
180 | } | 125 | } |