aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Memcache/CADTrait.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Memcache/CADTrait.php')
-rw-r--r--lib/private/Memcache/CADTrait.php1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/private/Memcache/CADTrait.php b/lib/private/Memcache/CADTrait.php
index 3bf94246338..d0f6611c4f3 100644
--- a/lib/private/Memcache/CADTrait.php
+++ b/lib/private/Memcache/CADTrait.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
='#n82'>82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
<?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\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;

/**
 * @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;

	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 = \OC::$server->getUserFolder('simple');

		$this->folder = $this->parentFolder->newFolder('test');
		$this->simpleFolder = new SimpleFolder($this->folder);
	}

	public function testGetName() {
		$this->assertEquals('test', $this->simpleFolder->getName());
	}

	public function testDelete() {
		$this->assertTrue($this->parentFolder->nodeExists('test'));
		$this->simpleFolder->delete();
		$this->assertFalse($this->parentFolder->nodeExists('test'));
	}

	public function testFileExists() {
		$this->folder->newFile('exists');

		$this->assertFalse($this->simpleFolder->fileExists('not-exists'));
		$this->assertTrue($this->simpleFolder->fileExists('exists'));
	}

	public function testGetFile() {
		$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() {
		$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() {
		$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 testGetFolder() {
		$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() {
		$result = $this->simpleFolder->newFolder('folder');
		$this->assertInstanceOf(ISimpleFolder::class, $result);
		$result->newFile('file');

		$this->assertTrue($this->folder->nodeExists('folder'));
	}
}