-
Notifications
You must be signed in to change notification settings - Fork 31
/
FileStoreTest.php
52 lines (45 loc) · 1.89 KB
/
FileStoreTest.php
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
<?php
class FileStoreTest extends LocalWebTestCase
{
const AUTH_PASS = true;
const AUTH_FAIL = false;
private function setAuthenticationMock($response)
{
$auth = $this->getMock('\There4\Authentication\Cookie');
$auth->expects($this->any())->method('authenticate')->will($this->returnValue($response));
$this->app->authentication = function ($c) use ($auth) {
return $auth;
};
}
public function testAuthenticationFailureGets401()
{
$this->setAuthenticationMock(self::AUTH_FAIL);
$this->client->get('/files/sample.json');
$this->assertEquals(401, $this->client->response->status());
}
public function testCanDownloadFile()
{
$this->setAuthenticationMock(self::AUTH_PASS);
$expected = file_get_contents(__DIR__ . '/../../file_store/sample.json');
$this->client->get('/files/sample.json');
$this->assertEquals(200, $this->client->response->status());
$this->assertEquals('application/json', $this->client->response['Content-Type']);
$this->assertEquals($expected, $this->client->response->body());
}
public function testMissingFileGets404()
{
$this->setAuthenticationMock(self::AUTH_PASS);
$this->client->get('/files/four04.json');
$this->assertEquals(404, $this->client->response->status());
}
public function testUnknownFileTypeGetsCorectHeader()
{
$this->setAuthenticationMock(self::AUTH_PASS);
$expected = file_get_contents(__DIR__ . '/../../file_store/unknownfile.type');
$this->client->get('/files/unknownfile.type');
$this->assertEquals(200, $this->client->response->status());
$this->assertEquals('application/octet-stream', $this->client->response['Content-Type']);
$this->assertEquals($expected, $this->client->response->body());
}
}
/* End of file FileStoreTest.php */