diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-02-10 12:44:27 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-02-10 12:44:27 +0100 |
commit | 9738fae3cf1ad18593d21eb62e138e00c01f5f36 (patch) | |
tree | d5a71f87ea49d758ac50696b7033ce605f61db0a /tests/lib/files/view.php | |
parent | 3e70d563a6774567ec77e9d9adf6b9ccb1e9619d (diff) | |
download | nextcloud-server-9738fae3cf1ad18593d21eb62e138e00c01f5f36.tar.gz nextcloud-server-9738fae3cf1ad18593d21eb62e138e00c01f5f36.zip |
Emulate touch() for backends that don't support it
Diffstat (limited to 'tests/lib/files/view.php')
-rw-r--r-- | tests/lib/files/view.php | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index c9a8a0fb081..af97761bbb7 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -7,6 +7,12 @@ namespace Test\Files; +class TemporaryNoTouch extends \OC\Files\Storage\Temporary { + public function touch($path, $mtime = null) { + return false; + } +} + class View extends \PHPUnit_Framework_TestCase { /** * @var \OC\Files\Storage\Storage[] $storages; @@ -228,12 +234,36 @@ class View extends \PHPUnit_Framework_TestCase { $this->assertEquals(3, $cachedData['size']); } + function testTouch() { + $storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch'); + + \OC\Files\Filesystem::mount($storage, array(), '/'); + + $rootView = new \OC\Files\View(''); + $oldCachedData = $rootView->getFileInfo('foo.txt'); + + $rootView->touch('foo.txt', 500); + + $cachedData = $rootView->getFileInfo('foo.txt'); + $this->assertEquals(500, $cachedData['mtime']); + $this->assertEquals($oldCachedData['storage_mtime'], $cachedData['storage_mtime']); + + $rootView->putFileInfo('foo.txt', array('storage_mtime' => 1000)); //make sure the watcher detects the change + $rootView->file_put_contents('foo.txt', 'asd'); + $cachedData = $rootView->getFileInfo('foo.txt'); + $this->assertGreaterThanOrEqual($cachedData['mtime'], $oldCachedData['mtime']); + $this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']); + } + /** * @param bool $scan * @return \OC\Files\Storage\Storage */ - private function getTestStorage($scan = true) { - $storage = new \OC\Files\Storage\Temporary(array()); + private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') { + /** + * @var \OC\Files\Storage\Storage $storage + */ + $storage = new $class(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); $storage->mkdir('folder'); |