1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?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 \Test\TestCase {
/**
* @var \OC\Files\Cache\ChangePropagator
*/
private $propagator;
/**
* @var \OC\Files\View
*/
private $view;
protected function setUp() {
parent::setUp();
$storage = new Temporary(array());
$root = $this->getUniqueID('/');
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->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag());
$this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag());
$this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag());
}
}
|