mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 04:23:49 +00:00
Feature: allow to convert to PDF from Chill and group action button on document
BREAKING CHANGE: avoid using the macro for download button. To keep the UI clean, use always the new "group of action buttons".
This commit is contained in:
92
src/Bundle/ChillWopiBundle/tests/Controller/ConverTest.php
Normal file
92
src/Bundle/ChillWopiBundle/tests/Controller/ConverTest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\WopiBundle\Tests\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\WopiBundle\Controller\Convert;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Component\HttpClient\Response\MockResponse;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ConverTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testConversionFailed(): void
|
||||
{
|
||||
$storedObject = (new StoredObject())->setType('application/vnd.oasis.opendocument.text');
|
||||
|
||||
$httpClient = new MockHttpClient([
|
||||
new MockResponse('not authorized', ['http_code' => 401]),
|
||||
], 'http://collabora:9980');
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn(new User());
|
||||
|
||||
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storeManager->read($storedObject)->willReturn('content');
|
||||
|
||||
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
|
||||
|
||||
$convert = new Convert(
|
||||
$httpClient,
|
||||
$security->reveal(),
|
||||
$storeManager->reveal(),
|
||||
new NullLogger(),
|
||||
$parameterBag
|
||||
);
|
||||
|
||||
$response = $convert($storedObject);
|
||||
|
||||
$this->assertNotEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testEverythingWentFine(): void
|
||||
{
|
||||
$storedObject = (new StoredObject())->setType('application/vnd.oasis.opendocument.text');
|
||||
|
||||
$httpClient = new MockHttpClient([
|
||||
new MockResponse('1234', ['http_code' => 200]),
|
||||
], 'http://collabora:9980');
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn(new User());
|
||||
|
||||
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storeManager->read($storedObject)->willReturn('content');
|
||||
|
||||
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
|
||||
|
||||
$convert = new Convert(
|
||||
$httpClient,
|
||||
$security->reveal(),
|
||||
$storeManager->reveal(),
|
||||
new NullLogger(),
|
||||
$parameterBag
|
||||
);
|
||||
|
||||
$response = $convert($storedObject);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('1234', $response->getContent());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user