Add WopiConverter service and update Collabora integration tests

Introduce the WopiConverter service to handle document-to-PDF conversion using Collabora Online. Extend and update related tests in WopiConvertToPdfTest and ConvertControllerTest for better coverage and reliability. Enhance the GitLab CI configuration to exclude new test category "collabora-integration".
This commit is contained in:
2024-09-10 10:44:45 +02:00
parent 2fb46c65c2
commit f5ba5d574b
9 changed files with 171 additions and 89 deletions

View File

@@ -13,16 +13,12 @@ namespace Chill\WopiBundle\Tests\Controller;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Chill\MainBundle\Entity\User;
use Chill\WopiBundle\Controller\ConvertController;
use Chill\WopiBundle\Service\WopiConverter;
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\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
/**
@@ -39,28 +35,27 @@ final class ConvertControllerTest extends TestCase
$storedObject = new StoredObject();
$storedObject->registerVersion(type: '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());
$security->isGranted('ROLE_USER')->willReturn(true);
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
$storeManager->read($storedObject)->willReturn('content');
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
$wopiConverter = $this->prophesize(WopiConverter::class);
$wopiConverter->convert('fr', 'content', 'application/vnd.oasis.opendocument.text')
->willThrow(new \RuntimeException());
$convert = new ConvertController(
$httpClient,
$this->makeRequestStack(),
$controller = new ConvertController(
$security->reveal(),
$storeManager->reveal(),
$wopiConverter->reveal(),
new NullLogger(),
$parameterBag
);
$response = $convert($storedObject);
$request = new Request();
$request->setLocale('fr');
$response = $controller($storedObject, $request);
$this->assertNotEquals(200, $response->getStatusCode());
}
@@ -70,38 +65,29 @@ final class ConvertControllerTest extends TestCase
$storedObject = new StoredObject();
$storedObject->registerVersion(type: '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());
$security->isGranted('ROLE_USER')->willReturn(true);
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
$storeManager->read($storedObject)->willReturn('content');
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
$wopiConverter = $this->prophesize(WopiConverter::class);
$wopiConverter->convert('fr', 'content', 'application/vnd.oasis.opendocument.text')
->willReturn('1234');
$convert = new ConvertController(
$httpClient,
$this->makeRequestStack(),
$controller = new ConvertController(
$security->reveal(),
$storeManager->reveal(),
$wopiConverter->reveal(),
new NullLogger(),
$parameterBag
);
$response = $convert($storedObject);
$request = new Request();
$request->setLocale('fr');
$response = $controller($storedObject, $request);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('1234', $response->getContent());
}
private function makeRequestStack(): RequestStack
{
$requestStack = new RequestStack();
$requestStack->push(new Request());
return $requestStack;
}
}