Files
nextcloud-server-mirror/tests/lib/Files/SimpleFS/SimpleFolderTest.php
Ferdinand Thiessen 0f60ffaa98 fix(theming): remove outdated cache folders again
Since the theming app data was scoped into the "global" folder,
`ImageManager::cleanup()` listed the cache-buster folders through
`ISimpleFolder::getDirectoryListing()`, which only returns files. So
outdated cache folders were never removed.

Add `ISimpleFolder::getFolderListing()` to list the sub folders of a
simple folder and use it for the cleanup.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-10-29 17:21:37 +01:00

130 lines
3.6 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\File\SimpleFS;
use OC\Files\SimpleFS\SimpleFolder;
use OC\Files\Storage\Temporary;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Server;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
#[\PHPUnit\Framework\Attributes\Group('DB')]
class SimpleFolderTest extends \Test\TestCase {
use MountProviderTrait;
use UserTrait;
/** @var Folder */
private $folder;
/** @var Folder */
private $parentFolder;
/** @var SimpleFolder */
private $simpleFolder;
private $storage;
#[\Override]
protected function setUp(): void {
parent::setUp();
$this->storage = new Temporary([]);
$this->createUser('simple', 'simple');
$this->registerMount('simple', $this->storage, '/simple/files');
$this->loginAsUser('simple');
$this->parentFolder = Server::get(IRootFolder::class)->getUserFolder('simple');
$this->folder = $this->parentFolder->newFolder('test');
$this->simpleFolder = new SimpleFolder($this->folder);
}
public function testGetName(): void {
$this->assertEquals('test', $this->simpleFolder->getName());
}
public function testDelete(): void {
$this->assertTrue($this->parentFolder->nodeExists('test'));
$this->simpleFolder->delete();
$this->assertFalse($this->parentFolder->nodeExists('test'));
}
public function testFileExists(): void {
$this->folder->newFile('exists');
$this->assertFalse($this->simpleFolder->fileExists('not-exists'));
$this->assertTrue($this->simpleFolder->fileExists('exists'));
}
public function testGetFile(): void {
$this->folder->newFile('exists');
$result = $this->simpleFolder->getFile('exists');
$this->assertInstanceOf(ISimpleFile::class, $result);
$this->expectException(NotFoundException::class);
$this->simpleFolder->getFile('not-exists');
}
public function testNewFile(): void {
$result = $this->simpleFolder->newFile('file');
$this->assertInstanceOf(ISimpleFile::class, $result);
$this->assertFalse($this->folder->nodeExists('file'));
$result->putContent('bar');
$this->assertTrue($this->folder->nodeExists('file'));
$this->assertEquals('bar', $result->getContent());
}
public function testGetDirectoryListing(): void {
$this->folder->newFile('file1');
$this->folder->newFile('file2');
$result = $this->simpleFolder->getDirectoryListing();
$this->assertCount(2, $result);
$this->assertInstanceOf(ISimpleFile::class, $result[0]);
$this->assertInstanceOf(ISimpleFile::class, $result[1]);
}
public function testGetFolderListing(): void {
$this->folder->newFile('file1');
$this->folder->newFolder('folder1');
$this->folder->newFolder('folder2');
$result = $this->simpleFolder->getFolderListing();
$this->assertCount(2, $result);
$this->assertContainsOnlyInstancesOf(ISimpleFolder::class, $result);
$names = array_map(static fn (ISimpleFolder $folder): string => $folder->getName(), $result);
sort($names);
$this->assertEquals(['folder1', 'folder2'], $names);
}
public function testGetFolder(): void {
$this->folder->newFolder('exists');
$result = $this->simpleFolder->getFolder('exists');
$this->assertInstanceOf(ISimpleFolder::class, $result);
$this->expectException(NotFoundException::class);
$this->simpleFolder->getFolder('not-exists');
}
public function testNewFolder(): void {
$result = $this->simpleFolder->newFolder('folder');
$this->assertInstanceOf(ISimpleFolder::class, $result);
$result->newFile('file');
$this->assertTrue($this->folder->nodeExists('folder'));
}
}