MyShaarli/tests/front/controller/admin/ShaarePublishControllerTest/DisplayCreateBatchFormTest.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

62 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ShaarePublishControllerTest;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ShaarePublishController;
use Shaarli\Http\HttpAccess;
use Shaarli\Http\MetadataRetriever;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
class DisplayCreateBatchFormTest extends TestCase
{
use FrontAdminControllerMockHelper;
/** @var ShaarePublishController */
protected $controller;
public function setUp(): void
{
$this->createContainer();
$this->container->httpAccess = $this->createMock(HttpAccess::class);
$this->container->metadataRetriever = $this->createMock(MetadataRetriever::class);
$this->controller = new ShaarePublishController($this->container);
}
/**
* TODO
*/
public function testDisplayCreateFormBatch(): void
{
$urls = [
'https://domain1.tld/url1',
'https://domain2.tld/url2',
'https://domain3.tld/url3',
];
$request = $this->createMock(Request::class);
$request->method('getParam')->willReturnCallback(function (string $key) use ($urls): ?string {
return $key === 'urls' ? implode(PHP_EOL, $urls) : null;
});
$response = new Response();
$assignedVariables = [];
$this->assignTemplateVars($assignedVariables);
$result = $this->controller->displayCreateBatchForms($request, $response);
static::assertSame(200, $result->getStatusCode());
static::assertSame('editlink.batch', (string) $result->getBody());
static::assertTrue($assignedVariables['batch_mode']);
static::assertCount(3, $assignedVariables['links']);
static::assertSame($urls[0], $assignedVariables['links'][0]['link']['url']);
static::assertSame($urls[1], $assignedVariables['links'][1]['link']['url']);
static::assertSame($urls[2], $assignedVariables['links'][2]['link']['url']);
}
}