3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Admin
;
7 use Shaarli\Config\ConfigManager
;
8 use Shaarli\Formatter\BookmarkMarkdownFormatter
;
9 use Shaarli\Http\HttpAccess
;
11 use Slim\Http\Request
;
12 use Slim\Http\Response
;
14 class ShaareAddControllerTest
extends TestCase
16 use FrontAdminControllerMockHelper
;
18 /** @var ShaareAddController */
19 protected $controller;
21 public function setUp(): void
23 $this->createContainer();
25 $this->container
->httpAccess
= $this->createMock(HttpAccess
::class);
26 $this->controller
= new ShaareAddController($this->container
);
30 * Test displaying add link page
32 public function testAddShaare(): void
34 $assignedVariables = [];
35 $this->assignTemplateVars($assignedVariables);
37 $request = $this->createMock(Request
::class);
38 $response = new Response();
45 $this->container
->bookmarkService
46 ->expects(static::once())
47 ->method('bookmarksCountPerTag')
48 ->willReturn($expectedTags)
50 $expectedTags = array_merge($expectedTags, [BookmarkMarkdownFormatter
::NO_MD_TAG
=> 1]);
52 $this->container
->conf
= $this->createMock(ConfigManager
::class);
53 $this->container
->conf
->method('get')->willReturnCallback(function (string $key, $default) {
54 return $key === 'formatter' ? 'markdown' : $default;
57 $result = $this->controller
->addShaare($request, $response);
59 static::assertSame(200, $result->getStatusCode());
60 static::assertSame('addlink', (string) $result->getBody());
62 static::assertSame('Shaare a new link - Shaarli', $assignedVariables['pagetitle']);
63 static::assertFalse($assignedVariables['default_private_links']);
64 static::assertTrue($assignedVariables['async_metadata']);
65 static::assertSame($expectedTags, $assignedVariables['tags']);
69 * Test displaying add link page
71 public function testAddShaareWithoutMd(): void
73 $assignedVariables = [];
74 $this->assignTemplateVars($assignedVariables);
76 $request = $this->createMock(Request
::class);
77 $response = new Response();
84 $this->container
->bookmarkService
85 ->expects(static::once())
86 ->method('bookmarksCountPerTag')
87 ->willReturn($expectedTags)
90 $result = $this->controller
->addShaare($request, $response);
92 static::assertSame(200, $result->getStatusCode());
93 static::assertSame('addlink', (string) $result->getBody());
95 static::assertSame($expectedTags, $assignedVariables['tags']);