<commit_before><?php
/**
 * Copyright (c) 2013 <NAME> <<EMAIL>>
 * 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\Cache\Cache;
use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;

class IntegrationTests extends \Test\TestCase {
	/**
	 * @var \OC\Files\Node\Root $root
	 */
	private $root;

	/** @var \OC\Files\Storage\Storage */
	private $originalStorage;

	/**
	 * @var \OC\Files\Storage\Storage[]
	 */
	private $storages;

	/**
	 * @var \OC\Files\View $view
	 */
	private $view;

	protected function setUp() {
		parent::setUp();

		$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
		\OC\Files\Filesystem::init('', '');
		\OC\Files\Filesystem::clearMounts();
		$manager = \OC\Files\Filesystem::getMountManager();

		\OC_Hook::clear('OC_Filesystem');

		\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
		\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
		\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
		\OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');

		$user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
		\OC_User::setUserId($user->getUID());
		$this->view = new View();
		$this->root = new Root($manager, $this->view, $user);
		$storage = new Temporary(array());
		$subStorage = new Temporary(array());
		$this->storages[] = $storage;
		$this->storages[] = $subStorage;
		$this->root->mount($storage, '/');
		$this->root->mount($subStorage, '/substorage/');
	}

	protected function tearDown() {
		foreach ($this->storages as $storage) {
			$storage->getCache()->clear();
		}
		\OC\Files\Filesystem::clearMounts();
		\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');

		parent::tearDown();
	}

	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'));
		$file->move('/bar.txt');
		$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');
		$this->assertNotEquals($id, $file->getId());
		$this->assertEquals('qwerty', $file->getContent());
	}

	public function testBasicFolder() {
		$folder = $this->root->newFolder('/foo');<commit_msg>Add unit test<commit_after><?php
/**
 * Copyright (c) 2013 <NAME> <<EMAIL>>
 * 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\Cache\Cache;
use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;

class IntegrationTests extends \Test\TestCase {
	/**
	 * @var \OC\Files\Node\Root $root
	 */
	private $root;

	/** @var \OC\Files\Storage\Storage */
	private $originalStorage;

	/**
	 * @var \OC\Files\Storage\Storage[]
	 */
	private $storages;

	/**
	 * @var \OC\Files\View $view
	 */
	private $view;

	protected function setUp() {
		parent::setUp();

		$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
		\OC\Files\Filesystem::init('', '');
		\OC\Files\Filesystem::clearMounts();
		$manager = \OC\Files\Filesystem::getMountManager();

		\OC_Hook::clear('OC_Filesystem');

		\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
		\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
		\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
		\OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');

		$user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
		\OC_User::setUserId($user->getUID());
		$this->view = new View();
		$this->root = new Root($manager, $this->view, $user);
		$storage = new Temporary(array());
		$subStorage = new Temporary(array());
		$this->storages[] = $storage;
		$this->storages[] = $subStorage;
		$this->root->mount($storage, '/');
		$this->root->mount($subStorage, '/substorage/');
	}

	protected function tearDown() {
		foreach ($this->storages as $storage) {
			$storage->getCache()->clear();
		}
		\OC\Files\Filesystem::clearMounts();
		\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');

		parent::tearDown();
	}

	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'));
		$target = $file->move('/bar.txt');
		$this->assertEquals($id, $target->getId());
		$this->assertEquals($id, $file->getId());
		$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');
		$this->assertNotEquals($id, $file->getId());
		$this->assertEquals('qwerty', $file->getContent());
	}

	public function testBasicFolder() {
		$folder = $this->root->newFolder('/foo');
{'fraction_non_alphanumeric': 0.22455789122455788, 'fraction_numerical': 0.002002002002002002, 'mean_word_length': 4.860215053763441, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5199974', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2057, 'n_words': 324}