From 5b37d6d9ff6bf6b99ba6dd25caab5a6ef5394598 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 16 Aug 2023 13:48:31 +0200 Subject: [PATCH 1/2] tests: Add test for CacheEntry getters Signed-off-by: Ferdinand Thiessen --- tests/lib/Files/Cache/CacheTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index a5086a3eb3c..1b5c8e6e5ff 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -98,6 +98,31 @@ class CacheTest extends \Test\TestCase { $this->assertEquals($cacheData1, $this->cache->get($id1)); } + public function testCacheEntryGetters() { + $file1 = 'foo'; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/file']; + + $id1 = $this->cache->put($file1, $data1); + $entry = $this->cache->get($file1); + + $this->assertEquals($entry->getId(), $id1); + $this->assertEquals($entry->getStorageId(), $this->cache->getNumericStorageId()); + $this->assertEquals($entry->getPath(), 'foo'); + $this->assertEquals($entry->getName(), 'foo'); + $this->assertEquals($entry->getMimeType(), 'foo/file'); + $this->assertEquals($entry->getMimePart(), 'foo'); + $this->assertEquals($entry->getSize(), 100); + $this->assertEquals($entry->getMTime(), 50); + $this->assertEquals($entry->getStorageMTime(), 50); + $this->assertEquals($entry->getEtag(), null); + $this->assertEquals($entry->getPermissions(), 0); + $this->assertEquals($entry->isEncrypted(), false); + $this->assertEquals($entry->getMetadataEtag(), null); + $this->assertEquals($entry->getCreationTime(), null); + $this->assertEquals($entry->getUploadTime(), null); + $this->assertEquals($entry->getUnencryptedSize(), 100); + } + public function testPartial() { $file1 = 'foo'; From 9c04c076228821d892346f5f35bbf74f4720d021 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 16 Aug 2023 14:12:40 +0200 Subject: [PATCH 2/2] fix: Prevent PHP warnings when optional CacheEntry attributes are unset Signed-off-by: Ferdinand Thiessen --- lib/private/Files/Cache/Cache.php | 2 +- lib/private/Files/Cache/CacheEntry.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index e2630879414..67d01bb6999 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -149,7 +149,7 @@ class Cache implements ICache { * get the stored metadata of a file or folder * * @param string | int $file either the path of a file or folder or the file id for a file or folder - * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache + * @return ICacheEntry|false the cache entry as array or false if the file is not found in the cache */ public function get($file) { $query = $this->getQueryBuilder(); diff --git a/lib/private/Files/Cache/CacheEntry.php b/lib/private/Files/Cache/CacheEntry.php index 3c93296ff62..ce9df2823c8 100644 --- a/lib/private/Files/Cache/CacheEntry.php +++ b/lib/private/Files/Cache/CacheEntry.php @@ -114,15 +114,15 @@ class CacheEntry implements ICacheEntry { } public function getMetadataEtag(): ?string { - return $this->data['metadata_etag']; + return $this->data['metadata_etag'] ?? null; } public function getCreationTime(): ?int { - return $this->data['creation_time']; + return $this->data['creation_time'] ?? null; } public function getUploadTime(): ?int { - return $this->data['upload_time']; + return $this->data['upload_time'] ?? null; } public function getData() {