diff options
Diffstat (limited to 'tests/front/controller/TagControllerTest.php')
-rw-r--r-- | tests/front/controller/TagControllerTest.php | 49 |
1 files changed, 9 insertions, 40 deletions
diff --git a/tests/front/controller/TagControllerTest.php b/tests/front/controller/TagControllerTest.php index bbac5652..5eea537b 100644 --- a/tests/front/controller/TagControllerTest.php +++ b/tests/front/controller/TagControllerTest.php | |||
@@ -5,32 +5,27 @@ declare(strict_types=1); | |||
5 | namespace Shaarli\Front\Controller; | 5 | namespace Shaarli\Front\Controller; |
6 | 6 | ||
7 | use PHPUnit\Framework\TestCase; | 7 | use PHPUnit\Framework\TestCase; |
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
9 | use Shaarli\Config\ConfigManager; | ||
10 | use Shaarli\Container\ShaarliContainer; | ||
11 | use Shaarli\Plugin\PluginManager; | ||
12 | use Shaarli\Render\PageBuilder; | ||
13 | use Shaarli\Security\LoginManager; | ||
14 | use Slim\Http\Request; | 8 | use Slim\Http\Request; |
15 | use Slim\Http\Response; | 9 | use Slim\Http\Response; |
16 | 10 | ||
17 | class TagControllerTest extends TestCase | 11 | class TagControllerTest extends TestCase |
18 | { | 12 | { |
19 | /** @var ShaarliContainer */ | 13 | use FrontControllerMockHelper; |
20 | protected $container; | ||
21 | 14 | ||
22 | /** @var TagController */ | 15 | /** @var TagController */ |
23 | protected $controller; | 16 | protected $controller; |
24 | 17 | ||
25 | public function setUp(): void | 18 | public function setUp(): void |
26 | { | 19 | { |
27 | $this->container = $this->createMock(ShaarliContainer::class); | 20 | $this->createContainer(); |
21 | |||
28 | $this->controller = new TagController($this->container); | 22 | $this->controller = new TagController($this->container); |
29 | } | 23 | } |
30 | 24 | ||
31 | public function testAddTagWithReferer(): void | 25 | public function testAddTagWithReferer(): void |
32 | { | 26 | { |
33 | $this->createValidContainerMockSet(); | 27 | $this->createValidContainerMockSet(); |
28 | |||
34 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/']; | 29 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/']; |
35 | 30 | ||
36 | $request = $this->createMock(Request::class); | 31 | $request = $this->createMock(Request::class); |
@@ -48,6 +43,7 @@ class TagControllerTest extends TestCase | |||
48 | public function testAddTagWithRefererAndExistingSearch(): void | 43 | public function testAddTagWithRefererAndExistingSearch(): void |
49 | { | 44 | { |
50 | $this->createValidContainerMockSet(); | 45 | $this->createValidContainerMockSet(); |
46 | |||
51 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; | 47 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; |
52 | 48 | ||
53 | $request = $this->createMock(Request::class); | 49 | $request = $this->createMock(Request::class); |
@@ -81,6 +77,7 @@ class TagControllerTest extends TestCase | |||
81 | public function testAddTagRemoveLegacyQueryParam(): void | 77 | public function testAddTagRemoveLegacyQueryParam(): void |
82 | { | 78 | { |
83 | $this->createValidContainerMockSet(); | 79 | $this->createValidContainerMockSet(); |
80 | |||
84 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&addtag=abc']; | 81 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&addtag=abc']; |
85 | 82 | ||
86 | $request = $this->createMock(Request::class); | 83 | $request = $this->createMock(Request::class); |
@@ -98,6 +95,7 @@ class TagControllerTest extends TestCase | |||
98 | public function testAddTagResetPagination(): void | 95 | public function testAddTagResetPagination(): void |
99 | { | 96 | { |
100 | $this->createValidContainerMockSet(); | 97 | $this->createValidContainerMockSet(); |
98 | |||
101 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&page=12']; | 99 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&page=12']; |
102 | 100 | ||
103 | $request = $this->createMock(Request::class); | 101 | $request = $this->createMock(Request::class); |
@@ -115,6 +113,7 @@ class TagControllerTest extends TestCase | |||
115 | public function testAddTagWithRefererAndEmptySearch(): void | 113 | public function testAddTagWithRefererAndEmptySearch(): void |
116 | { | 114 | { |
117 | $this->createValidContainerMockSet(); | 115 | $this->createValidContainerMockSet(); |
116 | |||
118 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=']; | 117 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=']; |
119 | 118 | ||
120 | $request = $this->createMock(Request::class); | 119 | $request = $this->createMock(Request::class); |
@@ -132,6 +131,7 @@ class TagControllerTest extends TestCase | |||
132 | public function testAddTagWithoutNewTagWithReferer(): void | 131 | public function testAddTagWithoutNewTagWithReferer(): void |
133 | { | 132 | { |
134 | $this->createValidContainerMockSet(); | 133 | $this->createValidContainerMockSet(); |
134 | |||
135 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; | 135 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; |
136 | 136 | ||
137 | $request = $this->createMock(Request::class); | 137 | $request = $this->createMock(Request::class); |
@@ -157,35 +157,4 @@ class TagControllerTest extends TestCase | |||
157 | static::assertSame(302, $result->getStatusCode()); | 157 | static::assertSame(302, $result->getStatusCode()); |
158 | static::assertSame(['./'], $result->getHeader('location')); | 158 | static::assertSame(['./'], $result->getHeader('location')); |
159 | } | 159 | } |
160 | |||
161 | protected function createValidContainerMockSet(): void | ||
162 | { | ||
163 | // User logged out | ||
164 | $loginManager = $this->createMock(LoginManager::class); | ||
165 | $loginManager->method('isLoggedIn')->willReturn(false); | ||
166 | $loginManager->method('canLogin')->willReturn(true); | ||
167 | $this->container->loginManager = $loginManager; | ||
168 | |||
169 | // Config | ||
170 | $conf = $this->createMock(ConfigManager::class); | ||
171 | $conf->method('get')->willReturnCallback(function (string $parameter, $default) { | ||
172 | return $default; | ||
173 | }); | ||
174 | $this->container->conf = $conf; | ||
175 | |||
176 | // PageBuilder | ||
177 | $pageBuilder = $this->createMock(PageBuilder::class); | ||
178 | $pageBuilder | ||
179 | ->method('render') | ||
180 | ->willReturnCallback(function (string $template): string { | ||
181 | return $template; | ||
182 | }) | ||
183 | ; | ||
184 | $this->container->pageBuilder = $pageBuilder; | ||
185 | |||
186 | $pluginManager = $this->createMock(PluginManager::class); | ||
187 | $this->container->pluginManager = $pluginManager; | ||
188 | $bookmarkService = $this->createMock(BookmarkServiceInterface::class); | ||
189 | $this->container->bookmarkService = $bookmarkService; | ||
190 | } | ||
191 | } | 160 | } |