mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Flush entities when storing document using webdav / put operation
The WebdavController has been updated to flush the EntityManager after writing a document, while its tests have been adjusted correspondingly. A new test for the document PUT operation has also been added, which ensures the EntityManager flushes and the StoredObjectManager writes to this document.
This commit is contained in:
parent
ce5659219a
commit
1b16d4fe3b
@ -16,6 +16,7 @@ use Chill\DocStoreBundle\Dav\Response\DavResponse;
|
|||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
||||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
@ -42,6 +43,7 @@ final readonly class WebdavController
|
|||||||
private \Twig\Environment $engine,
|
private \Twig\Environment $engine,
|
||||||
private StoredObjectManagerInterface $storedObjectManager,
|
private StoredObjectManagerInterface $storedObjectManager,
|
||||||
private Security $security,
|
private Security $security,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
) {
|
) {
|
||||||
$this->requestAnalyzer = new PropfindRequestAnalyzer();
|
$this->requestAnalyzer = new PropfindRequestAnalyzer();
|
||||||
}
|
}
|
||||||
@ -201,6 +203,8 @@ final readonly class WebdavController
|
|||||||
|
|
||||||
$this->storedObjectManager->write($storedObject, $request->getContent());
|
$this->storedObjectManager->write($storedObject, $request->getContent());
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
return new DavResponse('', Response::HTTP_NO_CONTENT);
|
return new DavResponse('', Response::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,17 +40,20 @@ class WebdavControllerTest extends KernelTestCase
|
|||||||
$this->engine = self::getContainer()->get(\Twig\Environment::class);
|
$this->engine = self::getContainer()->get(\Twig\Environment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildController(EntityManagerInterface $entityManager = null): WebdavController
|
private function buildController(?EntityManagerInterface $entityManager = null, ?StoredObjectManagerInterface $storedObjectManager = null): WebdavController
|
||||||
{
|
{
|
||||||
|
if (null === $storedObjectManager) {
|
||||||
$storedObjectManager = new MockedStoredObjectManager();
|
$storedObjectManager = new MockedStoredObjectManager();
|
||||||
$security = $this->prophesize(Security::class);
|
}
|
||||||
$security->isGranted(Argument::in(['EDIT', 'SEE']), Argument::type(StoredObject::class))
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
if (null === $entityManager) {
|
if (null === $entityManager) {
|
||||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted(Argument::in(['SEE_AND_EDIT', 'SEE']), Argument::type(StoredObject::class))
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
return new WebdavController($this->engine, $storedObjectManager, $security->reveal(), $entityManager);
|
return new WebdavController($this->engine, $storedObjectManager, $security->reveal(), $entityManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +168,30 @@ class WebdavControllerTest extends KernelTestCase
|
|||||||
self::assertEquals(5, $response->headers->get('content-length'));
|
self::assertEquals(5, $response->headers->get('content-length'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPutDocument(): void
|
||||||
|
{
|
||||||
|
$document = $this->buildDocument();
|
||||||
|
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||||
|
$storedObjectManager = $this->createMock(StoredObjectManagerInterface::class);
|
||||||
|
|
||||||
|
// entity manager must be flushed
|
||||||
|
$entityManager->expects($this->once())
|
||||||
|
->method('flush');
|
||||||
|
|
||||||
|
// object must be written by StoredObjectManager
|
||||||
|
$storedObjectManager->expects($this->once())
|
||||||
|
->method('write')
|
||||||
|
->with($this->identicalTo($document), $this->identicalTo('1234'));
|
||||||
|
|
||||||
|
$controller = $this->buildController($entityManager, $storedObjectManager);
|
||||||
|
|
||||||
|
$request = new Request(content: '1234');
|
||||||
|
$response = $controller->putDocument($document, $request);
|
||||||
|
|
||||||
|
self::assertEquals(204, $response->getStatusCode());
|
||||||
|
self::assertEquals('', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
public static function generateDataPropfindDocument(): iterable
|
public static function generateDataPropfindDocument(): iterable
|
||||||
{
|
{
|
||||||
$content =
|
$content =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user