Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-05-30 17:55:17 +0400
committerRobin Appelman <icewind@owncloud.com>2014-06-10 18:16:46 +0400
commit289526110256f7ff86cf56ebbddeb6e4fd716d61 (patch)
treea9ac05f7e36ce8843c30f6550e2846abcb0d7c70 /tests
parent29119065862e65c756c9c42f04c831c7eeec0417 (diff)
Add a change propagator class to handle propagating etag and mtime changes
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/changepropagator.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/lib/files/cache/changepropagator.php b/tests/lib/files/cache/changepropagator.php
new file mode 100644
index 00000000000..9beff27d50e
--- /dev/null
+++ b/tests/lib/files/cache/changepropagator.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Copyright (c) 2014 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\Cache;
+
+use OC\Files\Filesystem;
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+
+class ChangePropagator extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator
+ */
+ private $propagator;
+
+ /**
+ * @var \OC\Files\View
+ */
+ private $view;
+
+ public function setUp() {
+ $storage = new Temporary(array());
+ $root = '/' . uniqid();
+ Filesystem::mount($storage, array(), $root);
+ $this->view = new View($root);
+ $this->propagator = new \OC\Files\Cache\ChangePropagator($this->view);
+ }
+
+ public function testGetParentsSingle() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->assertEquals(array('/', '/foo', '/foo/bar'), $this->propagator->getAllParents());
+ }
+
+ public function testGetParentsMultiple() {
+ $this->propagator->addChange('/foo/bar/asd');
+ $this->propagator->addChange('/foo/qwerty');
+ $this->propagator->addChange('/foo/asd/bar');
+ $this->assertEquals(array('/', '/foo', '/foo/bar', '/foo/asd'), $this->propagator->getAllParents());
+ }
+
+ public function testSinglePropagate() {
+ $this->view->mkdir('/foo');
+ $this->view->mkdir('/foo/bar');
+ $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty');
+
+ $oldInfo1 = $this->view->getFileInfo('/');
+ $oldInfo2 = $this->view->getFileInfo('/foo');
+ $oldInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $time = time() + 50;
+
+ $this->propagator->addChange('/foo/bar/sad.txt');
+ $this->propagator->propagateChanges($time);
+
+ $newInfo1 = $this->view->getFileInfo('/');
+ $newInfo2 = $this->view->getFileInfo('/foo');
+ $newInfo3 = $this->view->getFileInfo('/foo/bar');
+
+ $this->assertEquals($newInfo1->getMTime(), $time);
+ $this->assertEquals($newInfo2->getMTime(), $time);
+ $this->assertEquals($newInfo3->getMTime(), $time);
+
+ $this->assertNotEquals($oldInfo1->getEtag(), $newInfo1->getEtag());
+ $this->assertNotEquals($oldInfo2->getEtag(), $newInfo2->getEtag());
+ $this->assertNotEquals($oldInfo3->getEtag(), $newInfo3->getEtag());
+ }
+}