diff options
Diffstat (limited to 'tests/lib/Files/Cache/CacheTest.php')
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 204f87d6a18..383962b7224 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -11,13 +12,18 @@ use OC\Files\Cache\Cache; use OC\Files\Cache\CacheEntry; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; +use OC\Files\Storage\Temporary; +use OC\User\User; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchComparison; use OCP\IDBConnection; +use OCP\ITagManager; use OCP\IUser; +use OCP\IUserManager; +use OCP\Server; -class LongId extends \OC\Files\Storage\Temporary { +class LongId extends Temporary { public function getId(): string { return 'long:' . str_repeat('foo', 50) . parent::getId(); } @@ -32,23 +38,42 @@ class LongId extends \OC\Files\Storage\Temporary { */ class CacheTest extends \Test\TestCase { /** - * @var \OC\Files\Storage\Temporary $storage ; + * @var Temporary $storage ; */ protected $storage; /** - * @var \OC\Files\Storage\Temporary $storage2 ; + * @var Temporary $storage2 ; */ protected $storage2; /** - * @var \OC\Files\Cache\Cache $cache + * @var Cache $cache */ protected $cache; /** - * @var \OC\Files\Cache\Cache $cache2 + * @var Cache $cache2 */ protected $cache2; + protected function setUp(): void { + parent::setUp(); + + $this->storage = new Temporary([]); + $this->storage2 = new Temporary([]); + $this->cache = new Cache($this->storage); + $this->cache2 = new Cache($this->storage2); + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + } + + protected function tearDown(): void { + if ($this->cache) { + $this->cache->clear(); + } + + parent::tearDown(); + } + public function testGetNumericId(): void { $this->assertNotNull($this->cache->getNumericStorageId()); } @@ -137,14 +162,12 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(new CacheEntry(['size' => 12, 'mtime' => 15]), $this->cache->get($file1)); } - /** - * @dataProvider folderDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('folderDataProvider')] public function testFolder($folder): void { if (strpos($folder, 'F09F9890')) { // 4 byte UTF doesn't work on mysql - $params = \OC::$server->get(\OC\DB\Connection::class)->getParams(); - if (\OC::$server->getDatabaseConnection()->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL && $params['charset'] !== 'utf8mb4') { + $params = Server::get(\OC\DB\Connection::class)->getParams(); + if (Server::get(IDBConnection::class)->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL && $params['charset'] !== 'utf8mb4') { $this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8'); } } @@ -208,7 +231,7 @@ class CacheTest extends \Test\TestCase { } } - public function folderDataProvider() { + public static function folderDataProvider(): array { return [ ['folder'], // that was too easy, try something harder @@ -292,16 +315,16 @@ class CacheTest extends \Test\TestCase { } public function testStatus(): void { - $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo')); + $this->assertEquals(Cache::NOT_FOUND, $this->cache->getStatus('foo')); $this->cache->put('foo', ['size' => -1]); - $this->assertEquals(\OC\Files\Cache\Cache::PARTIAL, $this->cache->getStatus('foo')); + $this->assertEquals(Cache::PARTIAL, $this->cache->getStatus('foo')); $this->cache->put('foo', ['size' => -1, 'mtime' => 20, 'mimetype' => 'foo/file']); - $this->assertEquals(\OC\Files\Cache\Cache::SHALLOW, $this->cache->getStatus('foo')); + $this->assertEquals(Cache::SHALLOW, $this->cache->getStatus('foo')); $this->cache->put('foo', ['size' => 10]); - $this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo')); + $this->assertEquals(Cache::COMPLETE, $this->cache->getStatus('foo')); } - public function putWithAllKindOfQuotesData() { + public static function putWithAllKindOfQuotesData(): array { return [ ['`backtick`'], ['´forward´'], @@ -310,11 +333,11 @@ class CacheTest extends \Test\TestCase { } /** - * @dataProvider putWithAllKindOfQuotesData * @param $fileName */ + #[\PHPUnit\Framework\Attributes\DataProvider('putWithAllKindOfQuotesData')] public function testPutWithAllKindOfQuotes($fileName): void { - $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->get($fileName)); + $this->assertEquals(Cache::NOT_FOUND, $this->cache->get($fileName)); $this->cache->put($fileName, ['size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file', 'etag' => $fileName]); $cacheEntry = $this->cache->get($fileName); @@ -352,9 +375,9 @@ class CacheTest extends \Test\TestCase { public function testSearchQueryByTag(): void { $userId = static::getUniqueID('user'); - \OC::$server->getUserManager()->createUser($userId, $userId); + Server::get(IUserManager::class)->createUser($userId, $userId); static::loginAsUser($userId); - $user = new \OC\User\User($userId, null, \OC::$server->get(IEventDispatcher::class)); + $user = new User($userId, null, Server::get(IEventDispatcher::class)); $file1 = 'folder'; $file2 = 'folder/foobar'; @@ -374,7 +397,7 @@ class CacheTest extends \Test\TestCase { $id4 = $this->cache->put($file4, $fileData['foo2']); $id5 = $this->cache->put($file5, $fileData['foo3']); - $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId); + $tagManager = Server::get(ITagManager::class)->load('files', [], false, $userId); $this->assertTrue($tagManager->tagAs($id1, 'tag1')); $this->assertTrue($tagManager->tagAs($id1, 'tag2')); $this->assertTrue($tagManager->tagAs($id2, 'tag2')); @@ -399,7 +422,7 @@ class CacheTest extends \Test\TestCase { $tagManager->delete('tag2'); static::logout(); - $user = \OC::$server->getUserManager()->get($userId); + $user = Server::get(IUserManager::class)->get($userId); if ($user !== null) { try { $user->delete(); @@ -437,7 +460,7 @@ class CacheTest extends \Test\TestCase { new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100), 10, 0, [], $user))); } - public function movePathProvider() { + public static function movePathProvider(): array { return [ ['folder/foo', 'folder/foobar', ['1', '2']], ['folder/foo', 'foo', ['1', '2']], @@ -445,9 +468,7 @@ class CacheTest extends \Test\TestCase { ]; } - /** - * @dataProvider movePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('movePathProvider')] public function testMove($sourceFolder, $targetFolder, $children): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar']; $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; @@ -531,7 +552,7 @@ class CacheTest extends \Test\TestCase { if (strlen($storageId) > 64) { $storageId = md5($storageId); } - $this->assertEquals([$storageId, 'foo'], \OC\Files\Cache\Cache::getById($id)); + $this->assertEquals([$storageId, 'foo'], Cache::getById($id)); } public function testStorageMTime(): void { @@ -558,7 +579,7 @@ class CacheTest extends \Test\TestCase { $storageId = $storage->getId(); $data = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file']; $id = $cache->put('foo', $data); - $this->assertEquals([md5($storageId), 'foo'], \OC\Files\Cache\Cache::getById($id)); + $this->assertEquals([md5($storageId), 'foo'], Cache::getById($id)); } /** @@ -572,10 +593,10 @@ class CacheTest extends \Test\TestCase { $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e"; /** - * @var \OC\Files\Cache\Cache | \PHPUnit\Framework\MockObject\MockObject $cacheMock + * @var Cache|\PHPUnit\Framework\MockObject\MockObject $cacheMock */ $cacheMock = $this->getMockBuilder(Cache::class) - ->setMethods(['normalize']) + ->onlyMethods(['normalize']) ->setConstructorArgs([$this->storage]) ->getMock(); @@ -646,7 +667,7 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(1, count($this->cache->getFolderContents('folder'))); } - public function bogusPathNamesProvider() { + public static function bogusPathNamesProvider(): array { return [ ['/bogus.txt', 'bogus.txt'], ['//bogus.txt', 'bogus.txt'], @@ -657,9 +678,8 @@ class CacheTest extends \Test\TestCase { /** * Test bogus paths with leading or doubled slashes - * - * @dataProvider bogusPathNamesProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('bogusPathNamesProvider')] public function testBogusPaths($bogusPath, $fixedBogusPath): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $parentId = $this->cache->getId(''); @@ -691,7 +711,7 @@ class CacheTest extends \Test\TestCase { $this->assertNotEquals($fileId, $fileId2); } - public function escapingProvider() { + public static function escapingProvider(): array { return [ ['foo'], ['o%'], @@ -701,8 +721,8 @@ class CacheTest extends \Test\TestCase { /** * @param string $name - * @dataProvider escapingProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('escapingProvider')] public function testEscaping($name): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain']; $this->cache->put($name, $data); @@ -807,23 +827,4 @@ class CacheTest extends \Test\TestCase { $this->cache->remove('sub'); } - - protected function tearDown(): void { - if ($this->cache) { - $this->cache->clear(); - } - - parent::tearDown(); - } - - protected function setUp(): void { - parent::setUp(); - - $this->storage = new \OC\Files\Storage\Temporary([]); - $this->storage2 = new \OC\Files\Storage\Temporary([]); - $this->cache = new \OC\Files\Cache\Cache($this->storage); - $this->cache2 = new \OC\Files\Cache\Cache($this->storage2); - $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); - $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); - } } |