diff options
Diffstat (limited to 'tests/front/controller/ShaarliControllerTest.php')
-rw-r--r-- | tests/front/controller/ShaarliControllerTest.php | 68 |
1 files changed, 23 insertions, 45 deletions
diff --git a/tests/front/controller/ShaarliControllerTest.php b/tests/front/controller/ShaarliControllerTest.php index 6fa3feb9..3efe4d95 100644 --- a/tests/front/controller/ShaarliControllerTest.php +++ b/tests/front/controller/ShaarliControllerTest.php | |||
@@ -6,11 +6,6 @@ namespace Shaarli\Front\Controller; | |||
6 | 6 | ||
7 | use PHPUnit\Framework\TestCase; | 7 | use PHPUnit\Framework\TestCase; |
8 | use Shaarli\Bookmark\BookmarkFilter; | 8 | use Shaarli\Bookmark\BookmarkFilter; |
9 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
10 | use Shaarli\Container\ShaarliContainer; | ||
11 | use Shaarli\Plugin\PluginManager; | ||
12 | use Shaarli\Render\PageBuilder; | ||
13 | use Shaarli\Security\LoginManager; | ||
14 | 9 | ||
15 | /** | 10 | /** |
16 | * Class ShaarliControllerTest | 11 | * Class ShaarliControllerTest |
@@ -20,8 +15,7 @@ use Shaarli\Security\LoginManager; | |||
20 | */ | 15 | */ |
21 | class ShaarliControllerTest extends TestCase | 16 | class ShaarliControllerTest extends TestCase |
22 | { | 17 | { |
23 | /** @var ShaarliContainer */ | 18 | use FrontControllerMockHelper; |
24 | protected $container; | ||
25 | 19 | ||
26 | /** @var LoginController */ | 20 | /** @var LoginController */ |
27 | protected $controller; | 21 | protected $controller; |
@@ -31,7 +25,8 @@ class ShaarliControllerTest extends TestCase | |||
31 | 25 | ||
32 | public function setUp(): void | 26 | public function setUp(): void |
33 | { | 27 | { |
34 | $this->container = $this->createMock(ShaarliContainer::class); | 28 | $this->createContainer(); |
29 | |||
35 | $this->controller = new class($this->container) extends ShaarliController | 30 | $this->controller = new class($this->container) extends ShaarliController |
36 | { | 31 | { |
37 | public function assignView(string $key, $value): ShaarliController | 32 | public function assignView(string $key, $value): ShaarliController |
@@ -51,6 +46,8 @@ class ShaarliControllerTest extends TestCase | |||
51 | { | 46 | { |
52 | $this->createValidContainerMockSet(); | 47 | $this->createValidContainerMockSet(); |
53 | 48 | ||
49 | $this->assignTemplateVars($this->assignedValues); | ||
50 | |||
54 | $self = $this->controller->assignView('variableName', 'variableValue'); | 51 | $self = $this->controller->assignView('variableName', 'variableValue'); |
55 | 52 | ||
56 | static::assertInstanceOf(ShaarliController::class, $self); | 53 | static::assertInstanceOf(ShaarliController::class, $self); |
@@ -61,6 +58,24 @@ class ShaarliControllerTest extends TestCase | |||
61 | { | 58 | { |
62 | $this->createValidContainerMockSet(); | 59 | $this->createValidContainerMockSet(); |
63 | 60 | ||
61 | $this->assignTemplateVars($this->assignedValues); | ||
62 | |||
63 | $this->container->bookmarkService | ||
64 | ->method('count') | ||
65 | ->willReturnCallback(function (string $visibility): int { | ||
66 | return $visibility === BookmarkFilter::$PRIVATE ? 5 : 10; | ||
67 | }) | ||
68 | ; | ||
69 | |||
70 | $this->container->pluginManager | ||
71 | ->method('executeHooks') | ||
72 | ->willReturnCallback(function (string $hook, array &$data, array $params): array { | ||
73 | return $data[$hook] = $params; | ||
74 | }); | ||
75 | $this->container->pluginManager->method('getErrors')->willReturn(['error']); | ||
76 | |||
77 | $this->container->loginManager->method('isLoggedIn')->willReturn(true); | ||
78 | |||
64 | $render = $this->controller->render('templateName'); | 79 | $render = $this->controller->render('templateName'); |
65 | 80 | ||
66 | static::assertSame('templateName', $render); | 81 | static::assertSame('templateName', $render); |
@@ -76,41 +91,4 @@ class ShaarliControllerTest extends TestCase | |||
76 | static::assertSame('templateName', $this->assignedValues['plugins_footer']['render_footer']['target']); | 91 | static::assertSame('templateName', $this->assignedValues['plugins_footer']['render_footer']['target']); |
77 | static::assertTrue($this->assignedValues['plugins_footer']['render_footer']['loggedin']); | 92 | static::assertTrue($this->assignedValues['plugins_footer']['render_footer']['loggedin']); |
78 | } | 93 | } |
79 | |||
80 | protected function createValidContainerMockSet(): void | ||
81 | { | ||
82 | $pageBuilder = $this->createMock(PageBuilder::class); | ||
83 | $pageBuilder | ||
84 | ->method('assign') | ||
85 | ->willReturnCallback(function (string $key, $value): void { | ||
86 | $this->assignedValues[$key] = $value; | ||
87 | }); | ||
88 | $pageBuilder | ||
89 | ->method('render') | ||
90 | ->willReturnCallback(function (string $template): string { | ||
91 | return $template; | ||
92 | }); | ||
93 | $this->container->pageBuilder = $pageBuilder; | ||
94 | |||
95 | $bookmarkService = $this->createMock(BookmarkServiceInterface::class); | ||
96 | $bookmarkService | ||
97 | ->method('count') | ||
98 | ->willReturnCallback(function (string $visibility): int { | ||
99 | return $visibility === BookmarkFilter::$PRIVATE ? 5 : 10; | ||
100 | }); | ||
101 | $this->container->bookmarkService = $bookmarkService; | ||
102 | |||
103 | $pluginManager = $this->createMock(PluginManager::class); | ||
104 | $pluginManager | ||
105 | ->method('executeHooks') | ||
106 | ->willReturnCallback(function (string $hook, array &$data, array $params): array { | ||
107 | return $data[$hook] = $params; | ||
108 | }); | ||
109 | $pluginManager->method('getErrors')->willReturn(['error']); | ||
110 | $this->container->pluginManager = $pluginManager; | ||
111 | |||
112 | $loginManager = $this->createMock(LoginManager::class); | ||
113 | $loginManager->method('isLoggedIn')->willReturn(true); | ||
114 | $this->container->loginManager = $loginManager; | ||
115 | } | ||
116 | } | 94 | } |