Rename Convert to ConvertController for clarity

Renamed Convert class and relevant references to ConvertController to improve clarity and maintain consistency. Updated corresponding test files and route configurations to reflect the new name.
This commit is contained in:
2024-09-06 14:07:51 +02:00
parent dd159f4379
commit 4d73f9b81a
3 changed files with 10 additions and 8 deletions

View File

@@ -0,0 +1,107 @@
<?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\ConvertController;
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;
/**
* @internal
*
* @coversNothing
*/
final class ConvertControllerTest extends TestCase
{
use ProphecyTrait;
public function testConversionFailed(): void
{
$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());
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
$storeManager->read($storedObject)->willReturn('content');
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
$convert = new ConvertController(
$httpClient,
$this->makeRequestStack(),
$security->reveal(),
$storeManager->reveal(),
new NullLogger(),
$parameterBag
);
$response = $convert($storedObject);
$this->assertNotEquals(200, $response->getStatusCode());
}
public function testEverythingWentFine(): void
{
$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());
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
$storeManager->read($storedObject)->willReturn('content');
$parameterBag = new ParameterBag(['wopi' => ['server' => 'http://collabora:9980']]);
$convert = new ConvertController(
$httpClient,
$this->makeRequestStack(),
$security->reveal(),
$storeManager->reveal(),
new NullLogger(),
$parameterBag
);
$response = $convert($storedObject);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('1234', $response->getContent());
}
private function makeRequestStack(): RequestStack
{
$requestStack = new RequestStack();
$requestStack->push(new Request());
return $requestStack;
}
}