2013-09-01 21:47:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Node;
|
|
|
|
|
|
|
|
use OC\Files\Node\Root;
|
|
|
|
use OC\Files\Storage\Temporary;
|
|
|
|
use OC\Files\View;
|
|
|
|
use OC\User\User;
|
2016-11-03 01:16:51 +03:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUserManager;
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2015-11-03 03:52:41 +03:00
|
|
|
/**
|
2016-05-20 16:38:20 +03:00
|
|
|
* Class IntegrationTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files\Node
|
|
|
|
*/
|
2016-05-19 09:41:01 +03:00
|
|
|
class IntegrationTest extends \Test\TestCase {
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\Node\Root $root
|
|
|
|
*/
|
|
|
|
private $root;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage[]
|
|
|
|
*/
|
|
|
|
private $storages;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View $view
|
|
|
|
*/
|
|
|
|
private $view;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-12 17:54:41 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$manager = \OC\Files\Filesystem::getMountManager();
|
|
|
|
|
|
|
|
\OC_Hook::clear('OC_Filesystem');
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
$user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy, \OC::$server->getEventDispatcher());
|
2015-04-08 13:03:55 +03:00
|
|
|
$this->loginAsUser($user->getUID());
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->view = new View();
|
2016-11-03 01:16:51 +03:00
|
|
|
$this->root = new Root(
|
|
|
|
$manager,
|
|
|
|
$this->view,
|
|
|
|
$user,
|
|
|
|
\OC::$server->getUserMountCache(),
|
|
|
|
$this->createMock(ILogger::class),
|
|
|
|
$this->createMock(IUserManager::class)
|
|
|
|
);
|
2013-09-01 21:47:48 +04:00
|
|
|
$storage = new Temporary(array());
|
|
|
|
$subStorage = new Temporary(array());
|
|
|
|
$this->storages[] = $storage;
|
|
|
|
$this->storages[] = $subStorage;
|
|
|
|
$this->root->mount($storage, '/');
|
|
|
|
$this->root->mount($subStorage, '/substorage/');
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2013-09-01 21:47:48 +04:00
|
|
|
foreach ($this->storages as $storage) {
|
|
|
|
$storage->getCache()->clear();
|
|
|
|
}
|
2014-11-12 17:54:41 +03:00
|
|
|
|
2015-04-08 13:03:55 +03:00
|
|
|
$this->logout();
|
2014-11-12 17:54:41 +03:00
|
|
|
parent::tearDown();
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicFile() {
|
|
|
|
$file = $this->root->newFile('/foo.txt');
|
|
|
|
$this->assertCount(2, $this->root->getDirectoryListing());
|
|
|
|
$this->assertTrue($this->root->nodeExists('/foo.txt'));
|
|
|
|
$id = $file->getId();
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $file);
|
|
|
|
$file->putContent('qwerty');
|
|
|
|
$this->assertEquals('text/plain', $file->getMimeType());
|
|
|
|
$this->assertEquals('qwerty', $file->getContent());
|
|
|
|
$this->assertFalse($this->root->nodeExists('/bar.txt'));
|
2015-01-26 16:51:27 +03:00
|
|
|
$target = $file->move('/bar.txt');
|
|
|
|
$this->assertEquals($id, $target->getId());
|
|
|
|
$this->assertEquals($id, $file->getId());
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->assertFalse($this->root->nodeExists('/foo.txt'));
|
|
|
|
$this->assertTrue($this->root->nodeExists('/bar.txt'));
|
|
|
|
$this->assertEquals('bar.txt', $file->getName());
|
|
|
|
$this->assertEquals('bar.txt', $file->getInternalPath());
|
|
|
|
|
|
|
|
$file->move('/substorage/bar.txt');
|
2015-04-09 16:13:56 +03:00
|
|
|
$this->assertEquals($id, $file->getId());
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->assertEquals('qwerty', $file->getContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicFolder() {
|
|
|
|
$folder = $this->root->newFolder('/foo');
|
|
|
|
$this->assertTrue($this->root->nodeExists('/foo'));
|
|
|
|
$file = $folder->newFile('/bar');
|
|
|
|
$this->assertTrue($this->root->nodeExists('/foo/bar'));
|
|
|
|
$file->putContent('qwerty');
|
|
|
|
|
|
|
|
$listing = $folder->getDirectoryListing();
|
|
|
|
$this->assertEquals(1, count($listing));
|
|
|
|
$this->assertEquals($file->getId(), $listing[0]->getId());
|
|
|
|
$this->assertEquals($file->getStorage(), $listing[0]->getStorage());
|
|
|
|
|
|
|
|
|
|
|
|
$rootListing = $this->root->getDirectoryListing();
|
|
|
|
$this->assertEquals(2, count($rootListing));
|
|
|
|
|
|
|
|
$folder->move('/asd');
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Node\File $file
|
|
|
|
*/
|
|
|
|
$file = $folder->get('/bar');
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $file);
|
|
|
|
$this->assertFalse($this->root->nodeExists('/foo/bar'));
|
|
|
|
$this->assertTrue($this->root->nodeExists('/asd/bar'));
|
|
|
|
$this->assertEquals('qwerty', $file->getContent());
|
|
|
|
$folder->move('/substorage/foo');
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Node\File $file
|
|
|
|
*/
|
|
|
|
$file = $folder->get('/bar');
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $file);
|
|
|
|
$this->assertTrue($this->root->nodeExists('/substorage/foo/bar'));
|
|
|
|
$this->assertEquals('qwerty', $file->getContent());
|
|
|
|
}
|
|
|
|
}
|