-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathResourceMetadataTest.php
More file actions
68 lines (56 loc) · 2.42 KB
/
ResourceMetadataTest.php
File metadata and controls
68 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* This file is part of the Solid Client PHP project.
* (c) Kévin Dunglas <kevin@dunglas.fr>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Dunglas\PhpSolidClient\Tests;
use Dunglas\PhpSolidClient\ResourceMetadata;
use PHPUnit\Framework\TestCase;
class ResourceMetadataTest extends TestCase
{
public function testFromResponseHeaders(): void
{
$headers = [
'content-type' => ['text/turtle; charset=utf-8'],
'content-length' => ['4567'],
'last-modified' => ['Mon, 23 Feb 2026 12:00:00 GMT'],
'link' => [
'<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"',
'<http://pod.example/resource.acl>; rel="acl"',
],
'wac-allow' => ['user="read write append control",public="read"'],
];
$metadata = ResourceMetadata::fromResponseHeaders($headers);
$this->assertSame('text/turtle', $metadata->contentType);
$this->assertSame(4567, $metadata->contentLength);
$this->assertInstanceOf(\DateTimeImmutable::class, $metadata->lastModified);
$this->assertSame('http://www.w3.org/ns/ldp#BasicContainer', $metadata->ldpType);
$this->assertTrue($metadata->isContainer());
$this->assertSame('http://pod.example/resource.acl', $metadata->aclUrl);
$this->assertSame(['read', 'write', 'append', 'control'], $metadata->wacAllow['user']);
$this->assertSame(['read'], $metadata->wacAllow['public']);
}
public function testResourceNotContainer(): void
{
$headers = [
'content-type' => ['application/ld+json'],
'link' => ['<http://www.w3.org/ns/ldp#Resource>; rel="type"'],
];
$metadata = ResourceMetadata::fromResponseHeaders($headers);
$this->assertFalse($metadata->isContainer());
$this->assertSame('http://www.w3.org/ns/ldp#Resource', $metadata->ldpType);
}
public function testEmptyHeaders(): void
{
$metadata = ResourceMetadata::fromResponseHeaders([]);
$this->assertNull($metadata->contentType);
$this->assertNull($metadata->contentLength);
$this->assertNull($metadata->lastModified);
$this->assertNull($metadata->ldpType);
$this->assertNull($metadata->aclUrl);
$this->assertSame([], $metadata->wacAllow);
}
}