MyShaarli/tests/front/controller/admin/ShaareAddControllerTest.php
ArthurHoaro 5d8de7587d Feature: bulk creation of bookmarks
This changes creates a new form in addlink page allowing to create
multiple bookmarks at once more easily. It focuses on re-using as much
existing code and template component as  possible.

These changes includes:
  - a new form in addlink (hidden behind a button by default),
containing a text area for URL, and tags/private status to apply to
created links
  - this form displays a new template called editlink.batch, itself
including editlink template multiple times
  - User interation in this new templates are handle by a new JS script
(shaare-batch.js) making AJAX requests, and therefore does not need page
reloading
  - ManageShaareController has been split into 3 distinct controllers:
    + ShaareAdd: displays addlink template
    + ShaareManage: various operation applied on existing shaares
(change visibility, pin, deletion, etc.)
    + ShaarePublish: handles creation/edit forms and saving Shaare's
form
  - Updated translations

Fixes #137
2020-10-27 20:11:30 +01:00

97 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\BookmarkMarkdownFormatter;
use Shaarli\Http\HttpAccess;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
class ShaareAddControllerTest extends TestCase
{
use FrontAdminControllerMockHelper;
/** @var ShaareAddController */
protected $controller;
public function setUp(): void
{
$this->createContainer();
$this->container->httpAccess = $this->createMock(HttpAccess::class);
$this->controller = new ShaareAddController($this->container);
}
/**
* Test displaying add link page
*/
public function testAddShaare(): void
{
$assignedVariables = [];
$this->assignTemplateVars($assignedVariables);
$request = $this->createMock(Request::class);
$response = new Response();
$expectedTags = [
'tag1' => 32,
'tag2' => 24,
'tag3' => 1,
];
$this->container->bookmarkService
->expects(static::once())
->method('bookmarksCountPerTag')
->willReturn($expectedTags)
;
$expectedTags = array_merge($expectedTags, [BookmarkMarkdownFormatter::NO_MD_TAG => 1]);
$this->container->conf = $this->createMock(ConfigManager::class);
$this->container->conf->method('get')->willReturnCallback(function (string $key, $default) {
return $key === 'formatter' ? 'markdown' : $default;
});
$result = $this->controller->addShaare($request, $response);
static::assertSame(200, $result->getStatusCode());
static::assertSame('addlink', (string) $result->getBody());
static::assertSame('Shaare a new link - Shaarli', $assignedVariables['pagetitle']);
static::assertFalse($assignedVariables['default_private_links']);
static::assertTrue($assignedVariables['async_metadata']);
static::assertSame($expectedTags, $assignedVariables['tags']);
}
/**
* Test displaying add link page
*/
public function testAddShaareWithoutMd(): void
{
$assignedVariables = [];
$this->assignTemplateVars($assignedVariables);
$request = $this->createMock(Request::class);
$response = new Response();
$expectedTags = [
'tag1' => 32,
'tag2' => 24,
'tag3' => 1,
];
$this->container->bookmarkService
->expects(static::once())
->method('bookmarksCountPerTag')
->willReturn($expectedTags)
;
$result = $this->controller->addShaare($request, $response);
static::assertSame(200, $result->getStatusCode());
static::assertSame('addlink', (string) $result->getBody());
static::assertSame($expectedTags, $assignedVariables['tags']);
}
}