Skip to content

Commit 0a83e44

Browse files
committed
Add more functional tests
1 parent 48c3b30 commit 0a83e44

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/Model/RDFSourceTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function testGetRDFSource()
5757
$this->assertTrue($response->headers->has("etag"), "Missing Etag header.");
5858
$etag = $response->headers->get('etag');
5959

60+
$size = filesize("./test/resources/test_directory/nobel_914.ttl");
61+
$this->assertTrue($response->headers->has("Content-Length"), "Missing Content-Length header");
62+
$this->assertEquals($size, $response->headers->get('Content-Length'), "Content-Length header incorrect");
63+
6064
$this->client->request('GET', "/nobel_914.ttl", [], [], ['HTTP_ACCEPT' => $expected_mime]);
6165
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed a second time.");
6266
$this->assertTrue($this->client->getResponse()->headers->has("etag"), "Missing Etag header.");
@@ -69,4 +73,46 @@ public function testGetRDFSource()
6973
$this->client->request('GET', "/nobel_914.ttl", [], [], $headers);
7074
$this->assertEquals(304, $this->client->getResponse()->getStatusCode(), "Conditional GET should return a 304");
7175
}
76+
77+
/**
78+
* Test GET a RDFSource as JSON-LD
79+
*/
80+
public function testGetRDFSourceJSON()
81+
{
82+
$expected_links = [
83+
"<" . Resource::LDP_NS . "Resource>; rel=\"type\"",
84+
"<" . Resource::LDP_NS . "RDFSource>; rel=\"type\""
85+
];
86+
$expected_vary = "Accept";
87+
$request_mime = "application/ld+json";
88+
89+
$this->client->request('GET', "/nobel_914.ttl", [], [], ['HTTP_ACCEPT' => $request_mime]);
90+
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed.");
91+
$response = $this->client->getResponse();
92+
$content = $response->getContent();
93+
94+
$this->assertTrue($response->headers->has('Link'), "Missing Link header");
95+
$this->assertEquals($expected_links, $response->headers->get("Link", null, false), "Link headers incorrect.");
96+
97+
$this->assertTrue($response->headers->has('Vary'), "Missing Vary header");
98+
$this->assertEquals($expected_vary, $response->headers->get('Vary'), "Vary headers incorrect.");
99+
100+
$this->assertTrue($response->headers->has("Content-Type"), "Missing Content-Type header");
101+
$this->assertEquals($request_mime, $response->headers->get('Content-Type'), "Content-Type header incorrect");
102+
103+
$this->assertTrue($response->headers->has("etag"), "Missing Etag header.");
104+
$etag = $response->headers->get('etag');
105+
106+
$this->client->request('GET', "/nobel_914.ttl", [], [], ['HTTP_ACCEPT' => $request_mime]);
107+
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "GET should be allowed a second time.");
108+
$this->assertTrue($this->client->getResponse()->headers->has("etag"), "Missing Etag header.");
109+
$this->assertEquals($etag, $this->client->getResponse()->headers->get('etag'), "Etags don't match.");
110+
111+
$headers = [
112+
'HTTP_ACCEPT' => $request_mime,
113+
'HTTP_IF_NONE_MATCH' => "{$etag}"
114+
];
115+
$this->client->request('GET', "/nobel_914.ttl", [], [], $headers);
116+
$this->assertEquals(304, $this->client->getResponse()->getStatusCode(), "Conditional GET should return a 304");
117+
}
72118
}

0 commit comments

Comments
 (0)