Skip to content

Commit 234b242

Browse files
committed
test: add tests for encryptedVersion cache entry preservation
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-sonnet-5
1 parent 57df4d8 commit 234b242

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/lib/Files/Cache/CacheTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,45 @@ public function testMoveFromCache() {
500500
$this->assertTrue($this->cache->inCache('targetfolder/sub'));
501501
}
502502

503+
public function testCopyFromCachePreservesEncryptedVersion(): void {
504+
$data = [
505+
'size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar',
506+
'encrypted' => true, 'encryptedVersion' => 3,
507+
];
508+
$this->cache->put('source', $data);
509+
$sourceEntry = $this->cache->get('source');
510+
$this->assertSame(3, $sourceEntry['encryptedVersion']);
511+
512+
$this->cache->copyFromCache($this->cache, $sourceEntry, 'target');
513+
514+
$targetEntry = $this->cache->get('target');
515+
$this->assertTrue($targetEntry->isEncrypted());
516+
$this->assertSame(3, $targetEntry['encryptedVersion']);
517+
}
518+
519+
public function testCopyFromCacheClearsEncryptedVersionWhenCopyingToNonEncryptedStorage(): void {
520+
$data = [
521+
'size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar',
522+
'encrypted' => true, 'encryptedVersion' => 3,
523+
];
524+
$this->cache2->put('source', $data);
525+
$sourceEntry = $this->cache2->get('source');
526+
527+
$sourceCache = $this->getMockBuilder(Cache::class)
528+
->setConstructorArgs([$this->storage2])
529+
->getMock();
530+
531+
$targetCache = $this->getMockBuilder(Cache::class)
532+
->setConstructorArgs([$this->storage])
533+
->getMock();
534+
535+
$targetCache->copyFromCache($sourceCache, $sourceEntry, 'target');
536+
537+
$targetEntry = $targetCache->get('target');
538+
$this->assertFalse($targetEntry->isEncrypted());
539+
$this->assertSame(0, $targetEntry['encryptedVersion']);
540+
}
541+
503542
public function testGetIncomplete() {
504543
$file1 = 'folder1';
505544
$file2 = 'folder2';

0 commit comments

Comments
 (0)