-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorageServerTest.php
More file actions
128 lines (108 loc) · 5.01 KB
/
StorageServerTest.php
File metadata and controls
128 lines (108 loc) · 5.01 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace Pdsinterop\PhpSolid;
require_once(__DIR__ . "/test-config.php");
use Pdsinterop\PhpSolid\StorageServer;
class StorageServerTest extends \PHPUnit\Framework\TestCase
{
public static $headers = [];
public static $createdUser;
protected function setUp(): void
{
$statements = [
'DROP TABLE IF EXISTS allowedClients',
'DROP TABLE IF EXISTS userStorage',
'DROP TABLE IF EXISTS users',
'CREATE TABLE IF NOT EXISTS allowedClients (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
clientId VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS userStorage (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
storageUrl VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS users (
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
email TEXT NOT NULL,
password TEXT NOT NULL,
data TEXT
)',
];
Db::connect();
try {
// create tables
foreach($statements as $statement){
Db::$pdo->exec($statement);
}
} catch(\PDOException $e) {
echo $e->getMessage();
}
$newUser = [
"password" => "hello123!@#ABC",
"email" => "alice@example.com",
"hello" => "world"
];
self::$createdUser = User::createUser($newUser);
$_SERVER['REQUEST_URI'] = "/test/";
$_SERVER['REQUEST_SCHEME'] = "https";
$_SERVER['SERVER_NAME'] = "storage-" . self::$createdUser['userId'] . ".example.com";
}
public function testGetFileSystem() {
$filesystem = StorageServer::getFileSystem();
$this->assertInstanceOf('\League\Flysystem\Filesystem', $filesystem);
}
public function testRespond() {
$response = new MockResponse();
ob_start();
StorageServer::respond($response);
$sentBody = ob_get_contents();
ob_end_clean();
$this->assertTrue(in_array("HTTP/1.1 200", StorageServerTest::$headers));
$this->assertTrue(in_array("Foo:Bar", StorageServerTest::$headers));
$this->assertTrue(in_array("Foo:Blah", StorageServerTest::$headers));
$this->assertEquals($sentBody, "{\"Hello\":\"world\"}");
}
public function testGetOwner() {
$owner = StorageServer::getOwner();
$this->assertEquals(self::$createdUser['webId'], $owner['webId']);
$this->assertEquals(self::$createdUser['email'], $owner['email']);
}
public function testGetOwnerWebId() {
$webId = StorageServer::getOwnerWebId();
$this->assertEquals(self::$createdUser['webId'], $webId);
}
public function testGenerateDefaultAcl() {
$defaultAcl = StorageServer::generateDefaultAcl();
$this->assertTrue(strpos($defaultAcl, self::$createdUser['webId']) > 0);
$this->assertMatchesRegularExpression("/@prefix/", $defaultAcl);
}
public function testGeneratePublicAppendAcl() {
$publicAppendAcl = StorageServer::generatePublicAppendAcl();
$this->assertTrue(strpos($publicAppendAcl, self::$createdUser['webId']) > 0);
$this->assertMatchesRegularExpression("/@prefix/", $publicAppendAcl);
}
public function testGeneratePublicReadAcl() {
$publicReadAcl = StorageServer::generatePublicReadAcl();
$this->assertTrue(strpos($publicReadAcl, self::$createdUser['webId']) > 0);
$this->assertMatchesRegularExpression("/@prefix/", $publicReadAcl);
}
public function testGenerateDefaultPrivateTypeIndex() {
$privateTypeIndex = StorageServer::generateDefaultPrivateTypeIndex();
$this->assertTrue(strpos($privateTypeIndex, "UnlistedDocument") > 0);
$this->assertMatchesRegularExpression("/@prefix/", $privateTypeIndex);
}
public function testGenerateDefaultPublicTypeIndex() {
$publicTypeIndex = StorageServer::generateDefaultPublicTypeIndex();
$this->assertTrue(strpos($publicTypeIndex, "ListedDocument") > 0);
$this->assertMatchesRegularExpression("/@prefix/", $publicTypeIndex);
}
public function testGenerateDefaultPreferences() {
$preferences = StorageServer::generateDefaultPreferences();
$this->assertTrue(strpos($preferences, "ConfigurationFile") > 0);
$this->assertMatchesRegularExpression("/@prefix/", $preferences);
}
/*
Currently untested:
public static function getWebId($rawRequest) {
public static function initializeStorage() {
*/
}