mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Apply new CS rules on the webdav feature
This commit is contained in:
@@ -14,18 +14,16 @@ namespace Chill\DocStoreBundle\Tests\Controller;
|
||||
use Chill\DocStoreBundle\Controller\WebdavController;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use DateTimeInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class WebdavControllerTest extends KernelTestCase
|
||||
@@ -124,7 +122,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
self::assertEquals($expectedStatusCode, $response->getStatusCode());
|
||||
self::assertContains('content-type', $response->headers->keys());
|
||||
self::assertStringContainsString('text/xml', $response->headers->get('content-type'));
|
||||
self::assertTrue((new \DOMDocument())->loadXML($response->getContent()), $message . " test that the xml response is a valid xml");
|
||||
self::assertTrue((new \DOMDocument())->loadXML($response->getContent()), $message.' test that the xml response is a valid xml');
|
||||
self::assertXmlStringEqualsXmlString($expectedXmlResponse, $response->getContent(), $message);
|
||||
}
|
||||
|
||||
@@ -137,13 +135,13 @@ class WebdavControllerTest extends KernelTestCase
|
||||
|
||||
$request = new Request([], [], [], [], [], [], $requestContent);
|
||||
$request->setMethod('PROPFIND');
|
||||
$request->headers->add(["Depth" => "0"]);
|
||||
$request->headers->add(['Depth' => '0']);
|
||||
$response = $controller->propfindDirectory($this->buildDocument(), '1234', $request);
|
||||
|
||||
self::assertEquals($expectedStatusCode, $response->getStatusCode());
|
||||
self::assertContains('content-type', $response->headers->keys());
|
||||
self::assertStringContainsString('text/xml', $response->headers->get('content-type'));
|
||||
self::assertTrue((new \DOMDocument())->loadXML($response->getContent()), $message . " test that the xml response is a valid xml");
|
||||
self::assertTrue((new \DOMDocument())->loadXML($response->getContent()), $message.' test that the xml response is a valid xml');
|
||||
self::assertXmlStringEqualsXmlString($expectedXmlResponse, $response->getContent(), $message);
|
||||
}
|
||||
|
||||
@@ -192,7 +190,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:multistatus>
|
||||
XML;
|
||||
|
||||
yield [$content, 207, $response, "get IsReadOnly and contenttype from server"];
|
||||
yield [$content, 207, $response, 'get IsReadOnly and contenttype from server'];
|
||||
|
||||
$content =
|
||||
<<<'XML'
|
||||
@@ -220,7 +218,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:multistatus>
|
||||
XML;
|
||||
|
||||
yield [$content, 207, $response, "get property IsReadOnly"];
|
||||
yield [$content, 207, $response, 'get property IsReadOnly'];
|
||||
|
||||
yield [
|
||||
<<<'XML'
|
||||
@@ -246,7 +244,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:response>
|
||||
</d:multistatus>
|
||||
XML,
|
||||
"Test requesting an unknow property"
|
||||
'Test requesting an unknow property',
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -274,7 +272,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:response>
|
||||
</d:multistatus>
|
||||
XML,
|
||||
"test getting the last modified date"
|
||||
'test getting the last modified date',
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -311,7 +309,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:response>
|
||||
</d:multistatus>
|
||||
XML,
|
||||
"test finding all properties"
|
||||
'test finding all properties',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -356,7 +354,7 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:response>
|
||||
</d:multistatus>
|
||||
XML,
|
||||
"test resourceType and IsReadOnly "
|
||||
'test resourceType and IsReadOnly ',
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -379,15 +377,14 @@ class WebdavControllerTest extends KernelTestCase
|
||||
</d:response>
|
||||
</d:multistatus>
|
||||
XML,
|
||||
"test creatableContentsInfo"
|
||||
'test creatableContentsInfo',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MockedStoredObjectManager implements StoredObjectManagerInterface
|
||||
{
|
||||
public function getLastModified(StoredObject $document): DateTimeInterface
|
||||
public function getLastModified(StoredObject $document): \DateTimeInterface
|
||||
{
|
||||
return new \DateTimeImmutable('2023-09-13T14:15');
|
||||
}
|
||||
@@ -402,11 +399,12 @@ class MockedStoredObjectManager implements StoredObjectManagerInterface
|
||||
return 'abcde';
|
||||
}
|
||||
|
||||
public function write(StoredObject $document, string $clearContent): void {}
|
||||
public function write(StoredObject $document, string $clearContent): void
|
||||
{
|
||||
}
|
||||
|
||||
public function etag(StoredObject $document): string
|
||||
{
|
||||
return 'ab56b4d92b40713acc5af89985d4b786';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,11 +12,11 @@ declare(strict_types=1);
|
||||
namespace Chill\DocStoreBundle\Tests\Dav\Request;
|
||||
|
||||
use Chill\DocStoreBundle\Dav\Request\PropfindRequestAnalyzer;
|
||||
use phpseclib3\Crypt\DSA\Formats\Keys\XML;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class PropfindRequestAnalyzerTest extends TestCase
|
||||
@@ -33,7 +33,7 @@ class PropfindRequestAnalyzerTest extends TestCase
|
||||
$actual = $analyzer->getRequestedProperties($request);
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
if ($key === 'unknowns') {
|
||||
if ('unknowns' === $key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -59,17 +59,17 @@ class PropfindRequestAnalyzerTest extends TestCase
|
||||
</propfind>
|
||||
XML,
|
||||
[
|
||||
"resourceType" => false,
|
||||
"contentType" => false,
|
||||
"lastModified" => false,
|
||||
"creationDate" => false,
|
||||
"contentLength" => false,
|
||||
"etag" => false,
|
||||
"supportedLock" => false,
|
||||
'resourceType' => false,
|
||||
'contentType' => false,
|
||||
'lastModified' => false,
|
||||
'creationDate' => false,
|
||||
'contentLength' => false,
|
||||
'etag' => false,
|
||||
'supportedLock' => false,
|
||||
'unknowns' => [
|
||||
['xmlns' => 'http://ucb.openoffice.org/dav/props/', 'prop' => 'BaseURI']
|
||||
]
|
||||
]
|
||||
['xmlns' => 'http://ucb.openoffice.org/dav/props/', 'prop' => 'BaseURI'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -80,15 +80,15 @@ class PropfindRequestAnalyzerTest extends TestCase
|
||||
</propfind>
|
||||
XML,
|
||||
[
|
||||
"resourceType" => true,
|
||||
"contentType" => true,
|
||||
"lastModified" => true,
|
||||
"creationDate" => true,
|
||||
"contentLength" => true,
|
||||
"etag" => true,
|
||||
"supportedLock" => true,
|
||||
"unknowns" => [],
|
||||
]
|
||||
'resourceType' => true,
|
||||
'contentType' => true,
|
||||
'lastModified' => true,
|
||||
'creationDate' => true,
|
||||
'contentLength' => true,
|
||||
'etag' => true,
|
||||
'supportedLock' => true,
|
||||
'unknowns' => [],
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -101,15 +101,15 @@ class PropfindRequestAnalyzerTest extends TestCase
|
||||
</propfind>
|
||||
XML,
|
||||
[
|
||||
"resourceType" => false,
|
||||
"contentType" => false,
|
||||
"lastModified" => true,
|
||||
"creationDate" => false,
|
||||
"contentLength" => false,
|
||||
"etag" => false,
|
||||
"supportedLock" => false,
|
||||
'unknowns' => []
|
||||
]
|
||||
'resourceType' => false,
|
||||
'contentType' => false,
|
||||
'lastModified' => true,
|
||||
'creationDate' => false,
|
||||
'contentLength' => false,
|
||||
'etag' => false,
|
||||
'supportedLock' => false,
|
||||
'unknowns' => [],
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -118,17 +118,17 @@ class PropfindRequestAnalyzerTest extends TestCase
|
||||
<propfind xmlns="DAV:"><prop><resourcetype xmlns="DAV:"/><IsReadOnly xmlns="http://ucb.openoffice.org/dav/props/"/><getcontenttype xmlns="DAV:"/><supportedlock xmlns="DAV:"/></prop></propfind>
|
||||
XML,
|
||||
[
|
||||
"resourceType" => true,
|
||||
"contentType" => true,
|
||||
"lastModified" => false,
|
||||
"creationDate" => false,
|
||||
"contentLength" => false,
|
||||
"etag" => false,
|
||||
"supportedLock" => false,
|
||||
'resourceType' => true,
|
||||
'contentType' => true,
|
||||
'lastModified' => false,
|
||||
'creationDate' => false,
|
||||
'contentLength' => false,
|
||||
'etag' => false,
|
||||
'supportedLock' => false,
|
||||
'unknowns' => [
|
||||
['xmlns' => 'http://ucb.openoffice.org/dav/props/', 'prop' => 'IsReadOnly']
|
||||
]
|
||||
]
|
||||
['xmlns' => 'http://ucb.openoffice.org/dav/props/', 'prop' => 'IsReadOnly'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class StoredObjectVoterTest extends TestCase
|
||||
@@ -31,7 +32,7 @@ class StoredObjectVoterTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideDataVote
|
||||
*/
|
||||
public function testVote(TokenInterface $token, object|null $subject, string $attribute, mixed $expected): void
|
||||
public function testVote(TokenInterface $token, null|object $subject, string $attribute, mixed $expected): void
|
||||
{
|
||||
$voter = new StoredObjectVoter();
|
||||
|
||||
@@ -44,28 +45,28 @@ class StoredObjectVoterTest extends TestCase
|
||||
$this->buildToken(StoredObjectRoleEnum::EDIT, new StoredObject()),
|
||||
new \stdClass(),
|
||||
'SOMETHING',
|
||||
VoterInterface::ACCESS_ABSTAIN
|
||||
VoterInterface::ACCESS_ABSTAIN,
|
||||
];
|
||||
|
||||
yield [
|
||||
$this->buildToken(StoredObjectRoleEnum::EDIT, $so = new StoredObject()),
|
||||
$so,
|
||||
'SOMETHING',
|
||||
VoterInterface::ACCESS_ABSTAIN
|
||||
VoterInterface::ACCESS_ABSTAIN,
|
||||
];
|
||||
|
||||
yield [
|
||||
$this->buildToken(StoredObjectRoleEnum::EDIT, $so = new StoredObject()),
|
||||
$so,
|
||||
StoredObjectRoleEnum::SEE->value,
|
||||
VoterInterface::ACCESS_GRANTED
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
];
|
||||
|
||||
yield [
|
||||
$this->buildToken(StoredObjectRoleEnum::EDIT, $so = new StoredObject()),
|
||||
$so,
|
||||
StoredObjectRoleEnum::EDIT->value,
|
||||
VoterInterface::ACCESS_GRANTED
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -79,7 +80,7 @@ class StoredObjectVoterTest extends TestCase
|
||||
$this->buildToken(StoredObjectRoleEnum::SEE, $so = new StoredObject()),
|
||||
$so,
|
||||
StoredObjectRoleEnum::SEE->value,
|
||||
VoterInterface::ACCESS_GRANTED
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -97,8 +98,7 @@ class StoredObjectVoterTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function buildToken(?StoredObjectRoleEnum $storedObjectRoleEnum = null, ?StoredObject $storedObject = null): TokenInterface
|
||||
private function buildToken(StoredObjectRoleEnum $storedObjectRoleEnum = null, StoredObject $storedObject = null): TokenInterface
|
||||
{
|
||||
$token = $this->prophesize(TokenInterface::class);
|
||||
|
||||
@@ -110,7 +110,6 @@ class StoredObjectVoterTest extends TestCase
|
||||
$token->getAttribute(DavTokenAuthenticationEventSubscriber::ACTIONS)->willThrow(new \InvalidArgumentException());
|
||||
}
|
||||
|
||||
|
||||
if (null !== $storedObject) {
|
||||
$token->hasAttribute(DavTokenAuthenticationEventSubscriber::STORED_OBJECT)->willReturn(true);
|
||||
$token->getAttribute(DavTokenAuthenticationEventSubscriber::STORED_OBJECT)->willReturn($storedObject->getUuid()->toString());
|
||||
|
@@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class DavOnUrlTokenExtractorTest extends TestCase
|
||||
@@ -28,7 +29,7 @@ class DavOnUrlTokenExtractorTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideDataUri
|
||||
*/
|
||||
public function testExtract(string $uri, string|false $expected): void
|
||||
public function testExtract(string $uri, false|string $expected): void
|
||||
{
|
||||
$request = $this->prophesize(Request::class);
|
||||
$request->getRequestUri()->willReturn($uri);
|
||||
|
Reference in New Issue
Block a user