@@ -24,212 +24,212 @@ |
||
24 | 24 | * @package OC\Files\Cache |
25 | 25 | */ |
26 | 26 | class Storage { |
27 | - /** @var StorageGlobal|null */ |
|
28 | - private static $globalCache = null; |
|
29 | - private $storageId; |
|
30 | - private $numericId; |
|
31 | - |
|
32 | - /** |
|
33 | - * @return StorageGlobal |
|
34 | - */ |
|
35 | - public static function getGlobalCache() { |
|
36 | - if (is_null(self::$globalCache)) { |
|
37 | - self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection()); |
|
38 | - } |
|
39 | - return self::$globalCache; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param \OC\Files\Storage\Storage|string $storage |
|
44 | - * @param bool $isAvailable |
|
45 | - * @throws \RuntimeException |
|
46 | - */ |
|
47 | - public function __construct($storage, $isAvailable, IDBConnection $connection) { |
|
48 | - if ($storage instanceof IStorage) { |
|
49 | - $this->storageId = $storage->getId(); |
|
50 | - } else { |
|
51 | - $this->storageId = $storage; |
|
52 | - } |
|
53 | - $this->storageId = self::adjustStorageId($this->storageId); |
|
54 | - |
|
55 | - if ($row = self::getStorageById($this->storageId)) { |
|
56 | - $this->numericId = (int)$row['numeric_id']; |
|
57 | - } else { |
|
58 | - $available = $isAvailable ? 1 : 0; |
|
59 | - if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { |
|
60 | - $this->numericId = $connection->lastInsertId('*PREFIX*storages'); |
|
61 | - } else { |
|
62 | - if ($row = self::getStorageById($this->storageId)) { |
|
63 | - $this->numericId = (int)$row['numeric_id']; |
|
64 | - } else { |
|
65 | - throw new \RuntimeException('Storage could neither be inserted nor be selected from the database: ' . $this->storageId); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $storageId |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public static function getStorageById($storageId) { |
|
76 | - return self::getGlobalCache()->getStorageInfo($storageId); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Adjusts the storage id to use md5 if too long |
|
81 | - * @param string $storageId storage id |
|
82 | - * @return string unchanged $storageId if its length is less than 64 characters, |
|
83 | - * else returns the md5 of $storageId |
|
84 | - */ |
|
85 | - public static function adjustStorageId($storageId) { |
|
86 | - if (strlen($storageId) > 64) { |
|
87 | - return md5($storageId); |
|
88 | - } |
|
89 | - return $storageId; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Get the numeric id for the storage |
|
94 | - * |
|
95 | - * @return int |
|
96 | - */ |
|
97 | - public function getNumericId() { |
|
98 | - return $this->numericId; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Get the string id for the storage |
|
103 | - * |
|
104 | - * @param int $numericId |
|
105 | - * @return string|null either the storage id string or null if the numeric id is not known |
|
106 | - */ |
|
107 | - public static function getStorageId(int $numericId): ?string { |
|
108 | - $storage = self::getGlobalCache()->getStorageInfoByNumericId($numericId); |
|
109 | - return $storage['id'] ?? null; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Get the numeric of the storage with the provided string id |
|
114 | - * |
|
115 | - * @param $storageId |
|
116 | - * @return int|null either the numeric storage id or null if the storage id is not known |
|
117 | - */ |
|
118 | - public static function getNumericStorageId($storageId) { |
|
119 | - $storageId = self::adjustStorageId($storageId); |
|
120 | - |
|
121 | - if ($row = self::getStorageById($storageId)) { |
|
122 | - return (int)$row['numeric_id']; |
|
123 | - } else { |
|
124 | - return null; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return array [ available, last_checked ] |
|
130 | - */ |
|
131 | - public function getAvailability() { |
|
132 | - if ($row = self::getStorageById($this->storageId)) { |
|
133 | - return [ |
|
134 | - 'available' => (int)$row['available'] === 1, |
|
135 | - 'last_checked' => $row['last_checked'] |
|
136 | - ]; |
|
137 | - } else { |
|
138 | - return [ |
|
139 | - 'available' => true, |
|
140 | - 'last_checked' => time(), |
|
141 | - ]; |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param bool $isAvailable |
|
147 | - * @param int $delay amount of seconds to delay reconsidering that storage further |
|
148 | - */ |
|
149 | - public function setAvailability($isAvailable, int $delay = 0) { |
|
150 | - $available = $isAvailable ? 1 : 0; |
|
151 | - if (!$isAvailable) { |
|
152 | - \OCP\Server::get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']); |
|
153 | - } |
|
154 | - |
|
155 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
156 | - $query->update('storages') |
|
157 | - ->set('available', $query->createNamedParameter($available)) |
|
158 | - ->set('last_checked', $query->createNamedParameter(time() + $delay)) |
|
159 | - ->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId))); |
|
160 | - $query->executeStatement(); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Check if a string storage id is known |
|
165 | - * |
|
166 | - * @param string $storageId |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public static function exists($storageId) { |
|
170 | - return !is_null(self::getNumericStorageId($storageId)); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * remove the entry for the storage |
|
175 | - * |
|
176 | - * @param string $storageId |
|
177 | - */ |
|
178 | - public static function remove($storageId) { |
|
179 | - $storageId = self::adjustStorageId($storageId); |
|
180 | - $numericId = self::getNumericStorageId($storageId); |
|
181 | - |
|
182 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
183 | - $query->delete('storages') |
|
184 | - ->where($query->expr()->eq('id', $query->createNamedParameter($storageId))); |
|
185 | - $query->executeStatement(); |
|
186 | - |
|
187 | - if (!is_null($numericId)) { |
|
188 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
189 | - $query->delete('filecache') |
|
190 | - ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId))); |
|
191 | - $query->executeStatement(); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * remove the entry for the storage by the mount id |
|
197 | - * |
|
198 | - * @param int $mountId |
|
199 | - */ |
|
200 | - public static function cleanByMountId(int $mountId) { |
|
201 | - $db = \OC::$server->getDatabaseConnection(); |
|
202 | - |
|
203 | - try { |
|
204 | - $db->beginTransaction(); |
|
205 | - |
|
206 | - $query = $db->getQueryBuilder(); |
|
207 | - $query->select('storage_id') |
|
208 | - ->from('mounts') |
|
209 | - ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
210 | - $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); |
|
211 | - $storageIds = array_unique($storageIds); |
|
212 | - |
|
213 | - $query = $db->getQueryBuilder(); |
|
214 | - $query->delete('filecache') |
|
215 | - ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
216 | - $query->runAcrossAllShards(); |
|
217 | - $query->executeStatement(); |
|
218 | - |
|
219 | - $query = $db->getQueryBuilder(); |
|
220 | - $query->delete('storages') |
|
221 | - ->where($query->expr()->in('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
222 | - $query->executeStatement(); |
|
223 | - |
|
224 | - $query = $db->getQueryBuilder(); |
|
225 | - $query->delete('mounts') |
|
226 | - ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
227 | - $query->executeStatement(); |
|
228 | - |
|
229 | - $db->commit(); |
|
230 | - } catch (\Exception $e) { |
|
231 | - $db->rollBack(); |
|
232 | - throw $e; |
|
233 | - } |
|
234 | - } |
|
27 | + /** @var StorageGlobal|null */ |
|
28 | + private static $globalCache = null; |
|
29 | + private $storageId; |
|
30 | + private $numericId; |
|
31 | + |
|
32 | + /** |
|
33 | + * @return StorageGlobal |
|
34 | + */ |
|
35 | + public static function getGlobalCache() { |
|
36 | + if (is_null(self::$globalCache)) { |
|
37 | + self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection()); |
|
38 | + } |
|
39 | + return self::$globalCache; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param \OC\Files\Storage\Storage|string $storage |
|
44 | + * @param bool $isAvailable |
|
45 | + * @throws \RuntimeException |
|
46 | + */ |
|
47 | + public function __construct($storage, $isAvailable, IDBConnection $connection) { |
|
48 | + if ($storage instanceof IStorage) { |
|
49 | + $this->storageId = $storage->getId(); |
|
50 | + } else { |
|
51 | + $this->storageId = $storage; |
|
52 | + } |
|
53 | + $this->storageId = self::adjustStorageId($this->storageId); |
|
54 | + |
|
55 | + if ($row = self::getStorageById($this->storageId)) { |
|
56 | + $this->numericId = (int)$row['numeric_id']; |
|
57 | + } else { |
|
58 | + $available = $isAvailable ? 1 : 0; |
|
59 | + if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { |
|
60 | + $this->numericId = $connection->lastInsertId('*PREFIX*storages'); |
|
61 | + } else { |
|
62 | + if ($row = self::getStorageById($this->storageId)) { |
|
63 | + $this->numericId = (int)$row['numeric_id']; |
|
64 | + } else { |
|
65 | + throw new \RuntimeException('Storage could neither be inserted nor be selected from the database: ' . $this->storageId); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $storageId |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public static function getStorageById($storageId) { |
|
76 | + return self::getGlobalCache()->getStorageInfo($storageId); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Adjusts the storage id to use md5 if too long |
|
81 | + * @param string $storageId storage id |
|
82 | + * @return string unchanged $storageId if its length is less than 64 characters, |
|
83 | + * else returns the md5 of $storageId |
|
84 | + */ |
|
85 | + public static function adjustStorageId($storageId) { |
|
86 | + if (strlen($storageId) > 64) { |
|
87 | + return md5($storageId); |
|
88 | + } |
|
89 | + return $storageId; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Get the numeric id for the storage |
|
94 | + * |
|
95 | + * @return int |
|
96 | + */ |
|
97 | + public function getNumericId() { |
|
98 | + return $this->numericId; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Get the string id for the storage |
|
103 | + * |
|
104 | + * @param int $numericId |
|
105 | + * @return string|null either the storage id string or null if the numeric id is not known |
|
106 | + */ |
|
107 | + public static function getStorageId(int $numericId): ?string { |
|
108 | + $storage = self::getGlobalCache()->getStorageInfoByNumericId($numericId); |
|
109 | + return $storage['id'] ?? null; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Get the numeric of the storage with the provided string id |
|
114 | + * |
|
115 | + * @param $storageId |
|
116 | + * @return int|null either the numeric storage id or null if the storage id is not known |
|
117 | + */ |
|
118 | + public static function getNumericStorageId($storageId) { |
|
119 | + $storageId = self::adjustStorageId($storageId); |
|
120 | + |
|
121 | + if ($row = self::getStorageById($storageId)) { |
|
122 | + return (int)$row['numeric_id']; |
|
123 | + } else { |
|
124 | + return null; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return array [ available, last_checked ] |
|
130 | + */ |
|
131 | + public function getAvailability() { |
|
132 | + if ($row = self::getStorageById($this->storageId)) { |
|
133 | + return [ |
|
134 | + 'available' => (int)$row['available'] === 1, |
|
135 | + 'last_checked' => $row['last_checked'] |
|
136 | + ]; |
|
137 | + } else { |
|
138 | + return [ |
|
139 | + 'available' => true, |
|
140 | + 'last_checked' => time(), |
|
141 | + ]; |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param bool $isAvailable |
|
147 | + * @param int $delay amount of seconds to delay reconsidering that storage further |
|
148 | + */ |
|
149 | + public function setAvailability($isAvailable, int $delay = 0) { |
|
150 | + $available = $isAvailable ? 1 : 0; |
|
151 | + if (!$isAvailable) { |
|
152 | + \OCP\Server::get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']); |
|
153 | + } |
|
154 | + |
|
155 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
156 | + $query->update('storages') |
|
157 | + ->set('available', $query->createNamedParameter($available)) |
|
158 | + ->set('last_checked', $query->createNamedParameter(time() + $delay)) |
|
159 | + ->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId))); |
|
160 | + $query->executeStatement(); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Check if a string storage id is known |
|
165 | + * |
|
166 | + * @param string $storageId |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public static function exists($storageId) { |
|
170 | + return !is_null(self::getNumericStorageId($storageId)); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * remove the entry for the storage |
|
175 | + * |
|
176 | + * @param string $storageId |
|
177 | + */ |
|
178 | + public static function remove($storageId) { |
|
179 | + $storageId = self::adjustStorageId($storageId); |
|
180 | + $numericId = self::getNumericStorageId($storageId); |
|
181 | + |
|
182 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
183 | + $query->delete('storages') |
|
184 | + ->where($query->expr()->eq('id', $query->createNamedParameter($storageId))); |
|
185 | + $query->executeStatement(); |
|
186 | + |
|
187 | + if (!is_null($numericId)) { |
|
188 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
189 | + $query->delete('filecache') |
|
190 | + ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId))); |
|
191 | + $query->executeStatement(); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * remove the entry for the storage by the mount id |
|
197 | + * |
|
198 | + * @param int $mountId |
|
199 | + */ |
|
200 | + public static function cleanByMountId(int $mountId) { |
|
201 | + $db = \OC::$server->getDatabaseConnection(); |
|
202 | + |
|
203 | + try { |
|
204 | + $db->beginTransaction(); |
|
205 | + |
|
206 | + $query = $db->getQueryBuilder(); |
|
207 | + $query->select('storage_id') |
|
208 | + ->from('mounts') |
|
209 | + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
210 | + $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); |
|
211 | + $storageIds = array_unique($storageIds); |
|
212 | + |
|
213 | + $query = $db->getQueryBuilder(); |
|
214 | + $query->delete('filecache') |
|
215 | + ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
216 | + $query->runAcrossAllShards(); |
|
217 | + $query->executeStatement(); |
|
218 | + |
|
219 | + $query = $db->getQueryBuilder(); |
|
220 | + $query->delete('storages') |
|
221 | + ->where($query->expr()->in('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
222 | + $query->executeStatement(); |
|
223 | + |
|
224 | + $query = $db->getQueryBuilder(); |
|
225 | + $query->delete('mounts') |
|
226 | + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
227 | + $query->executeStatement(); |
|
228 | + |
|
229 | + $db->commit(); |
|
230 | + } catch (\Exception $e) { |
|
231 | + $db->rollBack(); |
|
232 | + throw $e; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | } |
@@ -17,596 +17,596 @@ |
||
17 | 17 | * @group DB |
18 | 18 | */ |
19 | 19 | class GlobalStoragesServiceTest extends StoragesServiceTestCase { |
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); |
|
23 | - } |
|
24 | - |
|
25 | - protected function tearDown(): void { |
|
26 | - @unlink($this->dataDir . '/mount.json'); |
|
27 | - parent::tearDown(); |
|
28 | - } |
|
29 | - |
|
30 | - protected function makeTestStorageData() { |
|
31 | - return $this->makeStorageConfig([ |
|
32 | - 'mountPoint' => 'mountpoint', |
|
33 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
34 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
35 | - 'backendOptions' => [ |
|
36 | - 'option1' => 'value1', |
|
37 | - 'option2' => 'value2', |
|
38 | - 'password' => 'testPassword', |
|
39 | - ], |
|
40 | - 'applicableUsers' => [], |
|
41 | - 'applicableGroups' => [], |
|
42 | - 'priority' => 15, |
|
43 | - 'mountOptions' => [ |
|
44 | - 'preview' => false, |
|
45 | - ] |
|
46 | - ]); |
|
47 | - } |
|
48 | - |
|
49 | - public static function storageDataProvider(): array { |
|
50 | - return [ |
|
51 | - // all users |
|
52 | - [ |
|
53 | - [ |
|
54 | - 'mountPoint' => 'mountpoint', |
|
55 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
56 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
57 | - 'backendOptions' => [ |
|
58 | - 'option1' => 'value1', |
|
59 | - 'option2' => 'value2', |
|
60 | - 'password' => 'testPassword', |
|
61 | - ], |
|
62 | - 'applicableUsers' => [], |
|
63 | - 'applicableGroups' => [], |
|
64 | - 'priority' => 15, |
|
65 | - ], |
|
66 | - ], |
|
67 | - // some users |
|
68 | - [ |
|
69 | - [ |
|
70 | - 'mountPoint' => 'mountpoint', |
|
71 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
72 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
73 | - 'backendOptions' => [ |
|
74 | - 'option1' => 'value1', |
|
75 | - 'option2' => 'value2', |
|
76 | - 'password' => 'testPassword', |
|
77 | - ], |
|
78 | - 'applicableUsers' => ['user1', 'user2'], |
|
79 | - 'applicableGroups' => [], |
|
80 | - 'priority' => 15, |
|
81 | - ], |
|
82 | - ], |
|
83 | - // some groups |
|
84 | - [ |
|
85 | - [ |
|
86 | - 'mountPoint' => 'mountpoint', |
|
87 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
88 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
89 | - 'backendOptions' => [ |
|
90 | - 'option1' => 'value1', |
|
91 | - 'option2' => 'value2', |
|
92 | - 'password' => 'testPassword', |
|
93 | - ], |
|
94 | - 'applicableUsers' => [], |
|
95 | - 'applicableGroups' => ['group1', 'group2'], |
|
96 | - 'priority' => 15, |
|
97 | - ], |
|
98 | - ], |
|
99 | - // both users and groups |
|
100 | - [ |
|
101 | - [ |
|
102 | - 'mountPoint' => 'mountpoint', |
|
103 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
104 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
105 | - 'backendOptions' => [ |
|
106 | - 'option1' => 'value1', |
|
107 | - 'option2' => 'value2', |
|
108 | - 'password' => 'testPassword', |
|
109 | - ], |
|
110 | - 'applicableUsers' => ['user1', 'user2'], |
|
111 | - 'applicableGroups' => ['group1', 'group2'], |
|
112 | - 'priority' => 15, |
|
113 | - ], |
|
114 | - ], |
|
115 | - ]; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @dataProvider storageDataProvider |
|
120 | - */ |
|
121 | - public function testAddStorage($storageParams): void { |
|
122 | - $storage = $this->makeStorageConfig($storageParams); |
|
123 | - $newStorage = $this->service->addStorage($storage); |
|
124 | - |
|
125 | - $baseId = $newStorage->getId(); |
|
126 | - |
|
127 | - $newStorage = $this->service->getStorage($baseId); |
|
128 | - |
|
129 | - $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint()); |
|
130 | - $this->assertEquals($storage->getBackend(), $newStorage->getBackend()); |
|
131 | - $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism()); |
|
132 | - $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions()); |
|
133 | - $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
134 | - $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
135 | - $this->assertEquals($storage->getPriority(), $newStorage->getPriority()); |
|
136 | - $this->assertEquals(0, $newStorage->getStatus()); |
|
137 | - |
|
138 | - $nextStorage = $this->service->addStorage($storage); |
|
139 | - $this->assertEquals($baseId + 1, $nextStorage->getId()); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @dataProvider storageDataProvider |
|
144 | - */ |
|
145 | - public function testUpdateStorage($updatedStorageParams): void { |
|
146 | - $updatedStorage = $this->makeStorageConfig($updatedStorageParams); |
|
147 | - $storage = $this->makeStorageConfig([ |
|
148 | - 'mountPoint' => 'mountpoint', |
|
149 | - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
150 | - 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
151 | - 'backendOptions' => [ |
|
152 | - 'option1' => 'value1', |
|
153 | - 'option2' => 'value2', |
|
154 | - 'password' => 'testPassword', |
|
155 | - ], |
|
156 | - 'applicableUsers' => [], |
|
157 | - 'applicableGroups' => [], |
|
158 | - 'priority' => 15, |
|
159 | - ]); |
|
160 | - |
|
161 | - $newStorage = $this->service->addStorage($storage); |
|
162 | - $id = $newStorage->getId(); |
|
163 | - |
|
164 | - $updatedStorage->setId($id); |
|
165 | - |
|
166 | - $this->service->updateStorage($updatedStorage); |
|
167 | - $newStorage = $this->service->getStorage($id); |
|
168 | - |
|
169 | - $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint()); |
|
170 | - $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']); |
|
171 | - $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
172 | - $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
173 | - $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority()); |
|
174 | - $this->assertEquals(0, $newStorage->getStatus()); |
|
175 | - } |
|
176 | - |
|
177 | - public static function hooksAddStorageDataProvider(): array { |
|
178 | - return [ |
|
179 | - // applicable all |
|
180 | - [ |
|
181 | - [], |
|
182 | - [], |
|
183 | - // expected hook calls |
|
184 | - [ |
|
185 | - [ |
|
186 | - Filesystem::signal_create_mount, |
|
187 | - MountConfig::MOUNT_TYPE_USER, |
|
188 | - 'all' |
|
189 | - ], |
|
190 | - ], |
|
191 | - ], |
|
192 | - // single user |
|
193 | - [ |
|
194 | - ['user1'], |
|
195 | - [], |
|
196 | - // expected hook calls |
|
197 | - [ |
|
198 | - [ |
|
199 | - Filesystem::signal_create_mount, |
|
200 | - MountConfig::MOUNT_TYPE_USER, |
|
201 | - 'user1', |
|
202 | - ], |
|
203 | - ], |
|
204 | - ], |
|
205 | - // single group |
|
206 | - [ |
|
207 | - [], |
|
208 | - ['group1'], |
|
209 | - // expected hook calls |
|
210 | - [ |
|
211 | - [ |
|
212 | - Filesystem::signal_create_mount, |
|
213 | - MountConfig::MOUNT_TYPE_GROUP, |
|
214 | - 'group1', |
|
215 | - ], |
|
216 | - ], |
|
217 | - ], |
|
218 | - // multiple users |
|
219 | - [ |
|
220 | - ['user1', 'user2'], |
|
221 | - [], |
|
222 | - [ |
|
223 | - [ |
|
224 | - Filesystem::signal_create_mount, |
|
225 | - MountConfig::MOUNT_TYPE_USER, |
|
226 | - 'user1', |
|
227 | - ], |
|
228 | - [ |
|
229 | - Filesystem::signal_create_mount, |
|
230 | - MountConfig::MOUNT_TYPE_USER, |
|
231 | - 'user2', |
|
232 | - ], |
|
233 | - ], |
|
234 | - ], |
|
235 | - // multiple groups |
|
236 | - [ |
|
237 | - [], |
|
238 | - ['group1', 'group2'], |
|
239 | - // expected hook calls |
|
240 | - [ |
|
241 | - [ |
|
242 | - Filesystem::signal_create_mount, |
|
243 | - MountConfig::MOUNT_TYPE_GROUP, |
|
244 | - 'group1' |
|
245 | - ], |
|
246 | - [ |
|
247 | - Filesystem::signal_create_mount, |
|
248 | - MountConfig::MOUNT_TYPE_GROUP, |
|
249 | - 'group2' |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - // mixed groups and users |
|
254 | - [ |
|
255 | - ['user1', 'user2'], |
|
256 | - ['group1', 'group2'], |
|
257 | - // expected hook calls |
|
258 | - [ |
|
259 | - [ |
|
260 | - Filesystem::signal_create_mount, |
|
261 | - MountConfig::MOUNT_TYPE_USER, |
|
262 | - 'user1', |
|
263 | - ], |
|
264 | - [ |
|
265 | - Filesystem::signal_create_mount, |
|
266 | - MountConfig::MOUNT_TYPE_USER, |
|
267 | - 'user2', |
|
268 | - ], |
|
269 | - [ |
|
270 | - Filesystem::signal_create_mount, |
|
271 | - MountConfig::MOUNT_TYPE_GROUP, |
|
272 | - 'group1' |
|
273 | - ], |
|
274 | - [ |
|
275 | - Filesystem::signal_create_mount, |
|
276 | - MountConfig::MOUNT_TYPE_GROUP, |
|
277 | - 'group2' |
|
278 | - ], |
|
279 | - ], |
|
280 | - ], |
|
281 | - ]; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @dataProvider hooksAddStorageDataProvider |
|
286 | - */ |
|
287 | - public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void { |
|
288 | - $storage = $this->makeTestStorageData(); |
|
289 | - $storage->setApplicableUsers($applicableUsers); |
|
290 | - $storage->setApplicableGroups($applicableGroups); |
|
291 | - $this->service->addStorage($storage); |
|
292 | - |
|
293 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
294 | - |
|
295 | - foreach ($expectedCalls as $index => $call) { |
|
296 | - $this->assertHookCall( |
|
297 | - self::$hookCalls[$index], |
|
298 | - $call[0], |
|
299 | - $storage->getMountPoint(), |
|
300 | - $call[1], |
|
301 | - $call[2] |
|
302 | - ); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - public static function hooksUpdateStorageDataProvider(): array { |
|
307 | - return [ |
|
308 | - [ |
|
309 | - // nothing to multiple users and groups |
|
310 | - [], |
|
311 | - [], |
|
312 | - ['user1', 'user2'], |
|
313 | - ['group1', 'group2'], |
|
314 | - // expected hook calls |
|
315 | - [ |
|
316 | - // delete the "all entry" |
|
317 | - [ |
|
318 | - Filesystem::signal_delete_mount, |
|
319 | - MountConfig::MOUNT_TYPE_USER, |
|
320 | - 'all', |
|
321 | - ], |
|
322 | - [ |
|
323 | - Filesystem::signal_create_mount, |
|
324 | - MountConfig::MOUNT_TYPE_USER, |
|
325 | - 'user1', |
|
326 | - ], |
|
327 | - [ |
|
328 | - Filesystem::signal_create_mount, |
|
329 | - MountConfig::MOUNT_TYPE_USER, |
|
330 | - 'user2', |
|
331 | - ], |
|
332 | - [ |
|
333 | - Filesystem::signal_create_mount, |
|
334 | - MountConfig::MOUNT_TYPE_GROUP, |
|
335 | - 'group1' |
|
336 | - ], |
|
337 | - [ |
|
338 | - Filesystem::signal_create_mount, |
|
339 | - MountConfig::MOUNT_TYPE_GROUP, |
|
340 | - 'group2' |
|
341 | - ], |
|
342 | - ], |
|
343 | - ], |
|
344 | - [ |
|
345 | - // adding a user and a group |
|
346 | - ['user1'], |
|
347 | - ['group1'], |
|
348 | - ['user1', 'user2'], |
|
349 | - ['group1', 'group2'], |
|
350 | - // expected hook calls |
|
351 | - [ |
|
352 | - [ |
|
353 | - Filesystem::signal_create_mount, |
|
354 | - MountConfig::MOUNT_TYPE_USER, |
|
355 | - 'user2', |
|
356 | - ], |
|
357 | - [ |
|
358 | - Filesystem::signal_create_mount, |
|
359 | - MountConfig::MOUNT_TYPE_GROUP, |
|
360 | - 'group2' |
|
361 | - ], |
|
362 | - ], |
|
363 | - ], |
|
364 | - [ |
|
365 | - // removing a user and a group |
|
366 | - ['user1', 'user2'], |
|
367 | - ['group1', 'group2'], |
|
368 | - ['user1'], |
|
369 | - ['group1'], |
|
370 | - // expected hook calls |
|
371 | - [ |
|
372 | - [ |
|
373 | - Filesystem::signal_delete_mount, |
|
374 | - MountConfig::MOUNT_TYPE_USER, |
|
375 | - 'user2', |
|
376 | - ], |
|
377 | - [ |
|
378 | - Filesystem::signal_delete_mount, |
|
379 | - MountConfig::MOUNT_TYPE_GROUP, |
|
380 | - 'group2' |
|
381 | - ], |
|
382 | - ], |
|
383 | - ], |
|
384 | - [ |
|
385 | - // removing all |
|
386 | - ['user1'], |
|
387 | - ['group1'], |
|
388 | - [], |
|
389 | - [], |
|
390 | - // expected hook calls |
|
391 | - [ |
|
392 | - [ |
|
393 | - Filesystem::signal_delete_mount, |
|
394 | - MountConfig::MOUNT_TYPE_USER, |
|
395 | - 'user1', |
|
396 | - ], |
|
397 | - [ |
|
398 | - Filesystem::signal_delete_mount, |
|
399 | - MountConfig::MOUNT_TYPE_GROUP, |
|
400 | - 'group1' |
|
401 | - ], |
|
402 | - // create the "all" entry |
|
403 | - [ |
|
404 | - Filesystem::signal_create_mount, |
|
405 | - MountConfig::MOUNT_TYPE_USER, |
|
406 | - 'all' |
|
407 | - ], |
|
408 | - ], |
|
409 | - ], |
|
410 | - [ |
|
411 | - // no changes |
|
412 | - ['user1'], |
|
413 | - ['group1'], |
|
414 | - ['user1'], |
|
415 | - ['group1'], |
|
416 | - // no hook calls |
|
417 | - [] |
|
418 | - ] |
|
419 | - ]; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * @dataProvider hooksUpdateStorageDataProvider |
|
424 | - */ |
|
425 | - public function testHooksUpdateStorage( |
|
426 | - array $sourceApplicableUsers, |
|
427 | - array $sourceApplicableGroups, |
|
428 | - array $updatedApplicableUsers, |
|
429 | - array $updatedApplicableGroups, |
|
430 | - array $expectedCalls, |
|
431 | - ): void { |
|
432 | - $storage = $this->makeTestStorageData(); |
|
433 | - $storage->setApplicableUsers($sourceApplicableUsers); |
|
434 | - $storage->setApplicableGroups($sourceApplicableGroups); |
|
435 | - $storage = $this->service->addStorage($storage); |
|
436 | - |
|
437 | - $storage->setApplicableUsers($updatedApplicableUsers); |
|
438 | - $storage->setApplicableGroups($updatedApplicableGroups); |
|
439 | - |
|
440 | - // reset calls |
|
441 | - self::$hookCalls = []; |
|
442 | - |
|
443 | - $this->service->updateStorage($storage); |
|
444 | - |
|
445 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
446 | - |
|
447 | - foreach ($expectedCalls as $index => $call) { |
|
448 | - $this->assertHookCall( |
|
449 | - self::$hookCalls[$index], |
|
450 | - $call[0], |
|
451 | - '/mountpoint', |
|
452 | - $call[1], |
|
453 | - $call[2] |
|
454 | - ); |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - public function testHooksRenameMountPoint(): void { |
|
460 | - $storage = $this->makeTestStorageData(); |
|
461 | - $storage->setApplicableUsers(['user1', 'user2']); |
|
462 | - $storage->setApplicableGroups(['group1', 'group2']); |
|
463 | - $storage = $this->service->addStorage($storage); |
|
464 | - |
|
465 | - $storage->setMountPoint('renamedMountpoint'); |
|
466 | - |
|
467 | - // reset calls |
|
468 | - self::$hookCalls = []; |
|
469 | - |
|
470 | - $this->service->updateStorage($storage); |
|
471 | - |
|
472 | - $expectedCalls = [ |
|
473 | - // deletes old mount |
|
474 | - [ |
|
475 | - Filesystem::signal_delete_mount, |
|
476 | - '/mountpoint', |
|
477 | - MountConfig::MOUNT_TYPE_USER, |
|
478 | - 'user1', |
|
479 | - ], |
|
480 | - [ |
|
481 | - Filesystem::signal_delete_mount, |
|
482 | - '/mountpoint', |
|
483 | - MountConfig::MOUNT_TYPE_USER, |
|
484 | - 'user2', |
|
485 | - ], |
|
486 | - [ |
|
487 | - Filesystem::signal_delete_mount, |
|
488 | - '/mountpoint', |
|
489 | - MountConfig::MOUNT_TYPE_GROUP, |
|
490 | - 'group1', |
|
491 | - ], |
|
492 | - [ |
|
493 | - Filesystem::signal_delete_mount, |
|
494 | - '/mountpoint', |
|
495 | - MountConfig::MOUNT_TYPE_GROUP, |
|
496 | - 'group2', |
|
497 | - ], |
|
498 | - // creates new one |
|
499 | - [ |
|
500 | - Filesystem::signal_create_mount, |
|
501 | - '/renamedMountpoint', |
|
502 | - MountConfig::MOUNT_TYPE_USER, |
|
503 | - 'user1', |
|
504 | - ], |
|
505 | - [ |
|
506 | - Filesystem::signal_create_mount, |
|
507 | - '/renamedMountpoint', |
|
508 | - MountConfig::MOUNT_TYPE_USER, |
|
509 | - 'user2', |
|
510 | - ], |
|
511 | - [ |
|
512 | - Filesystem::signal_create_mount, |
|
513 | - '/renamedMountpoint', |
|
514 | - MountConfig::MOUNT_TYPE_GROUP, |
|
515 | - 'group1', |
|
516 | - ], |
|
517 | - [ |
|
518 | - Filesystem::signal_create_mount, |
|
519 | - '/renamedMountpoint', |
|
520 | - MountConfig::MOUNT_TYPE_GROUP, |
|
521 | - 'group2', |
|
522 | - ], |
|
523 | - ]; |
|
524 | - |
|
525 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
526 | - |
|
527 | - foreach ($expectedCalls as $index => $call) { |
|
528 | - $this->assertHookCall( |
|
529 | - self::$hookCalls[$index], |
|
530 | - $call[0], |
|
531 | - $call[1], |
|
532 | - $call[2], |
|
533 | - $call[3] |
|
534 | - ); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - public static function hooksDeleteStorageDataProvider(): array { |
|
539 | - return [ |
|
540 | - [ |
|
541 | - ['user1', 'user2'], |
|
542 | - ['group1', 'group2'], |
|
543 | - // expected hook calls |
|
544 | - [ |
|
545 | - [ |
|
546 | - Filesystem::signal_delete_mount, |
|
547 | - MountConfig::MOUNT_TYPE_USER, |
|
548 | - 'user1', |
|
549 | - ], |
|
550 | - [ |
|
551 | - Filesystem::signal_delete_mount, |
|
552 | - MountConfig::MOUNT_TYPE_USER, |
|
553 | - 'user2', |
|
554 | - ], |
|
555 | - [ |
|
556 | - Filesystem::signal_delete_mount, |
|
557 | - MountConfig::MOUNT_TYPE_GROUP, |
|
558 | - 'group1' |
|
559 | - ], |
|
560 | - [ |
|
561 | - Filesystem::signal_delete_mount, |
|
562 | - MountConfig::MOUNT_TYPE_GROUP, |
|
563 | - 'group2' |
|
564 | - ], |
|
565 | - ], |
|
566 | - ], |
|
567 | - [ |
|
568 | - // deleting "all" entry |
|
569 | - [], |
|
570 | - [], |
|
571 | - [ |
|
572 | - [ |
|
573 | - Filesystem::signal_delete_mount, |
|
574 | - MountConfig::MOUNT_TYPE_USER, |
|
575 | - 'all', |
|
576 | - ], |
|
577 | - ], |
|
578 | - ], |
|
579 | - ]; |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * @dataProvider hooksDeleteStorageDataProvider |
|
584 | - */ |
|
585 | - public function testHooksDeleteStorage( |
|
586 | - array $sourceApplicableUsers, |
|
587 | - array $sourceApplicableGroups, |
|
588 | - array $expectedCalls, |
|
589 | - ): void { |
|
590 | - $storage = $this->makeTestStorageData(); |
|
591 | - $storage->setApplicableUsers($sourceApplicableUsers); |
|
592 | - $storage->setApplicableGroups($sourceApplicableGroups); |
|
593 | - $storage = $this->service->addStorage($storage); |
|
594 | - |
|
595 | - // reset calls |
|
596 | - self::$hookCalls = []; |
|
597 | - |
|
598 | - $this->service->removeStorage($storage->getId()); |
|
599 | - |
|
600 | - $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
601 | - |
|
602 | - foreach ($expectedCalls as $index => $call) { |
|
603 | - $this->assertHookCall( |
|
604 | - self::$hookCalls[$index], |
|
605 | - $call[0], |
|
606 | - '/mountpoint', |
|
607 | - $call[1], |
|
608 | - $call[2] |
|
609 | - ); |
|
610 | - } |
|
611 | - } |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher); |
|
23 | + } |
|
24 | + |
|
25 | + protected function tearDown(): void { |
|
26 | + @unlink($this->dataDir . '/mount.json'); |
|
27 | + parent::tearDown(); |
|
28 | + } |
|
29 | + |
|
30 | + protected function makeTestStorageData() { |
|
31 | + return $this->makeStorageConfig([ |
|
32 | + 'mountPoint' => 'mountpoint', |
|
33 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
34 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
35 | + 'backendOptions' => [ |
|
36 | + 'option1' => 'value1', |
|
37 | + 'option2' => 'value2', |
|
38 | + 'password' => 'testPassword', |
|
39 | + ], |
|
40 | + 'applicableUsers' => [], |
|
41 | + 'applicableGroups' => [], |
|
42 | + 'priority' => 15, |
|
43 | + 'mountOptions' => [ |
|
44 | + 'preview' => false, |
|
45 | + ] |
|
46 | + ]); |
|
47 | + } |
|
48 | + |
|
49 | + public static function storageDataProvider(): array { |
|
50 | + return [ |
|
51 | + // all users |
|
52 | + [ |
|
53 | + [ |
|
54 | + 'mountPoint' => 'mountpoint', |
|
55 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
56 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
57 | + 'backendOptions' => [ |
|
58 | + 'option1' => 'value1', |
|
59 | + 'option2' => 'value2', |
|
60 | + 'password' => 'testPassword', |
|
61 | + ], |
|
62 | + 'applicableUsers' => [], |
|
63 | + 'applicableGroups' => [], |
|
64 | + 'priority' => 15, |
|
65 | + ], |
|
66 | + ], |
|
67 | + // some users |
|
68 | + [ |
|
69 | + [ |
|
70 | + 'mountPoint' => 'mountpoint', |
|
71 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
72 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
73 | + 'backendOptions' => [ |
|
74 | + 'option1' => 'value1', |
|
75 | + 'option2' => 'value2', |
|
76 | + 'password' => 'testPassword', |
|
77 | + ], |
|
78 | + 'applicableUsers' => ['user1', 'user2'], |
|
79 | + 'applicableGroups' => [], |
|
80 | + 'priority' => 15, |
|
81 | + ], |
|
82 | + ], |
|
83 | + // some groups |
|
84 | + [ |
|
85 | + [ |
|
86 | + 'mountPoint' => 'mountpoint', |
|
87 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
88 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
89 | + 'backendOptions' => [ |
|
90 | + 'option1' => 'value1', |
|
91 | + 'option2' => 'value2', |
|
92 | + 'password' => 'testPassword', |
|
93 | + ], |
|
94 | + 'applicableUsers' => [], |
|
95 | + 'applicableGroups' => ['group1', 'group2'], |
|
96 | + 'priority' => 15, |
|
97 | + ], |
|
98 | + ], |
|
99 | + // both users and groups |
|
100 | + [ |
|
101 | + [ |
|
102 | + 'mountPoint' => 'mountpoint', |
|
103 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
104 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
105 | + 'backendOptions' => [ |
|
106 | + 'option1' => 'value1', |
|
107 | + 'option2' => 'value2', |
|
108 | + 'password' => 'testPassword', |
|
109 | + ], |
|
110 | + 'applicableUsers' => ['user1', 'user2'], |
|
111 | + 'applicableGroups' => ['group1', 'group2'], |
|
112 | + 'priority' => 15, |
|
113 | + ], |
|
114 | + ], |
|
115 | + ]; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @dataProvider storageDataProvider |
|
120 | + */ |
|
121 | + public function testAddStorage($storageParams): void { |
|
122 | + $storage = $this->makeStorageConfig($storageParams); |
|
123 | + $newStorage = $this->service->addStorage($storage); |
|
124 | + |
|
125 | + $baseId = $newStorage->getId(); |
|
126 | + |
|
127 | + $newStorage = $this->service->getStorage($baseId); |
|
128 | + |
|
129 | + $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint()); |
|
130 | + $this->assertEquals($storage->getBackend(), $newStorage->getBackend()); |
|
131 | + $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism()); |
|
132 | + $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions()); |
|
133 | + $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
134 | + $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
135 | + $this->assertEquals($storage->getPriority(), $newStorage->getPriority()); |
|
136 | + $this->assertEquals(0, $newStorage->getStatus()); |
|
137 | + |
|
138 | + $nextStorage = $this->service->addStorage($storage); |
|
139 | + $this->assertEquals($baseId + 1, $nextStorage->getId()); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @dataProvider storageDataProvider |
|
144 | + */ |
|
145 | + public function testUpdateStorage($updatedStorageParams): void { |
|
146 | + $updatedStorage = $this->makeStorageConfig($updatedStorageParams); |
|
147 | + $storage = $this->makeStorageConfig([ |
|
148 | + 'mountPoint' => 'mountpoint', |
|
149 | + 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', |
|
150 | + 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', |
|
151 | + 'backendOptions' => [ |
|
152 | + 'option1' => 'value1', |
|
153 | + 'option2' => 'value2', |
|
154 | + 'password' => 'testPassword', |
|
155 | + ], |
|
156 | + 'applicableUsers' => [], |
|
157 | + 'applicableGroups' => [], |
|
158 | + 'priority' => 15, |
|
159 | + ]); |
|
160 | + |
|
161 | + $newStorage = $this->service->addStorage($storage); |
|
162 | + $id = $newStorage->getId(); |
|
163 | + |
|
164 | + $updatedStorage->setId($id); |
|
165 | + |
|
166 | + $this->service->updateStorage($updatedStorage); |
|
167 | + $newStorage = $this->service->getStorage($id); |
|
168 | + |
|
169 | + $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint()); |
|
170 | + $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']); |
|
171 | + $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
172 | + $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
173 | + $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority()); |
|
174 | + $this->assertEquals(0, $newStorage->getStatus()); |
|
175 | + } |
|
176 | + |
|
177 | + public static function hooksAddStorageDataProvider(): array { |
|
178 | + return [ |
|
179 | + // applicable all |
|
180 | + [ |
|
181 | + [], |
|
182 | + [], |
|
183 | + // expected hook calls |
|
184 | + [ |
|
185 | + [ |
|
186 | + Filesystem::signal_create_mount, |
|
187 | + MountConfig::MOUNT_TYPE_USER, |
|
188 | + 'all' |
|
189 | + ], |
|
190 | + ], |
|
191 | + ], |
|
192 | + // single user |
|
193 | + [ |
|
194 | + ['user1'], |
|
195 | + [], |
|
196 | + // expected hook calls |
|
197 | + [ |
|
198 | + [ |
|
199 | + Filesystem::signal_create_mount, |
|
200 | + MountConfig::MOUNT_TYPE_USER, |
|
201 | + 'user1', |
|
202 | + ], |
|
203 | + ], |
|
204 | + ], |
|
205 | + // single group |
|
206 | + [ |
|
207 | + [], |
|
208 | + ['group1'], |
|
209 | + // expected hook calls |
|
210 | + [ |
|
211 | + [ |
|
212 | + Filesystem::signal_create_mount, |
|
213 | + MountConfig::MOUNT_TYPE_GROUP, |
|
214 | + 'group1', |
|
215 | + ], |
|
216 | + ], |
|
217 | + ], |
|
218 | + // multiple users |
|
219 | + [ |
|
220 | + ['user1', 'user2'], |
|
221 | + [], |
|
222 | + [ |
|
223 | + [ |
|
224 | + Filesystem::signal_create_mount, |
|
225 | + MountConfig::MOUNT_TYPE_USER, |
|
226 | + 'user1', |
|
227 | + ], |
|
228 | + [ |
|
229 | + Filesystem::signal_create_mount, |
|
230 | + MountConfig::MOUNT_TYPE_USER, |
|
231 | + 'user2', |
|
232 | + ], |
|
233 | + ], |
|
234 | + ], |
|
235 | + // multiple groups |
|
236 | + [ |
|
237 | + [], |
|
238 | + ['group1', 'group2'], |
|
239 | + // expected hook calls |
|
240 | + [ |
|
241 | + [ |
|
242 | + Filesystem::signal_create_mount, |
|
243 | + MountConfig::MOUNT_TYPE_GROUP, |
|
244 | + 'group1' |
|
245 | + ], |
|
246 | + [ |
|
247 | + Filesystem::signal_create_mount, |
|
248 | + MountConfig::MOUNT_TYPE_GROUP, |
|
249 | + 'group2' |
|
250 | + ], |
|
251 | + ], |
|
252 | + ], |
|
253 | + // mixed groups and users |
|
254 | + [ |
|
255 | + ['user1', 'user2'], |
|
256 | + ['group1', 'group2'], |
|
257 | + // expected hook calls |
|
258 | + [ |
|
259 | + [ |
|
260 | + Filesystem::signal_create_mount, |
|
261 | + MountConfig::MOUNT_TYPE_USER, |
|
262 | + 'user1', |
|
263 | + ], |
|
264 | + [ |
|
265 | + Filesystem::signal_create_mount, |
|
266 | + MountConfig::MOUNT_TYPE_USER, |
|
267 | + 'user2', |
|
268 | + ], |
|
269 | + [ |
|
270 | + Filesystem::signal_create_mount, |
|
271 | + MountConfig::MOUNT_TYPE_GROUP, |
|
272 | + 'group1' |
|
273 | + ], |
|
274 | + [ |
|
275 | + Filesystem::signal_create_mount, |
|
276 | + MountConfig::MOUNT_TYPE_GROUP, |
|
277 | + 'group2' |
|
278 | + ], |
|
279 | + ], |
|
280 | + ], |
|
281 | + ]; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @dataProvider hooksAddStorageDataProvider |
|
286 | + */ |
|
287 | + public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void { |
|
288 | + $storage = $this->makeTestStorageData(); |
|
289 | + $storage->setApplicableUsers($applicableUsers); |
|
290 | + $storage->setApplicableGroups($applicableGroups); |
|
291 | + $this->service->addStorage($storage); |
|
292 | + |
|
293 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
294 | + |
|
295 | + foreach ($expectedCalls as $index => $call) { |
|
296 | + $this->assertHookCall( |
|
297 | + self::$hookCalls[$index], |
|
298 | + $call[0], |
|
299 | + $storage->getMountPoint(), |
|
300 | + $call[1], |
|
301 | + $call[2] |
|
302 | + ); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + public static function hooksUpdateStorageDataProvider(): array { |
|
307 | + return [ |
|
308 | + [ |
|
309 | + // nothing to multiple users and groups |
|
310 | + [], |
|
311 | + [], |
|
312 | + ['user1', 'user2'], |
|
313 | + ['group1', 'group2'], |
|
314 | + // expected hook calls |
|
315 | + [ |
|
316 | + // delete the "all entry" |
|
317 | + [ |
|
318 | + Filesystem::signal_delete_mount, |
|
319 | + MountConfig::MOUNT_TYPE_USER, |
|
320 | + 'all', |
|
321 | + ], |
|
322 | + [ |
|
323 | + Filesystem::signal_create_mount, |
|
324 | + MountConfig::MOUNT_TYPE_USER, |
|
325 | + 'user1', |
|
326 | + ], |
|
327 | + [ |
|
328 | + Filesystem::signal_create_mount, |
|
329 | + MountConfig::MOUNT_TYPE_USER, |
|
330 | + 'user2', |
|
331 | + ], |
|
332 | + [ |
|
333 | + Filesystem::signal_create_mount, |
|
334 | + MountConfig::MOUNT_TYPE_GROUP, |
|
335 | + 'group1' |
|
336 | + ], |
|
337 | + [ |
|
338 | + Filesystem::signal_create_mount, |
|
339 | + MountConfig::MOUNT_TYPE_GROUP, |
|
340 | + 'group2' |
|
341 | + ], |
|
342 | + ], |
|
343 | + ], |
|
344 | + [ |
|
345 | + // adding a user and a group |
|
346 | + ['user1'], |
|
347 | + ['group1'], |
|
348 | + ['user1', 'user2'], |
|
349 | + ['group1', 'group2'], |
|
350 | + // expected hook calls |
|
351 | + [ |
|
352 | + [ |
|
353 | + Filesystem::signal_create_mount, |
|
354 | + MountConfig::MOUNT_TYPE_USER, |
|
355 | + 'user2', |
|
356 | + ], |
|
357 | + [ |
|
358 | + Filesystem::signal_create_mount, |
|
359 | + MountConfig::MOUNT_TYPE_GROUP, |
|
360 | + 'group2' |
|
361 | + ], |
|
362 | + ], |
|
363 | + ], |
|
364 | + [ |
|
365 | + // removing a user and a group |
|
366 | + ['user1', 'user2'], |
|
367 | + ['group1', 'group2'], |
|
368 | + ['user1'], |
|
369 | + ['group1'], |
|
370 | + // expected hook calls |
|
371 | + [ |
|
372 | + [ |
|
373 | + Filesystem::signal_delete_mount, |
|
374 | + MountConfig::MOUNT_TYPE_USER, |
|
375 | + 'user2', |
|
376 | + ], |
|
377 | + [ |
|
378 | + Filesystem::signal_delete_mount, |
|
379 | + MountConfig::MOUNT_TYPE_GROUP, |
|
380 | + 'group2' |
|
381 | + ], |
|
382 | + ], |
|
383 | + ], |
|
384 | + [ |
|
385 | + // removing all |
|
386 | + ['user1'], |
|
387 | + ['group1'], |
|
388 | + [], |
|
389 | + [], |
|
390 | + // expected hook calls |
|
391 | + [ |
|
392 | + [ |
|
393 | + Filesystem::signal_delete_mount, |
|
394 | + MountConfig::MOUNT_TYPE_USER, |
|
395 | + 'user1', |
|
396 | + ], |
|
397 | + [ |
|
398 | + Filesystem::signal_delete_mount, |
|
399 | + MountConfig::MOUNT_TYPE_GROUP, |
|
400 | + 'group1' |
|
401 | + ], |
|
402 | + // create the "all" entry |
|
403 | + [ |
|
404 | + Filesystem::signal_create_mount, |
|
405 | + MountConfig::MOUNT_TYPE_USER, |
|
406 | + 'all' |
|
407 | + ], |
|
408 | + ], |
|
409 | + ], |
|
410 | + [ |
|
411 | + // no changes |
|
412 | + ['user1'], |
|
413 | + ['group1'], |
|
414 | + ['user1'], |
|
415 | + ['group1'], |
|
416 | + // no hook calls |
|
417 | + [] |
|
418 | + ] |
|
419 | + ]; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * @dataProvider hooksUpdateStorageDataProvider |
|
424 | + */ |
|
425 | + public function testHooksUpdateStorage( |
|
426 | + array $sourceApplicableUsers, |
|
427 | + array $sourceApplicableGroups, |
|
428 | + array $updatedApplicableUsers, |
|
429 | + array $updatedApplicableGroups, |
|
430 | + array $expectedCalls, |
|
431 | + ): void { |
|
432 | + $storage = $this->makeTestStorageData(); |
|
433 | + $storage->setApplicableUsers($sourceApplicableUsers); |
|
434 | + $storage->setApplicableGroups($sourceApplicableGroups); |
|
435 | + $storage = $this->service->addStorage($storage); |
|
436 | + |
|
437 | + $storage->setApplicableUsers($updatedApplicableUsers); |
|
438 | + $storage->setApplicableGroups($updatedApplicableGroups); |
|
439 | + |
|
440 | + // reset calls |
|
441 | + self::$hookCalls = []; |
|
442 | + |
|
443 | + $this->service->updateStorage($storage); |
|
444 | + |
|
445 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
446 | + |
|
447 | + foreach ($expectedCalls as $index => $call) { |
|
448 | + $this->assertHookCall( |
|
449 | + self::$hookCalls[$index], |
|
450 | + $call[0], |
|
451 | + '/mountpoint', |
|
452 | + $call[1], |
|
453 | + $call[2] |
|
454 | + ); |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + public function testHooksRenameMountPoint(): void { |
|
460 | + $storage = $this->makeTestStorageData(); |
|
461 | + $storage->setApplicableUsers(['user1', 'user2']); |
|
462 | + $storage->setApplicableGroups(['group1', 'group2']); |
|
463 | + $storage = $this->service->addStorage($storage); |
|
464 | + |
|
465 | + $storage->setMountPoint('renamedMountpoint'); |
|
466 | + |
|
467 | + // reset calls |
|
468 | + self::$hookCalls = []; |
|
469 | + |
|
470 | + $this->service->updateStorage($storage); |
|
471 | + |
|
472 | + $expectedCalls = [ |
|
473 | + // deletes old mount |
|
474 | + [ |
|
475 | + Filesystem::signal_delete_mount, |
|
476 | + '/mountpoint', |
|
477 | + MountConfig::MOUNT_TYPE_USER, |
|
478 | + 'user1', |
|
479 | + ], |
|
480 | + [ |
|
481 | + Filesystem::signal_delete_mount, |
|
482 | + '/mountpoint', |
|
483 | + MountConfig::MOUNT_TYPE_USER, |
|
484 | + 'user2', |
|
485 | + ], |
|
486 | + [ |
|
487 | + Filesystem::signal_delete_mount, |
|
488 | + '/mountpoint', |
|
489 | + MountConfig::MOUNT_TYPE_GROUP, |
|
490 | + 'group1', |
|
491 | + ], |
|
492 | + [ |
|
493 | + Filesystem::signal_delete_mount, |
|
494 | + '/mountpoint', |
|
495 | + MountConfig::MOUNT_TYPE_GROUP, |
|
496 | + 'group2', |
|
497 | + ], |
|
498 | + // creates new one |
|
499 | + [ |
|
500 | + Filesystem::signal_create_mount, |
|
501 | + '/renamedMountpoint', |
|
502 | + MountConfig::MOUNT_TYPE_USER, |
|
503 | + 'user1', |
|
504 | + ], |
|
505 | + [ |
|
506 | + Filesystem::signal_create_mount, |
|
507 | + '/renamedMountpoint', |
|
508 | + MountConfig::MOUNT_TYPE_USER, |
|
509 | + 'user2', |
|
510 | + ], |
|
511 | + [ |
|
512 | + Filesystem::signal_create_mount, |
|
513 | + '/renamedMountpoint', |
|
514 | + MountConfig::MOUNT_TYPE_GROUP, |
|
515 | + 'group1', |
|
516 | + ], |
|
517 | + [ |
|
518 | + Filesystem::signal_create_mount, |
|
519 | + '/renamedMountpoint', |
|
520 | + MountConfig::MOUNT_TYPE_GROUP, |
|
521 | + 'group2', |
|
522 | + ], |
|
523 | + ]; |
|
524 | + |
|
525 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
526 | + |
|
527 | + foreach ($expectedCalls as $index => $call) { |
|
528 | + $this->assertHookCall( |
|
529 | + self::$hookCalls[$index], |
|
530 | + $call[0], |
|
531 | + $call[1], |
|
532 | + $call[2], |
|
533 | + $call[3] |
|
534 | + ); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + public static function hooksDeleteStorageDataProvider(): array { |
|
539 | + return [ |
|
540 | + [ |
|
541 | + ['user1', 'user2'], |
|
542 | + ['group1', 'group2'], |
|
543 | + // expected hook calls |
|
544 | + [ |
|
545 | + [ |
|
546 | + Filesystem::signal_delete_mount, |
|
547 | + MountConfig::MOUNT_TYPE_USER, |
|
548 | + 'user1', |
|
549 | + ], |
|
550 | + [ |
|
551 | + Filesystem::signal_delete_mount, |
|
552 | + MountConfig::MOUNT_TYPE_USER, |
|
553 | + 'user2', |
|
554 | + ], |
|
555 | + [ |
|
556 | + Filesystem::signal_delete_mount, |
|
557 | + MountConfig::MOUNT_TYPE_GROUP, |
|
558 | + 'group1' |
|
559 | + ], |
|
560 | + [ |
|
561 | + Filesystem::signal_delete_mount, |
|
562 | + MountConfig::MOUNT_TYPE_GROUP, |
|
563 | + 'group2' |
|
564 | + ], |
|
565 | + ], |
|
566 | + ], |
|
567 | + [ |
|
568 | + // deleting "all" entry |
|
569 | + [], |
|
570 | + [], |
|
571 | + [ |
|
572 | + [ |
|
573 | + Filesystem::signal_delete_mount, |
|
574 | + MountConfig::MOUNT_TYPE_USER, |
|
575 | + 'all', |
|
576 | + ], |
|
577 | + ], |
|
578 | + ], |
|
579 | + ]; |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * @dataProvider hooksDeleteStorageDataProvider |
|
584 | + */ |
|
585 | + public function testHooksDeleteStorage( |
|
586 | + array $sourceApplicableUsers, |
|
587 | + array $sourceApplicableGroups, |
|
588 | + array $expectedCalls, |
|
589 | + ): void { |
|
590 | + $storage = $this->makeTestStorageData(); |
|
591 | + $storage->setApplicableUsers($sourceApplicableUsers); |
|
592 | + $storage->setApplicableGroups($sourceApplicableGroups); |
|
593 | + $storage = $this->service->addStorage($storage); |
|
594 | + |
|
595 | + // reset calls |
|
596 | + self::$hookCalls = []; |
|
597 | + |
|
598 | + $this->service->removeStorage($storage->getId()); |
|
599 | + |
|
600 | + $this->assertCount(count($expectedCalls), self::$hookCalls); |
|
601 | + |
|
602 | + foreach ($expectedCalls as $index => $call) { |
|
603 | + $this->assertHookCall( |
|
604 | + self::$hookCalls[$index], |
|
605 | + $call[0], |
|
606 | + '/mountpoint', |
|
607 | + $call[1], |
|
608 | + $call[2] |
|
609 | + ); |
|
610 | + } |
|
611 | + } |
|
612 | 612 | } |
@@ -18,259 +18,259 @@ |
||
18 | 18 | * @group DB |
19 | 19 | */ |
20 | 20 | class DBConfigServiceTest extends TestCase { |
21 | - private IDBConnection $connection; |
|
22 | - private DBConfigService $dbConfig; |
|
23 | - |
|
24 | - private array $mounts = []; |
|
25 | - |
|
26 | - protected function setUp(): void { |
|
27 | - parent::setUp(); |
|
28 | - $this->connection = Server::get(IDBConnection::class); |
|
29 | - $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class)); |
|
30 | - } |
|
31 | - |
|
32 | - protected function tearDown(): void { |
|
33 | - foreach ($this->mounts as $mount) { |
|
34 | - $this->dbConfig->removeMount($mount); |
|
35 | - } |
|
36 | - $this->mounts = []; |
|
37 | - parent::tearDown(); |
|
38 | - } |
|
39 | - |
|
40 | - private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) { |
|
41 | - $id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); |
|
42 | - $this->mounts[] = $id; |
|
43 | - return $id; |
|
44 | - } |
|
45 | - |
|
46 | - public function testAddSimpleMount(): void { |
|
47 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
48 | - |
|
49 | - $mount = $this->dbConfig->getMountById($id); |
|
50 | - $this->assertEquals('/test', $mount['mount_point']); |
|
51 | - $this->assertEquals('foo', $mount['storage_backend']); |
|
52 | - $this->assertEquals('bar', $mount['auth_backend']); |
|
53 | - $this->assertEquals(100, $mount['priority']); |
|
54 | - $this->assertEquals(DBConfigService::MOUNT_TYPE_ADMIN, $mount['type']); |
|
55 | - $this->assertEquals([], $mount['applicable']); |
|
56 | - $this->assertEquals([], $mount['config']); |
|
57 | - $this->assertEquals([], $mount['options']); |
|
58 | - } |
|
59 | - |
|
60 | - public function testAddApplicable(): void { |
|
61 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
62 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
63 | - |
|
64 | - $mount = $this->dbConfig->getMountById($id); |
|
65 | - $this->assertEquals([ |
|
66 | - ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
67 | - ], $mount['applicable']); |
|
68 | - |
|
69 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, 'bar'); |
|
70 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
71 | - |
|
72 | - $mount = $this->dbConfig->getMountById($id); |
|
73 | - $this->assertEqualsCanonicalizing([ |
|
74 | - ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id], |
|
75 | - ['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id], |
|
76 | - ['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id] |
|
77 | - ], $mount['applicable']); |
|
78 | - } |
|
79 | - |
|
80 | - public function testAddApplicableDouble(): void { |
|
81 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
82 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
83 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
84 | - |
|
85 | - $mount = $this->dbConfig->getMountById($id); |
|
86 | - $this->assertEquals([ |
|
87 | - ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
88 | - ], $mount['applicable']); |
|
89 | - } |
|
90 | - |
|
91 | - public function testDeleteMount(): void { |
|
92 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
93 | - |
|
94 | - $this->dbConfig->removeMount($id); |
|
95 | - |
|
96 | - $mount = $this->dbConfig->getMountById($id); |
|
97 | - $this->assertEquals(null, $mount); |
|
98 | - } |
|
99 | - |
|
100 | - public function testRemoveApplicable(): void { |
|
101 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
102 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
103 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
104 | - |
|
105 | - $mount = $this->dbConfig->getMountById($id); |
|
106 | - $this->assertEquals([], $mount['applicable']); |
|
107 | - } |
|
108 | - |
|
109 | - public function testRemoveApplicableGlobal(): void { |
|
110 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
111 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
112 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
113 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
114 | - |
|
115 | - $mount = $this->dbConfig->getMountById($id); |
|
116 | - $this->assertEquals([ |
|
117 | - ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
118 | - ], $mount['applicable']); |
|
119 | - } |
|
120 | - |
|
121 | - public function testSetConfig(): void { |
|
122 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
123 | - $this->dbConfig->setConfig($id, 'foo', 'bar'); |
|
124 | - |
|
125 | - $mount = $this->dbConfig->getMountById($id); |
|
126 | - $this->assertEquals(['foo' => 'bar'], $mount['config']); |
|
127 | - |
|
128 | - $this->dbConfig->setConfig($id, 'foo2', 'bar2'); |
|
129 | - |
|
130 | - $mount = $this->dbConfig->getMountById($id); |
|
131 | - $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']); |
|
132 | - } |
|
133 | - |
|
134 | - public function testSetConfigOverwrite(): void { |
|
135 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
136 | - $this->dbConfig->setConfig($id, 'foo', 'bar'); |
|
137 | - $this->dbConfig->setConfig($id, 'asd', '1'); |
|
138 | - $this->dbConfig->setConfig($id, 'foo', 'qwerty'); |
|
139 | - |
|
140 | - $mount = $this->dbConfig->getMountById($id); |
|
141 | - $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']); |
|
142 | - } |
|
143 | - |
|
144 | - public function testSetOption(): void { |
|
145 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
146 | - $this->dbConfig->setOption($id, 'foo', 'bar'); |
|
147 | - |
|
148 | - $mount = $this->dbConfig->getMountById($id); |
|
149 | - $this->assertEquals(['foo' => 'bar'], $mount['options']); |
|
150 | - |
|
151 | - $this->dbConfig->setOption($id, 'foo2', 'bar2'); |
|
152 | - |
|
153 | - $mount = $this->dbConfig->getMountById($id); |
|
154 | - $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']); |
|
155 | - } |
|
156 | - |
|
157 | - public function testSetOptionOverwrite(): void { |
|
158 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
159 | - $this->dbConfig->setOption($id, 'foo', 'bar'); |
|
160 | - $this->dbConfig->setOption($id, 'asd', '1'); |
|
161 | - $this->dbConfig->setOption($id, 'foo', 'qwerty'); |
|
162 | - |
|
163 | - $mount = $this->dbConfig->getMountById($id); |
|
164 | - $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']); |
|
165 | - } |
|
166 | - |
|
167 | - public function testGetMountsFor(): void { |
|
168 | - $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
169 | - $this->assertEquals([], $mounts); |
|
170 | - |
|
171 | - $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
172 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
173 | - |
|
174 | - $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
175 | - $this->assertCount(1, $mounts); |
|
176 | - $this->assertEquals($id, $mounts[0]['mount_id']); |
|
177 | - $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']); |
|
178 | - } |
|
179 | - |
|
180 | - public function testGetAdminMounts(): void { |
|
181 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
182 | - $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
183 | - |
|
184 | - $mounts = $this->dbConfig->getAdminMounts(); |
|
185 | - $this->assertCount(1, $mounts); |
|
186 | - $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
187 | - } |
|
188 | - |
|
189 | - public function testGetAdminMountsFor(): void { |
|
190 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
191 | - $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
192 | - $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
21 | + private IDBConnection $connection; |
|
22 | + private DBConfigService $dbConfig; |
|
23 | + |
|
24 | + private array $mounts = []; |
|
25 | + |
|
26 | + protected function setUp(): void { |
|
27 | + parent::setUp(); |
|
28 | + $this->connection = Server::get(IDBConnection::class); |
|
29 | + $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class)); |
|
30 | + } |
|
31 | + |
|
32 | + protected function tearDown(): void { |
|
33 | + foreach ($this->mounts as $mount) { |
|
34 | + $this->dbConfig->removeMount($mount); |
|
35 | + } |
|
36 | + $this->mounts = []; |
|
37 | + parent::tearDown(); |
|
38 | + } |
|
39 | + |
|
40 | + private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) { |
|
41 | + $id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); |
|
42 | + $this->mounts[] = $id; |
|
43 | + return $id; |
|
44 | + } |
|
45 | + |
|
46 | + public function testAddSimpleMount(): void { |
|
47 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
48 | + |
|
49 | + $mount = $this->dbConfig->getMountById($id); |
|
50 | + $this->assertEquals('/test', $mount['mount_point']); |
|
51 | + $this->assertEquals('foo', $mount['storage_backend']); |
|
52 | + $this->assertEquals('bar', $mount['auth_backend']); |
|
53 | + $this->assertEquals(100, $mount['priority']); |
|
54 | + $this->assertEquals(DBConfigService::MOUNT_TYPE_ADMIN, $mount['type']); |
|
55 | + $this->assertEquals([], $mount['applicable']); |
|
56 | + $this->assertEquals([], $mount['config']); |
|
57 | + $this->assertEquals([], $mount['options']); |
|
58 | + } |
|
59 | + |
|
60 | + public function testAddApplicable(): void { |
|
61 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
62 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
63 | + |
|
64 | + $mount = $this->dbConfig->getMountById($id); |
|
65 | + $this->assertEquals([ |
|
66 | + ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
67 | + ], $mount['applicable']); |
|
68 | + |
|
69 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, 'bar'); |
|
70 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
71 | + |
|
72 | + $mount = $this->dbConfig->getMountById($id); |
|
73 | + $this->assertEqualsCanonicalizing([ |
|
74 | + ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id], |
|
75 | + ['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id], |
|
76 | + ['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id] |
|
77 | + ], $mount['applicable']); |
|
78 | + } |
|
79 | + |
|
80 | + public function testAddApplicableDouble(): void { |
|
81 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
82 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
83 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
84 | + |
|
85 | + $mount = $this->dbConfig->getMountById($id); |
|
86 | + $this->assertEquals([ |
|
87 | + ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
88 | + ], $mount['applicable']); |
|
89 | + } |
|
90 | + |
|
91 | + public function testDeleteMount(): void { |
|
92 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
93 | + |
|
94 | + $this->dbConfig->removeMount($id); |
|
95 | + |
|
96 | + $mount = $this->dbConfig->getMountById($id); |
|
97 | + $this->assertEquals(null, $mount); |
|
98 | + } |
|
99 | + |
|
100 | + public function testRemoveApplicable(): void { |
|
101 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
102 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
103 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
104 | + |
|
105 | + $mount = $this->dbConfig->getMountById($id); |
|
106 | + $this->assertEquals([], $mount['applicable']); |
|
107 | + } |
|
108 | + |
|
109 | + public function testRemoveApplicableGlobal(): void { |
|
110 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
111 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
112 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
113 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
114 | + |
|
115 | + $mount = $this->dbConfig->getMountById($id); |
|
116 | + $this->assertEquals([ |
|
117 | + ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id] |
|
118 | + ], $mount['applicable']); |
|
119 | + } |
|
120 | + |
|
121 | + public function testSetConfig(): void { |
|
122 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
123 | + $this->dbConfig->setConfig($id, 'foo', 'bar'); |
|
124 | + |
|
125 | + $mount = $this->dbConfig->getMountById($id); |
|
126 | + $this->assertEquals(['foo' => 'bar'], $mount['config']); |
|
127 | + |
|
128 | + $this->dbConfig->setConfig($id, 'foo2', 'bar2'); |
|
129 | + |
|
130 | + $mount = $this->dbConfig->getMountById($id); |
|
131 | + $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']); |
|
132 | + } |
|
133 | + |
|
134 | + public function testSetConfigOverwrite(): void { |
|
135 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
136 | + $this->dbConfig->setConfig($id, 'foo', 'bar'); |
|
137 | + $this->dbConfig->setConfig($id, 'asd', '1'); |
|
138 | + $this->dbConfig->setConfig($id, 'foo', 'qwerty'); |
|
139 | + |
|
140 | + $mount = $this->dbConfig->getMountById($id); |
|
141 | + $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']); |
|
142 | + } |
|
143 | + |
|
144 | + public function testSetOption(): void { |
|
145 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
146 | + $this->dbConfig->setOption($id, 'foo', 'bar'); |
|
147 | + |
|
148 | + $mount = $this->dbConfig->getMountById($id); |
|
149 | + $this->assertEquals(['foo' => 'bar'], $mount['options']); |
|
150 | + |
|
151 | + $this->dbConfig->setOption($id, 'foo2', 'bar2'); |
|
152 | + |
|
153 | + $mount = $this->dbConfig->getMountById($id); |
|
154 | + $this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']); |
|
155 | + } |
|
156 | + |
|
157 | + public function testSetOptionOverwrite(): void { |
|
158 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
159 | + $this->dbConfig->setOption($id, 'foo', 'bar'); |
|
160 | + $this->dbConfig->setOption($id, 'asd', '1'); |
|
161 | + $this->dbConfig->setOption($id, 'foo', 'qwerty'); |
|
162 | + |
|
163 | + $mount = $this->dbConfig->getMountById($id); |
|
164 | + $this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']); |
|
165 | + } |
|
166 | + |
|
167 | + public function testGetMountsFor(): void { |
|
168 | + $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
169 | + $this->assertEquals([], $mounts); |
|
170 | + |
|
171 | + $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
172 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
173 | + |
|
174 | + $mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
175 | + $this->assertCount(1, $mounts); |
|
176 | + $this->assertEquals($id, $mounts[0]['mount_id']); |
|
177 | + $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']); |
|
178 | + } |
|
179 | + |
|
180 | + public function testGetAdminMounts(): void { |
|
181 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
182 | + $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
183 | + |
|
184 | + $mounts = $this->dbConfig->getAdminMounts(); |
|
185 | + $this->assertCount(1, $mounts); |
|
186 | + $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
187 | + } |
|
188 | + |
|
189 | + public function testGetAdminMountsFor(): void { |
|
190 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
191 | + $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
192 | + $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
193 | 193 | |
194 | - $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
195 | - $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
196 | - |
|
197 | - $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
198 | - $this->assertCount(1, $mounts); |
|
199 | - $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
200 | - $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']); |
|
201 | - } |
|
202 | - |
|
203 | - public function testGetUserMountsFor(): void { |
|
204 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
205 | - $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
206 | - $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
207 | - |
|
208 | - $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
209 | - $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
210 | - |
|
211 | - $mounts = $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
212 | - $this->assertCount(1, $mounts); |
|
213 | - $this->assertEquals($id3, $mounts[0]['mount_id']); |
|
214 | - $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']); |
|
215 | - } |
|
216 | - |
|
217 | - public function testGetAdminMountsForGlobal(): void { |
|
218 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
194 | + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
195 | + $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
196 | + |
|
197 | + $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
198 | + $this->assertCount(1, $mounts); |
|
199 | + $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
200 | + $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']); |
|
201 | + } |
|
202 | + |
|
203 | + public function testGetUserMountsFor(): void { |
|
204 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
205 | + $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
206 | + $id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
207 | + |
|
208 | + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
209 | + $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
210 | + |
|
211 | + $mounts = $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test'); |
|
212 | + $this->assertCount(1, $mounts); |
|
213 | + $this->assertEquals($id3, $mounts[0]['mount_id']); |
|
214 | + $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']); |
|
215 | + } |
|
216 | + |
|
217 | + public function testGetAdminMountsForGlobal(): void { |
|
218 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
219 | 219 | |
220 | - $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
220 | + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
221 | 221 | |
222 | - $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
223 | - $this->assertCount(1, $mounts); |
|
224 | - $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
225 | - $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']); |
|
226 | - } |
|
222 | + $mounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
223 | + $this->assertCount(1, $mounts); |
|
224 | + $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
225 | + $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']); |
|
226 | + } |
|
227 | 227 | |
228 | - public function testSetMountPoint(): void { |
|
229 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
230 | - $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
231 | - |
|
232 | - $this->dbConfig->setMountPoint($id1, '/asd'); |
|
228 | + public function testSetMountPoint(): void { |
|
229 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
230 | + $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
231 | + |
|
232 | + $this->dbConfig->setMountPoint($id1, '/asd'); |
|
233 | 233 | |
234 | - $mount = $this->dbConfig->getMountById($id1); |
|
235 | - $this->assertEquals('/asd', $mount['mount_point']); |
|
236 | - |
|
237 | - // remains unchanged |
|
238 | - $mount = $this->dbConfig->getMountById($id2); |
|
239 | - $this->assertEquals('/foo', $mount['mount_point']); |
|
240 | - } |
|
234 | + $mount = $this->dbConfig->getMountById($id1); |
|
235 | + $this->assertEquals('/asd', $mount['mount_point']); |
|
236 | + |
|
237 | + // remains unchanged |
|
238 | + $mount = $this->dbConfig->getMountById($id2); |
|
239 | + $this->assertEquals('/foo', $mount['mount_point']); |
|
240 | + } |
|
241 | 241 | |
242 | - public function testSetAuthBackend(): void { |
|
243 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
244 | - $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
242 | + public function testSetAuthBackend(): void { |
|
243 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
244 | + $id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
245 | 245 | |
246 | - $this->dbConfig->setAuthBackend($id1, 'none'); |
|
246 | + $this->dbConfig->setAuthBackend($id1, 'none'); |
|
247 | 247 | |
248 | - $mount = $this->dbConfig->getMountById($id1); |
|
249 | - $this->assertEquals('none', $mount['auth_backend']); |
|
248 | + $mount = $this->dbConfig->getMountById($id1); |
|
249 | + $this->assertEquals('none', $mount['auth_backend']); |
|
250 | 250 | |
251 | - // remains unchanged |
|
252 | - $mount = $this->dbConfig->getMountById($id2); |
|
253 | - $this->assertEquals('bar', $mount['auth_backend']); |
|
254 | - } |
|
255 | - |
|
256 | - public function testGetMountsForDuplicateByGroup(): void { |
|
257 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
258 | - |
|
259 | - $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1'); |
|
260 | - $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group2'); |
|
251 | + // remains unchanged |
|
252 | + $mount = $this->dbConfig->getMountById($id2); |
|
253 | + $this->assertEquals('bar', $mount['auth_backend']); |
|
254 | + } |
|
255 | + |
|
256 | + public function testGetMountsForDuplicateByGroup(): void { |
|
257 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
258 | + |
|
259 | + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1'); |
|
260 | + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group2'); |
|
261 | 261 | |
262 | - $mounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, ['group1', 'group2']); |
|
263 | - $this->assertCount(1, $mounts); |
|
264 | - $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
265 | - } |
|
262 | + $mounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, ['group1', 'group2']); |
|
263 | + $this->assertCount(1, $mounts); |
|
264 | + $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
265 | + } |
|
266 | 266 | |
267 | - public function testGetAllMounts(): void { |
|
268 | - $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
269 | - $id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
267 | + public function testGetAllMounts(): void { |
|
268 | + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); |
|
269 | + $id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); |
|
270 | 270 | |
271 | - $mounts = $this->dbConfig->getAllMounts(); |
|
272 | - $this->assertCount(2, $mounts); |
|
273 | - $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
274 | - $this->assertEquals($id2, $mounts[1]['mount_id']); |
|
275 | - } |
|
271 | + $mounts = $this->dbConfig->getAllMounts(); |
|
272 | + $this->assertCount(2, $mounts); |
|
273 | + $this->assertEquals($id1, $mounts[0]['mount_id']); |
|
274 | + $this->assertEquals($id2, $mounts[1]['mount_id']); |
|
275 | + } |
|
276 | 276 | } |
@@ -12,657 +12,657 @@ |
||
12 | 12 | use OCP\Files\Storage\IWriteStreamStorage; |
13 | 13 | |
14 | 14 | abstract class Storage extends \Test\TestCase { |
15 | - /** |
|
16 | - * @var \OC\Files\Storage\Storage instance |
|
17 | - */ |
|
18 | - protected $instance; |
|
19 | - protected $waitDelay = 0; |
|
20 | - |
|
21 | - /** |
|
22 | - * Sleep for the number of seconds specified in the |
|
23 | - * $waitDelay attribute |
|
24 | - */ |
|
25 | - protected function wait() { |
|
26 | - if ($this->waitDelay > 0) { |
|
27 | - sleep($this->waitDelay); |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * the root folder of the storage should always exist, be readable and be recognized as a directory |
|
33 | - */ |
|
34 | - public function testRoot(): void { |
|
35 | - $this->assertTrue($this->instance->file_exists('/'), 'Root folder does not exist'); |
|
36 | - $this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable'); |
|
37 | - $this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory'); |
|
38 | - $this->assertFalse($this->instance->is_file('/'), 'Root folder is a file'); |
|
39 | - $this->assertEquals('dir', $this->instance->filetype('/')); |
|
40 | - |
|
41 | - //without this, any further testing would be useless, not an actual requirement for filestorage though |
|
42 | - $this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable'); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Check that the test() function works |
|
47 | - */ |
|
48 | - public function testTestFunction(): void { |
|
49 | - $this->assertTrue($this->instance->test()); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @dataProvider directoryProvider |
|
54 | - */ |
|
55 | - public function testDirectories($directory): void { |
|
56 | - $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
57 | - |
|
58 | - $this->assertTrue($this->instance->mkdir('/' . $directory)); |
|
59 | - |
|
60 | - $this->assertTrue($this->instance->file_exists('/' . $directory)); |
|
61 | - $this->assertTrue($this->instance->is_dir('/' . $directory)); |
|
62 | - $this->assertFalse($this->instance->is_file('/' . $directory)); |
|
63 | - $this->assertEquals('dir', $this->instance->filetype('/' . $directory)); |
|
64 | - $this->assertEquals(0, $this->instance->filesize('/' . $directory)); |
|
65 | - $this->assertTrue($this->instance->isReadable('/' . $directory)); |
|
66 | - $this->assertTrue($this->instance->isUpdatable('/' . $directory)); |
|
67 | - |
|
68 | - $dh = $this->instance->opendir('/'); |
|
69 | - $content = []; |
|
70 | - while (($file = readdir($dh)) !== false) { |
|
71 | - if ($file != '.' and $file != '..') { |
|
72 | - $content[] = $file; |
|
73 | - } |
|
74 | - } |
|
75 | - $this->assertEquals([$directory], $content); |
|
76 | - |
|
77 | - $content = iterator_to_array($this->instance->getDirectoryContent('/')); |
|
78 | - |
|
79 | - $this->assertCount(1, $content); |
|
80 | - $dirEntry = $content[0]; |
|
81 | - unset($dirEntry['scan_permissions']); |
|
82 | - unset($dirEntry['etag']); |
|
83 | - $this->assertLessThanOrEqual(1, abs($dirEntry['mtime'] - $this->instance->filemtime($directory))); |
|
84 | - unset($dirEntry['mtime']); |
|
85 | - unset($dirEntry['storage_mtime']); |
|
86 | - $this->assertEquals([ |
|
87 | - 'name' => $directory, |
|
88 | - 'mimetype' => $this->instance->getMimeType($directory), |
|
89 | - 'size' => -1, |
|
90 | - 'permissions' => $this->instance->getPermissions($directory), |
|
91 | - ], $dirEntry); |
|
92 | - |
|
93 | - $this->assertFalse($this->instance->mkdir('/' . $directory)); //can't create existing folders |
|
94 | - $this->assertTrue($this->instance->rmdir('/' . $directory)); |
|
95 | - |
|
96 | - $this->wait(); |
|
97 | - $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
98 | - |
|
99 | - $this->assertFalse($this->instance->rmdir('/' . $directory)); //can't remove non existing folders |
|
100 | - |
|
101 | - $dh = $this->instance->opendir('/'); |
|
102 | - $content = []; |
|
103 | - while (($file = readdir($dh)) !== false) { |
|
104 | - if ($file != '.' and $file != '..') { |
|
105 | - $content[] = $file; |
|
106 | - } |
|
107 | - } |
|
108 | - $this->assertEquals([], $content); |
|
109 | - } |
|
110 | - |
|
111 | - public static function fileNameProvider(): array { |
|
112 | - return [ |
|
113 | - ['file.txt'], |
|
114 | - [' file.txt'], |
|
115 | - ['folder .txt'], |
|
116 | - ['file with space.txt'], |
|
117 | - ['spéciäl fäile'], |
|
118 | - ['test single\'quote.txt'], |
|
119 | - ]; |
|
120 | - } |
|
121 | - |
|
122 | - public static function directoryProvider(): array { |
|
123 | - return [ |
|
124 | - ['folder'], |
|
125 | - [' folder'], |
|
126 | - ['folder '], |
|
127 | - ['folder with space'], |
|
128 | - ['spéciäl földer'], |
|
129 | - ['test single\'quote'], |
|
130 | - ]; |
|
131 | - } |
|
132 | - |
|
133 | - public static function loremFileProvider(): array { |
|
134 | - $root = \OC::$SERVERROOT . '/tests/data/'; |
|
135 | - return [ |
|
136 | - // small file |
|
137 | - [$root . 'lorem.txt'], |
|
138 | - // bigger file (> 8 KB which is the standard PHP block size) |
|
139 | - [$root . 'lorem-big.txt'] |
|
140 | - ]; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * test the various uses of file_get_contents and file_put_contents |
|
145 | - * |
|
146 | - * @dataProvider loremFileProvider |
|
147 | - */ |
|
148 | - public function testGetPutContents($sourceFile): void { |
|
149 | - $sourceText = file_get_contents($sourceFile); |
|
150 | - |
|
151 | - //fill a file with string data |
|
152 | - $this->instance->file_put_contents('/lorem.txt', $sourceText); |
|
153 | - $this->assertFalse($this->instance->is_dir('/lorem.txt')); |
|
154 | - $this->assertEquals($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); |
|
155 | - |
|
156 | - //empty the file |
|
157 | - $this->instance->file_put_contents('/lorem.txt', ''); |
|
158 | - $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * test various known mimetypes |
|
163 | - */ |
|
164 | - public function testMimeType(): void { |
|
165 | - $this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/')); |
|
166 | - $this->assertEquals(false, $this->instance->getMimeType('/non/existing/file')); |
|
167 | - |
|
168 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
169 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); |
|
170 | - $this->assertEquals('text/plain', $this->instance->getMimeType('/lorem.txt')); |
|
171 | - |
|
172 | - $pngFile = \OC::$SERVERROOT . '/tests/data/desktopapp.png'; |
|
173 | - $this->instance->file_put_contents('/desktopapp.png', file_get_contents($pngFile, 'r')); |
|
174 | - $this->assertEquals('image/png', $this->instance->getMimeType('/desktopapp.png')); |
|
175 | - |
|
176 | - $svgFile = \OC::$SERVERROOT . '/tests/data/desktopapp.svg'; |
|
177 | - $this->instance->file_put_contents('/desktopapp.svg', file_get_contents($svgFile, 'r')); |
|
178 | - $this->assertEquals('image/svg+xml', $this->instance->getMimeType('/desktopapp.svg')); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - public static function copyAndMoveProvider(): array { |
|
183 | - return [ |
|
184 | - ['/source.txt', '/target.txt'], |
|
185 | - ['/source.txt', '/target with space.txt'], |
|
186 | - ['/source with space.txt', '/target.txt'], |
|
187 | - ['/source with space.txt', '/target with space.txt'], |
|
188 | - ['/source.txt', '/tärgét.txt'], |
|
189 | - ['/sòurcē.txt', '/target.txt'], |
|
190 | - ['/sòurcē.txt', '/tärgét.txt'], |
|
191 | - ['/single \' quote.txt', '/tar\'get.txt'], |
|
192 | - ]; |
|
193 | - } |
|
194 | - |
|
195 | - public function initSourceAndTarget($source, $target = null) { |
|
196 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
197 | - $this->instance->file_put_contents($source, file_get_contents($textFile)); |
|
198 | - if ($target) { |
|
199 | - $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
200 | - $this->instance->file_put_contents($target, $testContents); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - public function assertSameAsLorem($file) { |
|
205 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
206 | - $this->assertEquals( |
|
207 | - file_get_contents($textFile), |
|
208 | - $this->instance->file_get_contents($file), |
|
209 | - 'Expected ' . $file . ' to be a copy of ' . $textFile |
|
210 | - ); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @dataProvider copyAndMoveProvider |
|
215 | - */ |
|
216 | - public function testCopy($source, $target): void { |
|
217 | - $this->initSourceAndTarget($source); |
|
218 | - |
|
219 | - $this->instance->copy($source, $target); |
|
220 | - |
|
221 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
222 | - $this->assertSameAsLorem($target); |
|
223 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @dataProvider copyAndMoveProvider |
|
228 | - */ |
|
229 | - public function testMove($source, $target): void { |
|
230 | - $this->initSourceAndTarget($source); |
|
231 | - |
|
232 | - $this->instance->rename($source, $target); |
|
233 | - |
|
234 | - $this->wait(); |
|
235 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
236 | - $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
237 | - $this->assertSameAsLorem($target); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @dataProvider copyAndMoveProvider |
|
242 | - */ |
|
243 | - public function testCopyOverwrite($source, $target): void { |
|
244 | - $this->initSourceAndTarget($source, $target); |
|
245 | - |
|
246 | - $this->instance->copy($source, $target); |
|
247 | - |
|
248 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
249 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
250 | - $this->assertSameAsLorem($target); |
|
251 | - $this->assertSameAsLorem($source); |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @dataProvider copyAndMoveProvider |
|
256 | - */ |
|
257 | - public function testMoveOverwrite($source, $target): void { |
|
258 | - $this->initSourceAndTarget($source, $target); |
|
259 | - |
|
260 | - $this->instance->rename($source, $target); |
|
261 | - |
|
262 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
263 | - $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
264 | - $this->assertSameAsLorem($target); |
|
265 | - } |
|
266 | - |
|
267 | - public function testLocal(): void { |
|
268 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
269 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
270 | - $localFile = $this->instance->getLocalFile('/lorem.txt'); |
|
271 | - $this->assertTrue(file_exists($localFile)); |
|
272 | - $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile)); |
|
273 | - |
|
274 | - $this->instance->mkdir('/folder'); |
|
275 | - $this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile)); |
|
276 | - $this->instance->file_put_contents('/folder/bar.txt', 'asd'); |
|
277 | - $this->instance->mkdir('/folder/recursive'); |
|
278 | - $this->instance->file_put_contents('/folder/recursive/file.txt', 'foo'); |
|
279 | - |
|
280 | - // test below require to use instance->getLocalFile because the physical storage might be different |
|
281 | - $localFile = $this->instance->getLocalFile('/folder/lorem.txt'); |
|
282 | - $this->assertTrue(file_exists($localFile)); |
|
283 | - $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile)); |
|
284 | - |
|
285 | - $localFile = $this->instance->getLocalFile('/folder/bar.txt'); |
|
286 | - $this->assertTrue(file_exists($localFile)); |
|
287 | - $this->assertEquals(file_get_contents($localFile), 'asd'); |
|
288 | - |
|
289 | - $localFile = $this->instance->getLocalFile('/folder/recursive/file.txt'); |
|
290 | - $this->assertTrue(file_exists($localFile)); |
|
291 | - $this->assertEquals(file_get_contents($localFile), 'foo'); |
|
292 | - } |
|
293 | - |
|
294 | - public function testStat(): void { |
|
295 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
296 | - $ctimeStart = time(); |
|
297 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
298 | - $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
299 | - $ctimeEnd = time(); |
|
300 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
301 | - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
302 | - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); |
|
303 | - |
|
304 | - // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
305 | - $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
306 | - $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
307 | - $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
308 | - |
|
309 | - $stat = $this->instance->stat('/lorem.txt'); |
|
310 | - //only size and mtime are required in the result |
|
311 | - $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
312 | - $this->assertEquals($stat['mtime'], $mTime); |
|
313 | - |
|
314 | - if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
315 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
316 | - $this->assertEquals($mTime, 100); |
|
317 | - } |
|
318 | - |
|
319 | - $mtimeStart = time(); |
|
320 | - |
|
321 | - $this->instance->unlink('/lorem.txt'); |
|
322 | - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Test whether checkUpdate properly returns false when there was |
|
327 | - * no change. |
|
328 | - */ |
|
329 | - public function testCheckUpdate(): void { |
|
330 | - if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) { |
|
331 | - $this->markTestSkipped('Cannot test update check on wrappers'); |
|
332 | - } |
|
333 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
334 | - $watcher = $this->instance->getWatcher(); |
|
335 | - $watcher->setPolicy(Watcher::CHECK_ALWAYS); |
|
336 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
337 | - $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected'); |
|
338 | - $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update'); |
|
339 | - } |
|
340 | - |
|
341 | - public function testUnlink(): void { |
|
342 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
343 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
344 | - |
|
345 | - $this->assertTrue($this->instance->file_exists('/lorem.txt')); |
|
346 | - |
|
347 | - $this->assertTrue($this->instance->unlink('/lorem.txt')); |
|
348 | - $this->wait(); |
|
349 | - |
|
350 | - $this->assertFalse($this->instance->file_exists('/lorem.txt')); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * @dataProvider fileNameProvider |
|
355 | - */ |
|
356 | - public function testFOpen($fileName): void { |
|
357 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
358 | - |
|
359 | - $fh = @$this->instance->fopen($fileName, 'r'); |
|
360 | - if ($fh) { |
|
361 | - fclose($fh); |
|
362 | - } |
|
363 | - $this->assertFalse($fh); |
|
364 | - $this->assertFalse($this->instance->file_exists($fileName)); |
|
365 | - |
|
366 | - $fh = $this->instance->fopen($fileName, 'w'); |
|
367 | - fwrite($fh, file_get_contents($textFile)); |
|
368 | - fclose($fh); |
|
369 | - $this->assertTrue($this->instance->file_exists($fileName)); |
|
370 | - |
|
371 | - $fh = $this->instance->fopen($fileName, 'r'); |
|
372 | - $content = stream_get_contents($fh); |
|
373 | - $this->assertEquals(file_get_contents($textFile), $content); |
|
374 | - } |
|
375 | - |
|
376 | - public function testTouchCreateFile(): void { |
|
377 | - $this->assertFalse($this->instance->file_exists('touch')); |
|
378 | - // returns true on success |
|
379 | - $this->assertTrue($this->instance->touch('touch')); |
|
380 | - $this->assertTrue($this->instance->file_exists('touch')); |
|
381 | - } |
|
382 | - |
|
383 | - public function testRecursiveRmdir(): void { |
|
384 | - $this->instance->mkdir('folder'); |
|
385 | - $this->instance->mkdir('folder/bar'); |
|
386 | - $this->wait(); |
|
387 | - $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
388 | - $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
389 | - $this->assertTrue($this->instance->rmdir('folder')); |
|
390 | - $this->wait(); |
|
391 | - $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
392 | - $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
393 | - $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
394 | - $this->assertFalse($this->instance->file_exists('folder')); |
|
395 | - } |
|
396 | - |
|
397 | - public function testRmdirEmptyFolder(): void { |
|
398 | - $this->assertTrue($this->instance->mkdir('empty')); |
|
399 | - $this->wait(); |
|
400 | - $this->assertTrue($this->instance->rmdir('empty')); |
|
401 | - $this->assertFalse($this->instance->file_exists('empty')); |
|
402 | - } |
|
403 | - |
|
404 | - public function testRecursiveUnlink(): void { |
|
405 | - $this->instance->mkdir('folder'); |
|
406 | - $this->instance->mkdir('folder/bar'); |
|
407 | - $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
408 | - $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
409 | - $this->assertTrue($this->instance->unlink('folder')); |
|
410 | - $this->wait(); |
|
411 | - $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
412 | - $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
413 | - $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
414 | - $this->assertFalse($this->instance->file_exists('folder')); |
|
415 | - } |
|
416 | - |
|
417 | - public static function hashProvider(): array { |
|
418 | - return [ |
|
419 | - ['Foobar', 'md5'], |
|
420 | - ['Foobar', 'sha1'], |
|
421 | - ['Foobar', 'sha256'], |
|
422 | - ]; |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * @dataProvider hashProvider |
|
427 | - */ |
|
428 | - public function testHash($data, $type): void { |
|
429 | - $this->instance->file_put_contents('hash.txt', $data); |
|
430 | - $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); |
|
431 | - $this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true)); |
|
432 | - } |
|
433 | - |
|
434 | - public function testHashInFileName(): void { |
|
435 | - $this->instance->file_put_contents('#test.txt', 'data'); |
|
436 | - $this->assertEquals('data', $this->instance->file_get_contents('#test.txt')); |
|
437 | - |
|
438 | - $this->instance->mkdir('#foo'); |
|
439 | - $this->instance->file_put_contents('#foo/test.txt', 'data'); |
|
440 | - $this->assertEquals('data', $this->instance->file_get_contents('#foo/test.txt')); |
|
441 | - |
|
442 | - $dh = $this->instance->opendir('#foo'); |
|
443 | - $content = []; |
|
444 | - while ($file = readdir($dh)) { |
|
445 | - if ($file != '.' and $file != '..') { |
|
446 | - $content[] = $file; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - $this->assertEquals(['test.txt'], $content); |
|
451 | - } |
|
452 | - |
|
453 | - public function testCopyOverWriteFile(): void { |
|
454 | - $this->instance->file_put_contents('target.txt', 'foo'); |
|
455 | - $this->instance->file_put_contents('source.txt', 'bar'); |
|
456 | - $this->instance->copy('source.txt', 'target.txt'); |
|
457 | - $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
458 | - } |
|
459 | - |
|
460 | - public function testRenameOverWriteFile(): void { |
|
461 | - $this->instance->file_put_contents('target.txt', 'foo'); |
|
462 | - $this->instance->file_put_contents('source.txt', 'bar'); |
|
463 | - $this->instance->rename('source.txt', 'target.txt'); |
|
464 | - $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
465 | - $this->assertFalse($this->instance->file_exists('source.txt')); |
|
466 | - } |
|
467 | - |
|
468 | - public function testRenameDirectory(): void { |
|
469 | - $this->instance->mkdir('source'); |
|
470 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
471 | - $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
472 | - $this->instance->mkdir('source/subfolder'); |
|
473 | - $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
474 | - $this->instance->rename('source', 'target'); |
|
475 | - |
|
476 | - $this->assertFalse($this->instance->file_exists('source')); |
|
477 | - $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
478 | - $this->assertFalse($this->instance->file_exists('source/test2.txt')); |
|
479 | - $this->assertFalse($this->instance->file_exists('source/subfolder')); |
|
480 | - $this->assertFalse($this->instance->file_exists('source/subfolder/test.txt')); |
|
481 | - |
|
482 | - $this->assertTrue($this->instance->file_exists('target')); |
|
483 | - $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
484 | - $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
485 | - $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
486 | - $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
487 | - |
|
488 | - $contents = iterator_to_array($this->instance->getDirectoryContent('')); |
|
489 | - $this->assertCount(1, $contents); |
|
490 | - |
|
491 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
492 | - $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
493 | - $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
494 | - } |
|
495 | - |
|
496 | - public function testRenameOverWriteDirectory(): void { |
|
497 | - $this->instance->mkdir('source'); |
|
498 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
499 | - |
|
500 | - $this->instance->mkdir('target'); |
|
501 | - $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
502 | - $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
503 | - |
|
504 | - $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
505 | - |
|
506 | - $this->assertFalse($this->instance->file_exists('source'), 'source has not been removed'); |
|
507 | - $this->assertFalse($this->instance->file_exists('source/test1.txt'), 'source/test1.txt has not been removed'); |
|
508 | - $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'target/test2.txt has not been removed'); |
|
509 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'), 'target/test1.txt has not been overwritten'); |
|
510 | - } |
|
511 | - |
|
512 | - public function testRenameOverWriteDirectoryOverFile(): void { |
|
513 | - $this->instance->mkdir('source'); |
|
514 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
515 | - |
|
516 | - $this->instance->file_put_contents('target', 'bar'); |
|
517 | - |
|
518 | - $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
519 | - |
|
520 | - $this->assertFalse($this->instance->file_exists('source')); |
|
521 | - $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
522 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
523 | - } |
|
524 | - |
|
525 | - public function testCopyDirectory(): void { |
|
526 | - $this->instance->mkdir('source'); |
|
527 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
528 | - $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
529 | - $this->instance->mkdir('source/subfolder'); |
|
530 | - $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
531 | - $this->instance->copy('source', 'target'); |
|
532 | - |
|
533 | - $this->assertTrue($this->instance->file_exists('source')); |
|
534 | - $this->assertTrue($this->instance->file_exists('source/test1.txt')); |
|
535 | - $this->assertTrue($this->instance->file_exists('source/test2.txt')); |
|
536 | - $this->assertTrue($this->instance->file_exists('source/subfolder')); |
|
537 | - $this->assertTrue($this->instance->file_exists('source/subfolder/test.txt')); |
|
538 | - |
|
539 | - $this->assertTrue($this->instance->file_exists('target')); |
|
540 | - $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
541 | - $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
542 | - $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
543 | - $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
544 | - |
|
545 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
546 | - $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
547 | - $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
548 | - } |
|
549 | - |
|
550 | - public function testCopyOverWriteDirectory(): void { |
|
551 | - $this->instance->mkdir('source'); |
|
552 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
553 | - |
|
554 | - $this->instance->mkdir('target'); |
|
555 | - $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
556 | - $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
557 | - |
|
558 | - $this->instance->copy('source', 'target'); |
|
559 | - |
|
560 | - $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does'); |
|
561 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
562 | - } |
|
563 | - |
|
564 | - public function testCopyOverWriteDirectoryOverFile(): void { |
|
565 | - $this->instance->mkdir('source'); |
|
566 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
567 | - |
|
568 | - $this->instance->file_put_contents('target', 'bar'); |
|
569 | - |
|
570 | - $this->instance->copy('source', 'target'); |
|
571 | - |
|
572 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
573 | - } |
|
574 | - |
|
575 | - public function testInstanceOfStorage(): void { |
|
576 | - $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); |
|
577 | - $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); |
|
578 | - $this->assertFalse($this->instance->instanceOfStorage('\OC')); |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * @dataProvider copyAndMoveProvider |
|
583 | - */ |
|
584 | - public function testCopyFromSameStorage($source, $target): void { |
|
585 | - $this->initSourceAndTarget($source); |
|
586 | - |
|
587 | - $this->instance->copyFromStorage($this->instance, $source, $target); |
|
588 | - |
|
589 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
590 | - $this->assertSameAsLorem($target); |
|
591 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
592 | - } |
|
593 | - |
|
594 | - public function testIsCreatable(): void { |
|
595 | - $this->instance->mkdir('source'); |
|
596 | - $this->assertTrue($this->instance->isCreatable('source')); |
|
597 | - } |
|
598 | - |
|
599 | - public function testIsReadable(): void { |
|
600 | - $this->instance->mkdir('source'); |
|
601 | - $this->assertTrue($this->instance->isReadable('source')); |
|
602 | - } |
|
603 | - |
|
604 | - public function testIsUpdatable(): void { |
|
605 | - $this->instance->mkdir('source'); |
|
606 | - $this->assertTrue($this->instance->isUpdatable('source')); |
|
607 | - } |
|
608 | - |
|
609 | - public function testIsDeletable(): void { |
|
610 | - $this->instance->mkdir('source'); |
|
611 | - $this->assertTrue($this->instance->isDeletable('source')); |
|
612 | - } |
|
613 | - |
|
614 | - public function testIsShareable(): void { |
|
615 | - $this->instance->mkdir('source'); |
|
616 | - $this->assertTrue($this->instance->isSharable('source')); |
|
617 | - } |
|
618 | - |
|
619 | - public function testStatAfterWrite(): void { |
|
620 | - $this->instance->file_put_contents('foo.txt', 'bar'); |
|
621 | - $stat = $this->instance->stat('foo.txt'); |
|
622 | - $this->assertEquals(3, $stat['size']); |
|
623 | - |
|
624 | - $fh = $this->instance->fopen('foo.txt', 'w'); |
|
625 | - fwrite($fh, 'qwerty'); |
|
626 | - fclose($fh); |
|
627 | - |
|
628 | - $stat = $this->instance->stat('foo.txt'); |
|
629 | - $this->assertEquals(6, $stat['size']); |
|
630 | - } |
|
631 | - |
|
632 | - public function testPartFile(): void { |
|
633 | - $this->instance->file_put_contents('bar.txt.part', 'bar'); |
|
634 | - $this->instance->rename('bar.txt.part', 'bar.txt'); |
|
635 | - $this->assertEquals('bar', $this->instance->file_get_contents('bar.txt')); |
|
636 | - } |
|
637 | - |
|
638 | - public function testWriteStream(): void { |
|
639 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
640 | - |
|
641 | - if (!$this->instance->instanceOfStorage(IWriteStreamStorage::class)) { |
|
642 | - $this->markTestSkipped('Not a WriteSteamStorage'); |
|
643 | - } |
|
644 | - /** @var IWriteStreamStorage $storage */ |
|
645 | - $storage = $this->instance; |
|
646 | - |
|
647 | - $source = fopen($textFile, 'r'); |
|
648 | - |
|
649 | - $storage->writeStream('test.txt', $source); |
|
650 | - $this->assertTrue($storage->file_exists('test.txt')); |
|
651 | - $this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt')); |
|
652 | - $this->assertEquals('resource (closed)', gettype($source)); |
|
653 | - } |
|
654 | - |
|
655 | - public function testFseekSize(): void { |
|
656 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
657 | - $this->instance->file_put_contents('bar.txt', file_get_contents($textFile)); |
|
658 | - |
|
659 | - $size = $this->instance->filesize('bar.txt'); |
|
660 | - $this->assertEquals(filesize($textFile), $size); |
|
661 | - $fh = $this->instance->fopen('bar.txt', 'r'); |
|
662 | - |
|
663 | - fseek($fh, 0, SEEK_END); |
|
664 | - $pos = ftell($fh); |
|
665 | - |
|
666 | - $this->assertEquals($size, $pos); |
|
667 | - } |
|
15 | + /** |
|
16 | + * @var \OC\Files\Storage\Storage instance |
|
17 | + */ |
|
18 | + protected $instance; |
|
19 | + protected $waitDelay = 0; |
|
20 | + |
|
21 | + /** |
|
22 | + * Sleep for the number of seconds specified in the |
|
23 | + * $waitDelay attribute |
|
24 | + */ |
|
25 | + protected function wait() { |
|
26 | + if ($this->waitDelay > 0) { |
|
27 | + sleep($this->waitDelay); |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * the root folder of the storage should always exist, be readable and be recognized as a directory |
|
33 | + */ |
|
34 | + public function testRoot(): void { |
|
35 | + $this->assertTrue($this->instance->file_exists('/'), 'Root folder does not exist'); |
|
36 | + $this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable'); |
|
37 | + $this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory'); |
|
38 | + $this->assertFalse($this->instance->is_file('/'), 'Root folder is a file'); |
|
39 | + $this->assertEquals('dir', $this->instance->filetype('/')); |
|
40 | + |
|
41 | + //without this, any further testing would be useless, not an actual requirement for filestorage though |
|
42 | + $this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable'); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Check that the test() function works |
|
47 | + */ |
|
48 | + public function testTestFunction(): void { |
|
49 | + $this->assertTrue($this->instance->test()); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @dataProvider directoryProvider |
|
54 | + */ |
|
55 | + public function testDirectories($directory): void { |
|
56 | + $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
57 | + |
|
58 | + $this->assertTrue($this->instance->mkdir('/' . $directory)); |
|
59 | + |
|
60 | + $this->assertTrue($this->instance->file_exists('/' . $directory)); |
|
61 | + $this->assertTrue($this->instance->is_dir('/' . $directory)); |
|
62 | + $this->assertFalse($this->instance->is_file('/' . $directory)); |
|
63 | + $this->assertEquals('dir', $this->instance->filetype('/' . $directory)); |
|
64 | + $this->assertEquals(0, $this->instance->filesize('/' . $directory)); |
|
65 | + $this->assertTrue($this->instance->isReadable('/' . $directory)); |
|
66 | + $this->assertTrue($this->instance->isUpdatable('/' . $directory)); |
|
67 | + |
|
68 | + $dh = $this->instance->opendir('/'); |
|
69 | + $content = []; |
|
70 | + while (($file = readdir($dh)) !== false) { |
|
71 | + if ($file != '.' and $file != '..') { |
|
72 | + $content[] = $file; |
|
73 | + } |
|
74 | + } |
|
75 | + $this->assertEquals([$directory], $content); |
|
76 | + |
|
77 | + $content = iterator_to_array($this->instance->getDirectoryContent('/')); |
|
78 | + |
|
79 | + $this->assertCount(1, $content); |
|
80 | + $dirEntry = $content[0]; |
|
81 | + unset($dirEntry['scan_permissions']); |
|
82 | + unset($dirEntry['etag']); |
|
83 | + $this->assertLessThanOrEqual(1, abs($dirEntry['mtime'] - $this->instance->filemtime($directory))); |
|
84 | + unset($dirEntry['mtime']); |
|
85 | + unset($dirEntry['storage_mtime']); |
|
86 | + $this->assertEquals([ |
|
87 | + 'name' => $directory, |
|
88 | + 'mimetype' => $this->instance->getMimeType($directory), |
|
89 | + 'size' => -1, |
|
90 | + 'permissions' => $this->instance->getPermissions($directory), |
|
91 | + ], $dirEntry); |
|
92 | + |
|
93 | + $this->assertFalse($this->instance->mkdir('/' . $directory)); //can't create existing folders |
|
94 | + $this->assertTrue($this->instance->rmdir('/' . $directory)); |
|
95 | + |
|
96 | + $this->wait(); |
|
97 | + $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
98 | + |
|
99 | + $this->assertFalse($this->instance->rmdir('/' . $directory)); //can't remove non existing folders |
|
100 | + |
|
101 | + $dh = $this->instance->opendir('/'); |
|
102 | + $content = []; |
|
103 | + while (($file = readdir($dh)) !== false) { |
|
104 | + if ($file != '.' and $file != '..') { |
|
105 | + $content[] = $file; |
|
106 | + } |
|
107 | + } |
|
108 | + $this->assertEquals([], $content); |
|
109 | + } |
|
110 | + |
|
111 | + public static function fileNameProvider(): array { |
|
112 | + return [ |
|
113 | + ['file.txt'], |
|
114 | + [' file.txt'], |
|
115 | + ['folder .txt'], |
|
116 | + ['file with space.txt'], |
|
117 | + ['spéciäl fäile'], |
|
118 | + ['test single\'quote.txt'], |
|
119 | + ]; |
|
120 | + } |
|
121 | + |
|
122 | + public static function directoryProvider(): array { |
|
123 | + return [ |
|
124 | + ['folder'], |
|
125 | + [' folder'], |
|
126 | + ['folder '], |
|
127 | + ['folder with space'], |
|
128 | + ['spéciäl földer'], |
|
129 | + ['test single\'quote'], |
|
130 | + ]; |
|
131 | + } |
|
132 | + |
|
133 | + public static function loremFileProvider(): array { |
|
134 | + $root = \OC::$SERVERROOT . '/tests/data/'; |
|
135 | + return [ |
|
136 | + // small file |
|
137 | + [$root . 'lorem.txt'], |
|
138 | + // bigger file (> 8 KB which is the standard PHP block size) |
|
139 | + [$root . 'lorem-big.txt'] |
|
140 | + ]; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * test the various uses of file_get_contents and file_put_contents |
|
145 | + * |
|
146 | + * @dataProvider loremFileProvider |
|
147 | + */ |
|
148 | + public function testGetPutContents($sourceFile): void { |
|
149 | + $sourceText = file_get_contents($sourceFile); |
|
150 | + |
|
151 | + //fill a file with string data |
|
152 | + $this->instance->file_put_contents('/lorem.txt', $sourceText); |
|
153 | + $this->assertFalse($this->instance->is_dir('/lorem.txt')); |
|
154 | + $this->assertEquals($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); |
|
155 | + |
|
156 | + //empty the file |
|
157 | + $this->instance->file_put_contents('/lorem.txt', ''); |
|
158 | + $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * test various known mimetypes |
|
163 | + */ |
|
164 | + public function testMimeType(): void { |
|
165 | + $this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/')); |
|
166 | + $this->assertEquals(false, $this->instance->getMimeType('/non/existing/file')); |
|
167 | + |
|
168 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
169 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); |
|
170 | + $this->assertEquals('text/plain', $this->instance->getMimeType('/lorem.txt')); |
|
171 | + |
|
172 | + $pngFile = \OC::$SERVERROOT . '/tests/data/desktopapp.png'; |
|
173 | + $this->instance->file_put_contents('/desktopapp.png', file_get_contents($pngFile, 'r')); |
|
174 | + $this->assertEquals('image/png', $this->instance->getMimeType('/desktopapp.png')); |
|
175 | + |
|
176 | + $svgFile = \OC::$SERVERROOT . '/tests/data/desktopapp.svg'; |
|
177 | + $this->instance->file_put_contents('/desktopapp.svg', file_get_contents($svgFile, 'r')); |
|
178 | + $this->assertEquals('image/svg+xml', $this->instance->getMimeType('/desktopapp.svg')); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + public static function copyAndMoveProvider(): array { |
|
183 | + return [ |
|
184 | + ['/source.txt', '/target.txt'], |
|
185 | + ['/source.txt', '/target with space.txt'], |
|
186 | + ['/source with space.txt', '/target.txt'], |
|
187 | + ['/source with space.txt', '/target with space.txt'], |
|
188 | + ['/source.txt', '/tärgét.txt'], |
|
189 | + ['/sòurcē.txt', '/target.txt'], |
|
190 | + ['/sòurcē.txt', '/tärgét.txt'], |
|
191 | + ['/single \' quote.txt', '/tar\'get.txt'], |
|
192 | + ]; |
|
193 | + } |
|
194 | + |
|
195 | + public function initSourceAndTarget($source, $target = null) { |
|
196 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
197 | + $this->instance->file_put_contents($source, file_get_contents($textFile)); |
|
198 | + if ($target) { |
|
199 | + $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
200 | + $this->instance->file_put_contents($target, $testContents); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + public function assertSameAsLorem($file) { |
|
205 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
206 | + $this->assertEquals( |
|
207 | + file_get_contents($textFile), |
|
208 | + $this->instance->file_get_contents($file), |
|
209 | + 'Expected ' . $file . ' to be a copy of ' . $textFile |
|
210 | + ); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @dataProvider copyAndMoveProvider |
|
215 | + */ |
|
216 | + public function testCopy($source, $target): void { |
|
217 | + $this->initSourceAndTarget($source); |
|
218 | + |
|
219 | + $this->instance->copy($source, $target); |
|
220 | + |
|
221 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
222 | + $this->assertSameAsLorem($target); |
|
223 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @dataProvider copyAndMoveProvider |
|
228 | + */ |
|
229 | + public function testMove($source, $target): void { |
|
230 | + $this->initSourceAndTarget($source); |
|
231 | + |
|
232 | + $this->instance->rename($source, $target); |
|
233 | + |
|
234 | + $this->wait(); |
|
235 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
236 | + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
237 | + $this->assertSameAsLorem($target); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @dataProvider copyAndMoveProvider |
|
242 | + */ |
|
243 | + public function testCopyOverwrite($source, $target): void { |
|
244 | + $this->initSourceAndTarget($source, $target); |
|
245 | + |
|
246 | + $this->instance->copy($source, $target); |
|
247 | + |
|
248 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
249 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
250 | + $this->assertSameAsLorem($target); |
|
251 | + $this->assertSameAsLorem($source); |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * @dataProvider copyAndMoveProvider |
|
256 | + */ |
|
257 | + public function testMoveOverwrite($source, $target): void { |
|
258 | + $this->initSourceAndTarget($source, $target); |
|
259 | + |
|
260 | + $this->instance->rename($source, $target); |
|
261 | + |
|
262 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
263 | + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
264 | + $this->assertSameAsLorem($target); |
|
265 | + } |
|
266 | + |
|
267 | + public function testLocal(): void { |
|
268 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
269 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
270 | + $localFile = $this->instance->getLocalFile('/lorem.txt'); |
|
271 | + $this->assertTrue(file_exists($localFile)); |
|
272 | + $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile)); |
|
273 | + |
|
274 | + $this->instance->mkdir('/folder'); |
|
275 | + $this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile)); |
|
276 | + $this->instance->file_put_contents('/folder/bar.txt', 'asd'); |
|
277 | + $this->instance->mkdir('/folder/recursive'); |
|
278 | + $this->instance->file_put_contents('/folder/recursive/file.txt', 'foo'); |
|
279 | + |
|
280 | + // test below require to use instance->getLocalFile because the physical storage might be different |
|
281 | + $localFile = $this->instance->getLocalFile('/folder/lorem.txt'); |
|
282 | + $this->assertTrue(file_exists($localFile)); |
|
283 | + $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile)); |
|
284 | + |
|
285 | + $localFile = $this->instance->getLocalFile('/folder/bar.txt'); |
|
286 | + $this->assertTrue(file_exists($localFile)); |
|
287 | + $this->assertEquals(file_get_contents($localFile), 'asd'); |
|
288 | + |
|
289 | + $localFile = $this->instance->getLocalFile('/folder/recursive/file.txt'); |
|
290 | + $this->assertTrue(file_exists($localFile)); |
|
291 | + $this->assertEquals(file_get_contents($localFile), 'foo'); |
|
292 | + } |
|
293 | + |
|
294 | + public function testStat(): void { |
|
295 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
296 | + $ctimeStart = time(); |
|
297 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
298 | + $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
299 | + $ctimeEnd = time(); |
|
300 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
301 | + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
302 | + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); |
|
303 | + |
|
304 | + // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
305 | + $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
306 | + $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
307 | + $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
308 | + |
|
309 | + $stat = $this->instance->stat('/lorem.txt'); |
|
310 | + //only size and mtime are required in the result |
|
311 | + $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
312 | + $this->assertEquals($stat['mtime'], $mTime); |
|
313 | + |
|
314 | + if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
315 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
316 | + $this->assertEquals($mTime, 100); |
|
317 | + } |
|
318 | + |
|
319 | + $mtimeStart = time(); |
|
320 | + |
|
321 | + $this->instance->unlink('/lorem.txt'); |
|
322 | + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Test whether checkUpdate properly returns false when there was |
|
327 | + * no change. |
|
328 | + */ |
|
329 | + public function testCheckUpdate(): void { |
|
330 | + if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) { |
|
331 | + $this->markTestSkipped('Cannot test update check on wrappers'); |
|
332 | + } |
|
333 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
334 | + $watcher = $this->instance->getWatcher(); |
|
335 | + $watcher->setPolicy(Watcher::CHECK_ALWAYS); |
|
336 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
337 | + $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected'); |
|
338 | + $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update'); |
|
339 | + } |
|
340 | + |
|
341 | + public function testUnlink(): void { |
|
342 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
343 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
344 | + |
|
345 | + $this->assertTrue($this->instance->file_exists('/lorem.txt')); |
|
346 | + |
|
347 | + $this->assertTrue($this->instance->unlink('/lorem.txt')); |
|
348 | + $this->wait(); |
|
349 | + |
|
350 | + $this->assertFalse($this->instance->file_exists('/lorem.txt')); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * @dataProvider fileNameProvider |
|
355 | + */ |
|
356 | + public function testFOpen($fileName): void { |
|
357 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
358 | + |
|
359 | + $fh = @$this->instance->fopen($fileName, 'r'); |
|
360 | + if ($fh) { |
|
361 | + fclose($fh); |
|
362 | + } |
|
363 | + $this->assertFalse($fh); |
|
364 | + $this->assertFalse($this->instance->file_exists($fileName)); |
|
365 | + |
|
366 | + $fh = $this->instance->fopen($fileName, 'w'); |
|
367 | + fwrite($fh, file_get_contents($textFile)); |
|
368 | + fclose($fh); |
|
369 | + $this->assertTrue($this->instance->file_exists($fileName)); |
|
370 | + |
|
371 | + $fh = $this->instance->fopen($fileName, 'r'); |
|
372 | + $content = stream_get_contents($fh); |
|
373 | + $this->assertEquals(file_get_contents($textFile), $content); |
|
374 | + } |
|
375 | + |
|
376 | + public function testTouchCreateFile(): void { |
|
377 | + $this->assertFalse($this->instance->file_exists('touch')); |
|
378 | + // returns true on success |
|
379 | + $this->assertTrue($this->instance->touch('touch')); |
|
380 | + $this->assertTrue($this->instance->file_exists('touch')); |
|
381 | + } |
|
382 | + |
|
383 | + public function testRecursiveRmdir(): void { |
|
384 | + $this->instance->mkdir('folder'); |
|
385 | + $this->instance->mkdir('folder/bar'); |
|
386 | + $this->wait(); |
|
387 | + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
388 | + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
389 | + $this->assertTrue($this->instance->rmdir('folder')); |
|
390 | + $this->wait(); |
|
391 | + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
392 | + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
393 | + $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
394 | + $this->assertFalse($this->instance->file_exists('folder')); |
|
395 | + } |
|
396 | + |
|
397 | + public function testRmdirEmptyFolder(): void { |
|
398 | + $this->assertTrue($this->instance->mkdir('empty')); |
|
399 | + $this->wait(); |
|
400 | + $this->assertTrue($this->instance->rmdir('empty')); |
|
401 | + $this->assertFalse($this->instance->file_exists('empty')); |
|
402 | + } |
|
403 | + |
|
404 | + public function testRecursiveUnlink(): void { |
|
405 | + $this->instance->mkdir('folder'); |
|
406 | + $this->instance->mkdir('folder/bar'); |
|
407 | + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
408 | + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
409 | + $this->assertTrue($this->instance->unlink('folder')); |
|
410 | + $this->wait(); |
|
411 | + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
412 | + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
413 | + $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
414 | + $this->assertFalse($this->instance->file_exists('folder')); |
|
415 | + } |
|
416 | + |
|
417 | + public static function hashProvider(): array { |
|
418 | + return [ |
|
419 | + ['Foobar', 'md5'], |
|
420 | + ['Foobar', 'sha1'], |
|
421 | + ['Foobar', 'sha256'], |
|
422 | + ]; |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * @dataProvider hashProvider |
|
427 | + */ |
|
428 | + public function testHash($data, $type): void { |
|
429 | + $this->instance->file_put_contents('hash.txt', $data); |
|
430 | + $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); |
|
431 | + $this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true)); |
|
432 | + } |
|
433 | + |
|
434 | + public function testHashInFileName(): void { |
|
435 | + $this->instance->file_put_contents('#test.txt', 'data'); |
|
436 | + $this->assertEquals('data', $this->instance->file_get_contents('#test.txt')); |
|
437 | + |
|
438 | + $this->instance->mkdir('#foo'); |
|
439 | + $this->instance->file_put_contents('#foo/test.txt', 'data'); |
|
440 | + $this->assertEquals('data', $this->instance->file_get_contents('#foo/test.txt')); |
|
441 | + |
|
442 | + $dh = $this->instance->opendir('#foo'); |
|
443 | + $content = []; |
|
444 | + while ($file = readdir($dh)) { |
|
445 | + if ($file != '.' and $file != '..') { |
|
446 | + $content[] = $file; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + $this->assertEquals(['test.txt'], $content); |
|
451 | + } |
|
452 | + |
|
453 | + public function testCopyOverWriteFile(): void { |
|
454 | + $this->instance->file_put_contents('target.txt', 'foo'); |
|
455 | + $this->instance->file_put_contents('source.txt', 'bar'); |
|
456 | + $this->instance->copy('source.txt', 'target.txt'); |
|
457 | + $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
458 | + } |
|
459 | + |
|
460 | + public function testRenameOverWriteFile(): void { |
|
461 | + $this->instance->file_put_contents('target.txt', 'foo'); |
|
462 | + $this->instance->file_put_contents('source.txt', 'bar'); |
|
463 | + $this->instance->rename('source.txt', 'target.txt'); |
|
464 | + $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
465 | + $this->assertFalse($this->instance->file_exists('source.txt')); |
|
466 | + } |
|
467 | + |
|
468 | + public function testRenameDirectory(): void { |
|
469 | + $this->instance->mkdir('source'); |
|
470 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
471 | + $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
472 | + $this->instance->mkdir('source/subfolder'); |
|
473 | + $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
474 | + $this->instance->rename('source', 'target'); |
|
475 | + |
|
476 | + $this->assertFalse($this->instance->file_exists('source')); |
|
477 | + $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
478 | + $this->assertFalse($this->instance->file_exists('source/test2.txt')); |
|
479 | + $this->assertFalse($this->instance->file_exists('source/subfolder')); |
|
480 | + $this->assertFalse($this->instance->file_exists('source/subfolder/test.txt')); |
|
481 | + |
|
482 | + $this->assertTrue($this->instance->file_exists('target')); |
|
483 | + $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
484 | + $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
485 | + $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
486 | + $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
487 | + |
|
488 | + $contents = iterator_to_array($this->instance->getDirectoryContent('')); |
|
489 | + $this->assertCount(1, $contents); |
|
490 | + |
|
491 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
492 | + $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
493 | + $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
494 | + } |
|
495 | + |
|
496 | + public function testRenameOverWriteDirectory(): void { |
|
497 | + $this->instance->mkdir('source'); |
|
498 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
499 | + |
|
500 | + $this->instance->mkdir('target'); |
|
501 | + $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
502 | + $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
503 | + |
|
504 | + $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
505 | + |
|
506 | + $this->assertFalse($this->instance->file_exists('source'), 'source has not been removed'); |
|
507 | + $this->assertFalse($this->instance->file_exists('source/test1.txt'), 'source/test1.txt has not been removed'); |
|
508 | + $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'target/test2.txt has not been removed'); |
|
509 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'), 'target/test1.txt has not been overwritten'); |
|
510 | + } |
|
511 | + |
|
512 | + public function testRenameOverWriteDirectoryOverFile(): void { |
|
513 | + $this->instance->mkdir('source'); |
|
514 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
515 | + |
|
516 | + $this->instance->file_put_contents('target', 'bar'); |
|
517 | + |
|
518 | + $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
519 | + |
|
520 | + $this->assertFalse($this->instance->file_exists('source')); |
|
521 | + $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
522 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
523 | + } |
|
524 | + |
|
525 | + public function testCopyDirectory(): void { |
|
526 | + $this->instance->mkdir('source'); |
|
527 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
528 | + $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
529 | + $this->instance->mkdir('source/subfolder'); |
|
530 | + $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
531 | + $this->instance->copy('source', 'target'); |
|
532 | + |
|
533 | + $this->assertTrue($this->instance->file_exists('source')); |
|
534 | + $this->assertTrue($this->instance->file_exists('source/test1.txt')); |
|
535 | + $this->assertTrue($this->instance->file_exists('source/test2.txt')); |
|
536 | + $this->assertTrue($this->instance->file_exists('source/subfolder')); |
|
537 | + $this->assertTrue($this->instance->file_exists('source/subfolder/test.txt')); |
|
538 | + |
|
539 | + $this->assertTrue($this->instance->file_exists('target')); |
|
540 | + $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
541 | + $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
542 | + $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
543 | + $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
544 | + |
|
545 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
546 | + $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
547 | + $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
548 | + } |
|
549 | + |
|
550 | + public function testCopyOverWriteDirectory(): void { |
|
551 | + $this->instance->mkdir('source'); |
|
552 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
553 | + |
|
554 | + $this->instance->mkdir('target'); |
|
555 | + $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
556 | + $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
557 | + |
|
558 | + $this->instance->copy('source', 'target'); |
|
559 | + |
|
560 | + $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does'); |
|
561 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
562 | + } |
|
563 | + |
|
564 | + public function testCopyOverWriteDirectoryOverFile(): void { |
|
565 | + $this->instance->mkdir('source'); |
|
566 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
567 | + |
|
568 | + $this->instance->file_put_contents('target', 'bar'); |
|
569 | + |
|
570 | + $this->instance->copy('source', 'target'); |
|
571 | + |
|
572 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
573 | + } |
|
574 | + |
|
575 | + public function testInstanceOfStorage(): void { |
|
576 | + $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); |
|
577 | + $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); |
|
578 | + $this->assertFalse($this->instance->instanceOfStorage('\OC')); |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * @dataProvider copyAndMoveProvider |
|
583 | + */ |
|
584 | + public function testCopyFromSameStorage($source, $target): void { |
|
585 | + $this->initSourceAndTarget($source); |
|
586 | + |
|
587 | + $this->instance->copyFromStorage($this->instance, $source, $target); |
|
588 | + |
|
589 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
590 | + $this->assertSameAsLorem($target); |
|
591 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
592 | + } |
|
593 | + |
|
594 | + public function testIsCreatable(): void { |
|
595 | + $this->instance->mkdir('source'); |
|
596 | + $this->assertTrue($this->instance->isCreatable('source')); |
|
597 | + } |
|
598 | + |
|
599 | + public function testIsReadable(): void { |
|
600 | + $this->instance->mkdir('source'); |
|
601 | + $this->assertTrue($this->instance->isReadable('source')); |
|
602 | + } |
|
603 | + |
|
604 | + public function testIsUpdatable(): void { |
|
605 | + $this->instance->mkdir('source'); |
|
606 | + $this->assertTrue($this->instance->isUpdatable('source')); |
|
607 | + } |
|
608 | + |
|
609 | + public function testIsDeletable(): void { |
|
610 | + $this->instance->mkdir('source'); |
|
611 | + $this->assertTrue($this->instance->isDeletable('source')); |
|
612 | + } |
|
613 | + |
|
614 | + public function testIsShareable(): void { |
|
615 | + $this->instance->mkdir('source'); |
|
616 | + $this->assertTrue($this->instance->isSharable('source')); |
|
617 | + } |
|
618 | + |
|
619 | + public function testStatAfterWrite(): void { |
|
620 | + $this->instance->file_put_contents('foo.txt', 'bar'); |
|
621 | + $stat = $this->instance->stat('foo.txt'); |
|
622 | + $this->assertEquals(3, $stat['size']); |
|
623 | + |
|
624 | + $fh = $this->instance->fopen('foo.txt', 'w'); |
|
625 | + fwrite($fh, 'qwerty'); |
|
626 | + fclose($fh); |
|
627 | + |
|
628 | + $stat = $this->instance->stat('foo.txt'); |
|
629 | + $this->assertEquals(6, $stat['size']); |
|
630 | + } |
|
631 | + |
|
632 | + public function testPartFile(): void { |
|
633 | + $this->instance->file_put_contents('bar.txt.part', 'bar'); |
|
634 | + $this->instance->rename('bar.txt.part', 'bar.txt'); |
|
635 | + $this->assertEquals('bar', $this->instance->file_get_contents('bar.txt')); |
|
636 | + } |
|
637 | + |
|
638 | + public function testWriteStream(): void { |
|
639 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
640 | + |
|
641 | + if (!$this->instance->instanceOfStorage(IWriteStreamStorage::class)) { |
|
642 | + $this->markTestSkipped('Not a WriteSteamStorage'); |
|
643 | + } |
|
644 | + /** @var IWriteStreamStorage $storage */ |
|
645 | + $storage = $this->instance; |
|
646 | + |
|
647 | + $source = fopen($textFile, 'r'); |
|
648 | + |
|
649 | + $storage->writeStream('test.txt', $source); |
|
650 | + $this->assertTrue($storage->file_exists('test.txt')); |
|
651 | + $this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt')); |
|
652 | + $this->assertEquals('resource (closed)', gettype($source)); |
|
653 | + } |
|
654 | + |
|
655 | + public function testFseekSize(): void { |
|
656 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
657 | + $this->instance->file_put_contents('bar.txt', file_get_contents($textFile)); |
|
658 | + |
|
659 | + $size = $this->instance->filesize('bar.txt'); |
|
660 | + $this->assertEquals(filesize($textFile), $size); |
|
661 | + $fh = $this->instance->fopen('bar.txt', 'r'); |
|
662 | + |
|
663 | + fseek($fh, 0, SEEK_END); |
|
664 | + $pos = ftell($fh); |
|
665 | + |
|
666 | + $this->assertEquals($size, $pos); |
|
667 | + } |
|
668 | 668 | } |
@@ -8,18 +8,18 @@ |
||
8 | 8 | require_once __DIR__ . '/../lib/base.php'; |
9 | 9 | |
10 | 10 | function enableApp($app) { |
11 | - try { |
|
12 | - (new \OC_App())->enable($app); |
|
13 | - } catch (Exception $e) { |
|
14 | - echo $e; |
|
15 | - } |
|
11 | + try { |
|
12 | + (new \OC_App())->enable($app); |
|
13 | + } catch (Exception $e) { |
|
14 | + echo $e; |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | foreach (new \DirectoryIterator(__DIR__ . '/../apps/') as $file) { |
19 | - if ($file->isDot()) { |
|
20 | - continue; |
|
21 | - } |
|
22 | - if (!file_exists($file->getPathname() . '/.git')) { |
|
23 | - enableApp($file->getFilename()); |
|
24 | - } |
|
19 | + if ($file->isDot()) { |
|
20 | + continue; |
|
21 | + } |
|
22 | + if (!file_exists($file->getPathname() . '/.git')) { |
|
23 | + enableApp($file->getFilename()); |
|
24 | + } |
|
25 | 25 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * SPDX-License-Identifier: AGPL-3.0-or-later |
6 | 6 | */ |
7 | 7 | |
8 | -require_once __DIR__ . '/../lib/base.php'; |
|
8 | +require_once __DIR__.'/../lib/base.php'; |
|
9 | 9 | |
10 | 10 | function enableApp($app) { |
11 | 11 | try { |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | } |
16 | 16 | } |
17 | 17 | |
18 | -foreach (new \DirectoryIterator(__DIR__ . '/../apps/') as $file) { |
|
18 | +foreach (new \DirectoryIterator(__DIR__.'/../apps/') as $file) { |
|
19 | 19 | if ($file->isDot()) { |
20 | 20 | continue; |
21 | 21 | } |
22 | - if (!file_exists($file->getPathname() . '/.git')) { |
|
22 | + if (!file_exists($file->getPathname().'/.git')) { |
|
23 | 23 | enableApp($file->getFilename()); |
24 | 24 | } |
25 | 25 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | $configDir = getenv('CONFIG_DIR'); |
10 | 10 | if ($configDir) { |
11 | - define('PHPUNIT_CONFIG_DIR', $configDir); |
|
11 | + define('PHPUNIT_CONFIG_DIR', $configDir); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | require_once __DIR__ . '/../lib/base.php'; |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | |
19 | 19 | // load all apps |
20 | 20 | foreach (new \DirectoryIterator(__DIR__ . '/../apps/') as $file) { |
21 | - if ($file->isDot()) { |
|
22 | - continue; |
|
23 | - } |
|
24 | - \OC_App::loadApp($file->getFilename()); |
|
21 | + if ($file->isDot()) { |
|
22 | + continue; |
|
23 | + } |
|
24 | + \OC_App::loadApp($file->getFilename()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | OC_Hook::clear(); |
28 | 28 | |
29 | 29 | set_include_path( |
30 | - get_include_path() . PATH_SEPARATOR |
|
31 | - . '/usr/share/php' . PATH_SEPARATOR |
|
32 | - . __DIR__ . '/..' |
|
30 | + get_include_path() . PATH_SEPARATOR |
|
31 | + . '/usr/share/php' . PATH_SEPARATOR |
|
32 | + . __DIR__ . '/..' |
|
33 | 33 | ); |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | define('PHPUNIT_CONFIG_DIR', $configDir); |
12 | 12 | } |
13 | 13 | |
14 | -require_once __DIR__ . '/../lib/base.php'; |
|
15 | -require_once __DIR__ . '/autoload.php'; |
|
14 | +require_once __DIR__.'/../lib/base.php'; |
|
15 | +require_once __DIR__.'/autoload.php'; |
|
16 | 16 | |
17 | -\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT . '/tests/', true); |
|
17 | +\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT.'/tests/', true); |
|
18 | 18 | |
19 | 19 | // load all apps |
20 | -foreach (new \DirectoryIterator(__DIR__ . '/../apps/') as $file) { |
|
20 | +foreach (new \DirectoryIterator(__DIR__.'/../apps/') as $file) { |
|
21 | 21 | if ($file->isDot()) { |
22 | 22 | continue; |
23 | 23 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | OC_Hook::clear(); |
28 | 28 | |
29 | 29 | set_include_path( |
30 | - get_include_path() . PATH_SEPARATOR |
|
31 | - . '/usr/share/php' . PATH_SEPARATOR |
|
32 | - . __DIR__ . '/..' |
|
30 | + get_include_path().PATH_SEPARATOR |
|
31 | + . '/usr/share/php'.PATH_SEPARATOR |
|
32 | + . __DIR__.'/..' |
|
33 | 33 | ); |