aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/PictureWallControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/front/controller/PictureWallControllerTest.php')
-rw-r--r--tests/front/controller/PictureWallControllerTest.php65
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
7use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 8use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\BookmarkServiceInterface;
10use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
11use Shaarli\Container\ShaarliContainer;
12use Shaarli\Formatter\BookmarkFormatter;
13use Shaarli\Formatter\BookmarkRawFormatter;
14use Shaarli\Formatter\FormatterFactory;
15use Shaarli\Front\Exception\ThumbnailsDisabledException; 10use Shaarli\Front\Exception\ThumbnailsDisabledException;
16use Shaarli\Plugin\PluginManager;
17use Shaarli\Render\PageBuilder;
18use Shaarli\Security\LoginManager;
19use Shaarli\Thumbnailer; 11use Shaarli\Thumbnailer;
20use Slim\Http\Request; 12use Slim\Http\Request;
21use Slim\Http\Response; 13use Slim\Http\Response;
22 14
23class PictureWallControllerTest extends TestCase 15class 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}