aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-20 10:47:20 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit5ec4708ced1cdca01eddd7e52377ab5e5f8b3290 (patch)
tree2d65bdd883c70ac12bee12e113f514cd59d3bdc2 /tests
parent7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5 (diff)
downloadShaarli-5ec4708ced1cdca01eddd7e52377ab5e5f8b3290.tar.gz
Shaarli-5ec4708ced1cdca01eddd7e52377ab5e5f8b3290.tar.zst
Shaarli-5ec4708ced1cdca01eddd7e52377ab5e5f8b3290.zip
Process OpenSearch controller through Slim
Also it was missing on the default template feeds
Diffstat (limited to 'tests')
-rw-r--r--tests/front/controller/OpenSearchControllerTest.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/front/controller/OpenSearchControllerTest.php b/tests/front/controller/OpenSearchControllerTest.php
new file mode 100644
index 00000000..7ba0f7df
--- /dev/null
+++ b/tests/front/controller/OpenSearchControllerTest.php
@@ -0,0 +1,92 @@
1<?php
2
3declare(strict_types=1);
4
5namespace front\controller;
6
7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Container\ShaarliContainer;
10use Shaarli\Front\Controller\OpenSearchController;
11use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder;
13use Shaarli\Security\LoginManager;
14use Slim\Http\Request;
15use Slim\Http\Response;
16
17class OpenSearchControllerTest extends TestCase
18{
19 /** @var ShaarliContainer */
20 protected $container;
21
22 /** @var OpenSearchController */
23 protected $controller;
24
25 public function setUp(): void
26 {
27 $this->container = $this->createMock(ShaarliContainer::class);
28 $this->controller = new OpenSearchController($this->container);
29 }
30
31 public function testOpenSearchController(): void
32 {
33 $this->createValidContainerMockSet();
34
35 $request = $this->createMock(Request::class);
36 $response = new Response();
37
38 // Save RainTPL assigned variables
39 $assignedVariables = [];
40 $this->assignTemplateVars($assignedVariables);
41
42 $result = $this->controller->index($request, $response);
43
44 static::assertSame(200, $result->getStatusCode());
45 static::assertStringContainsString('application/xml', $result->getHeader('Content-Type')[0]);
46 static::assertSame('opensearch', (string) $result->getBody());
47 static::assertSame('http://shaarli', $assignedVariables['serverurl']);
48 }
49
50 protected function createValidContainerMockSet(): void
51 {
52 $loginManager = $this->createMock(LoginManager::class);
53 $this->container->loginManager = $loginManager;
54
55 // PageBuilder
56 $pageBuilder = $this->createMock(PageBuilder::class);
57 $pageBuilder
58 ->method('render')
59 ->willReturnCallback(function (string $template): string {
60 return $template;
61 })
62 ;
63 $this->container->pageBuilder = $pageBuilder;
64
65 $bookmarkService = $this->createMock(BookmarkServiceInterface::class);
66 $this->container->bookmarkService = $bookmarkService;
67
68 // Plugin Manager
69 $pluginManager = $this->createMock(PluginManager::class);
70 $this->container->pluginManager = $pluginManager;
71
72 // $_SERVER
73 $this->container->environment = [
74 'SERVER_NAME' => 'shaarli',
75 'SERVER_PORT' => '80',
76 'REQUEST_URI' => '/open-search',
77 ];
78 }
79
80 protected function assignTemplateVars(array &$variables): void
81 {
82 $this->container->pageBuilder
83 ->expects(static::atLeastOnce())
84 ->method('assign')
85 ->willReturnCallback(function ($key, $value) use (&$variables) {
86 $variables[$key] = $value;
87
88 return $this;
89 })
90 ;
91 }
92}