summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-06 16:34:29 +0100
committerRobin Appelman <robin@icewind.nl>2017-01-27 10:44:45 +0100
commitd14ff700503ebef6cda27aae1dd348f75b093d09 (patch)
treef3b3bf6210f2a28492d1025b65d37c503abbac44 /apps/files_external
parent72eeb8fd2267f1a4d319372c455e3fbd0539976f (diff)
downloadnextcloud-server-d14ff700503ebef6cda27aae1dd348f75b093d09.tar.gz
nextcloud-server-d14ff700503ebef6cda27aae1dd348f75b093d09.zip
add unit tests for smb notify backend
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php1
-rw-r--r--apps/files_external/tests/Storage/SmbTest.php47
2 files changed, 48 insertions, 0 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index c73288f8cc2..690f8e2a334 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -499,6 +499,7 @@ class SMB extends Common implements INotifyStorage {
}
public function notify($path) {
+ $path = '/' . ltrim($path, '/');
$shareNotifyHandler = $this->share->notify($this->buildPath($path));
return new SMBNotifyHandler($shareNotifyHandler, $this->root);
}
diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php
index 150d4d3a035..45c01a0c59e 100644
--- a/apps/files_external/tests/Storage/SmbTest.php
+++ b/apps/files_external/tests/Storage/SmbTest.php
@@ -27,7 +27,10 @@
namespace OCA\Files_External\Tests\Storage;
+use OC\Files\Notify\Change;
+use OC\Files\Notify\RenameChange;
use \OCA\Files_External\Lib\Storage\SMB;
+use OCP\Files\Notify\IChange;
/**
* Class SmbTest
@@ -37,6 +40,10 @@ use \OCA\Files_External\Lib\Storage\SMB;
* @package OCA\Files_External\Tests\Storage
*/
class SmbTest extends \Test\Files\Storage\Storage {
+ /**
+ * @var SMB instance
+ */
+ protected $instance;
protected function setUp() {
parent::setUp();
@@ -85,4 +92,44 @@ class SmbTest extends \Test\Files\Storage\Storage {
$this->assertEquals('smb::testuser@testhost//someshare//someroot/', $this->instance->getId());
$this->instance = null;
}
+
+ public function testNotifyGetChanges() {
+ $notifyHandler = $this->instance->notify('');
+ usleep(100 * 1000); //give time for the notify to start
+ $this->instance->file_put_contents('/newfile.txt', 'test content');
+ $this->instance->rename('/newfile.txt', 'renamed.txt');
+ $this->instance->unlink('/renamed.txt');
+ usleep(100 * 1000); //time for all changes to be processed
+
+ $changes = $notifyHandler->getChanges();
+ $notifyHandler->stop();
+
+ $expected = [
+ new Change(IChange::ADDED, 'newfile.txt'),
+ new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
+ new Change(IChange::REMOVED, 'renamed.txt')
+ ];
+
+ foreach ($expected as $expectedChange) {
+ $this->assertContains($expectedChange, $changes, '', false, false); // dont check object identity
+ }
+ }
+
+ public function testNotifyListen() {
+ $notifyHandler = $this->instance->notify('');
+ usleep(100 * 1000); //give time for the notify to start
+ $this->instance->file_put_contents('/newfile.txt', 'test content');
+ $this->instance->unlink('/newfile.txt');
+ usleep(100 * 1000); //time for all changes to be processed
+
+ $result = null;
+
+ // since the notify handler buffers untill we start listening we will get the above changes
+ $notifyHandler->listen(function (IChange $change) use (&$result) {
+ $result = $change;
+ return false;//stop listening
+ });
+
+ $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result);
+ }
}