summaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty/icewind/smb/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/tests')
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/AbstractShare.php534
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/NativeShare.php27
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/NativeStream.php143
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/Parser.php87
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/Server.php57
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/Share.php24
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/bootstrap.php9
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/config.json7
-rw-r--r--apps/files_external/3rdparty/icewind/smb/tests/phpunit.xml6
9 files changed, 894 insertions, 0 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/AbstractShare.php b/apps/files_external/3rdparty/icewind/smb/tests/AbstractShare.php
new file mode 100644
index 00000000000..117fff1ca19
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/AbstractShare.php
@@ -0,0 +1,534 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+use Icewind\SMB\FileInfo;
+
+abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \Icewind\SMB\Server $server
+ */
+ protected $server;
+
+ /**
+ * @var \Icewind\SMB\IShare $share
+ */
+ protected $share;
+
+ /**
+ * @var string $root
+ */
+ protected $root;
+
+ protected $config;
+
+ public function tearDown() {
+ try {
+ if ($this->share) {
+ $this->cleanDir($this->root);
+ }
+ unset($this->share);
+ } catch (\Exception $e) {
+ unset($this->share);
+ throw $e;
+ }
+ }
+
+ public function nameProvider() {
+ // / ? < > \ : * | " are illegal characters in path on windows
+ return array(
+ array('simple'),
+ array('with spaces_and-underscores'),
+ array("single'quote'"),
+ array('日本語'),
+ array('url %2F +encode'),
+ array('a somewhat longer filename than the other with more charaters as the all the other filenames'),
+ array('$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫ')
+ );
+ }
+
+ public function fileDataProvider() {
+ return array(
+ array('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'),
+ array('Mixed language, 日本語 が わからか and Various _/* characters \\|” €')
+ );
+ }
+
+ public function nameAndDataProvider() {
+ $names = $this->nameProvider();
+ $data = $this->fileDataProvider();
+ $result = array();
+ foreach ($names as $name) {
+ foreach ($data as $text) {
+ $result[] = array($name[0], $text[0]);
+ }
+ }
+ return $result;
+ }
+
+ public function cleanDir($dir) {
+ $content = $this->share->dir($dir);
+ foreach ($content as $metadata) {
+ if ($metadata->isDirectory()) {
+ $this->cleanDir($metadata->getPath());
+ } else {
+ $this->share->del($metadata->getPath());
+ }
+ }
+ $this->share->rmdir($dir);
+ }
+
+ private function getTextFile($text = '') {
+ if (!$text) {
+ $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
+ }
+ $file = tempnam('/tmp', 'smb_test_');
+ file_put_contents($file, $text);
+ return $file;
+ }
+
+ public function testListShares() {
+ $shares = $this->server->listShares();
+ foreach ($shares as $share) {
+ if ($share->getName() === $this->config->share) {
+ return;
+ }
+ }
+ $this->fail('Share "' . $this->config->share . '" not found');
+ }
+
+ public function testRootStartsEmpty() {
+ $this->assertEquals(array(), $this->share->dir($this->root));
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testMkdir($name) {
+ $this->share->mkdir($this->root . '/' . $name);
+ $dirs = $this->share->dir($this->root);
+ $this->assertCount(1, $dirs);
+ $this->assertEquals($name, $dirs[0]->getName());
+ $this->assertTrue($dirs[0]->isDirectory());
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testRenameDirectory($name) {
+ $this->share->mkdir($this->root . '/' . $name);
+ $this->share->rename($this->root . '/' . $name, $this->root . '/' . $name . '_rename');
+ $dirs = $this->share->dir($this->root);
+ $this->assertEquals(1, count($dirs));
+ $this->assertEquals($name . '_rename', $dirs[0]->getName());
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testRmdir($name) {
+ $this->share->mkdir($this->root . '/' . $name);
+ $this->share->rmdir($this->root . '/' . $name);
+ $this->assertCount(0, $this->share->dir($this->root));
+ }
+
+ /**
+ * @dataProvider nameAndDataProvider
+ */
+ public function testPut($name, $text) {
+ $tmpFile = $this->getTextFile($text);
+ $size = filesize($tmpFile);
+
+ $this->share->put($tmpFile, $this->root . '/' . $name);
+ unlink($tmpFile);
+
+ $files = $this->share->dir($this->root);
+ $this->assertCount(1, $files);
+ $this->assertEquals($name, $files[0]->getName());
+ $this->assertEquals($size, $files[0]->getSize());
+ $this->assertFalse($files[0]->isDirectory());
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testRenameFile($name) {
+ $tmpFile = $this->getTextFile();
+
+ $this->share->put($tmpFile, $this->root . '/' . $name);
+ unlink($tmpFile);
+
+ $this->share->rename($this->root . '/' . $name, $this->root . '/' . $name . '_renamed');
+
+ $files = $this->share->dir($this->root);
+ $this->assertEquals(1, count($files));
+ $this->assertEquals($name . '_renamed', $files[0]->getName());
+ }
+
+ /**
+ * @dataProvider nameAndDataProvider
+ */
+ public function testGet($name, $text) {
+ $tmpFile = $this->getTextFile($text);
+
+ $this->share->put($tmpFile, $this->root . '/' . $name);
+ unlink($tmpFile);
+
+ $targetFile = tempnam('/tmp', 'smb_test_');
+ $this->share->get($this->root . '/' . $name, $targetFile);
+
+ $this->assertEquals($text, file_get_contents($targetFile));
+ unlink($targetFile);
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testDel($name) {
+ $tmpFile = $this->getTextFile();
+
+ $this->share->put($tmpFile, $this->root . '/' . $name);
+ unlink($tmpFile);
+
+ $this->share->del($this->root . '/' . $name);
+ $this->assertCount(0, $this->share->dir($this->root));
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testCreateFolderInNonExistingFolder() {
+ $this->share->mkdir($this->root . '/foo/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testRemoveFolderInNonExistingFolder() {
+ $this->share->rmdir($this->root . '/foo/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testRemoveNonExistingFolder() {
+ $this->share->rmdir($this->root . '/foo');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\AlreadyExistsException
+ */
+ public function testCreateExistingFolder() {
+ $this->share->mkdir($this->root . '/bar');
+ $this->share->mkdir($this->root . '/bar');
+ $this->share->rmdir($this->root . '/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\InvalidTypeException
+ */
+ public function testCreateFileExistingFolder() {
+ $this->share->mkdir($this->root . '/bar');
+ $this->share->put($this->getTextFile(), $this->root . '/bar');
+ $this->share->rmdir($this->root . '/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testCreateFileInNonExistingFolder() {
+ $this->share->put($this->getTextFile(), $this->root . '/foo/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testTestRemoveNonExistingFile() {
+ $this->share->del($this->root . '/foo');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testDownloadNonExistingFile() {
+ $this->share->get($this->root . '/foo', '/dev/null');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\InvalidTypeException
+ */
+ public function testDownloadFolder() {
+ $this->share->mkdir($this->root . '/foobar');
+ $this->share->get($this->root . '/foobar', '/dev/null');
+ $this->share->rmdir($this->root . '/foobar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\InvalidTypeException
+ */
+ public function testDelFolder() {
+ $this->share->mkdir($this->root . '/foobar');
+ $this->share->del($this->root . '/foobar');
+ $this->share->rmdir($this->root . '/foobar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\InvalidTypeException
+ */
+ public function testRmdirFile() {
+ $this->share->put($this->getTextFile(), $this->root . '/foobar');
+ $this->share->rmdir($this->root . '/foobar');
+ $this->share->del($this->root . '/foobar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotEmptyException
+ */
+ public function testRmdirNotEmpty() {
+ $this->share->mkdir($this->root . '/foobar');
+ $this->share->put($this->getTextFile(), $this->root . '/foobar/asd');
+ $this->share->rmdir($this->root . '/foobar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testDirNonExisting() {
+ $this->share->dir('/foobar/asd');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testRmDirNonExisting() {
+ $this->share->rmdir('/foobar/asd');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testRenameNonExisting() {
+ $this->share->rename('/foobar/asd', '/foobar/bar');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testRenameTargetNonExisting() {
+ $txt = $this->getTextFile();
+ $this->share->put($txt, $this->root . '/foo.txt');
+ unlink($txt);
+ $this->share->rename($this->root . '/foo.txt', $this->root . '/bar/foo.txt');
+ }
+
+ public function testModifiedDate() {
+ $now = time();
+ $this->share->put($this->getTextFile(), $this->root . '/foo.txt');
+ $dir = $this->share->dir($this->root);
+ $mtime = $dir[0]->getMTime();
+ $this->assertTrue(abs($now - $mtime) <= 1, 'Modified time differs by ' . abs($now - $mtime) . ' seconds');
+ $this->share->del($this->root . '/foo.txt');
+ }
+
+ /**
+ * @dataProvider nameAndDataProvider
+ */
+ public function testReadStream($name, $text) {
+ $sourceFile = $this->getTextFile($text);
+ $this->share->put($sourceFile, $this->root . '/' . $name);
+ $fh = $this->share->read($this->root . '/' . $name);
+ $content = stream_get_contents($fh);
+ fclose($fh);
+ $this->share->del($this->root . '/' . $name);
+
+ $this->assertEquals(file_get_contents($sourceFile), $content);
+ }
+
+ /**
+ * @dataProvider nameAndDataProvider
+ */
+ public function testWriteStream($name, $text) {
+ $fh = $this->share->write($this->root . '/' . $name);
+ fwrite($fh, $text);
+ fclose($fh);
+
+ $tmpFile1 = tempnam('/tmp', 'smb_test_');
+ $this->share->get($this->root . '/' . $name, $tmpFile1);
+ $this->assertEquals($text, file_get_contents($tmpFile1));
+ $this->share->del($this->root . '/' . $name);
+ unlink($tmpFile1);
+ }
+
+ public function testDir() {
+ $txtFile = $this->getTextFile();
+
+ $this->share->mkdir($this->root . '/dir');
+ $this->share->put($txtFile, $this->root . '/file.txt');
+ unlink($txtFile);
+
+ $dir = $this->share->dir($this->root);
+ if ($dir[0]->getName() === 'dir') {
+ $dirEntry = $dir[0];
+ } else {
+ $dirEntry = $dir[1];
+ }
+ $this->assertTrue($dirEntry->isDirectory());
+ $this->assertFalse($dirEntry->isReadOnly());
+ $this->assertFalse($dirEntry->isReadOnly());
+
+ if ($dir[0]->getName() === 'file.txt') {
+ $fileEntry = $dir[0];
+ } else {
+ $fileEntry = $dir[1];
+ }
+ $this->assertFalse($fileEntry->isDirectory());
+ $this->assertFalse($fileEntry->isReadOnly());
+ $this->assertFalse($fileEntry->isReadOnly());
+ }
+
+ /**
+ * @dataProvider nameProvider
+ */
+ public function testStat($name) {
+ $txtFile = $this->getTextFile();
+ $size = filesize($txtFile);
+
+ $this->share->put($txtFile, $this->root . '/' . $name);
+ unlink($txtFile);
+
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertEquals($size, $info->getSize());
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\NotFoundException
+ */
+ public function testStatNonExisting() {
+ $this->share->stat($this->root . '/fo.txt');
+ }
+
+ /**
+ * note setting archive and system bit is not supported
+ *
+ * @dataProvider nameProvider
+ */
+ public function testSetMode($name) {
+ $txtFile = $this->getTextFile();
+
+ $this->share->put($txtFile, $this->root . '/' . $name);
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_NORMAL);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertFalse($info->isReadOnly());
+ $this->assertFalse($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertFalse($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_READONLY);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertTrue($info->isReadOnly());
+ $this->assertFalse($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertFalse($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_ARCHIVE);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertFalse($info->isReadOnly());
+ $this->assertTrue($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertFalse($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertTrue($info->isReadOnly());
+ $this->assertTrue($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertFalse($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_HIDDEN);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertFalse($info->isReadOnly());
+ $this->assertFalse($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertTrue($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_SYSTEM);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertFalse($info->isReadOnly());
+ $this->assertFalse($info->isArchived());
+ $this->assertTrue($info->isSystem());
+ $this->assertFalse($info->isHidden());
+
+ $this->share->setMode($this->root . '/' . $name, FileInfo::MODE_NORMAL);
+ $info = $this->share->stat($this->root . '/' . $name);
+ $this->assertFalse($info->isReadOnly());
+ $this->assertFalse($info->isArchived());
+ $this->assertFalse($info->isSystem());
+ $this->assertFalse($info->isHidden());
+ }
+
+ public function pathProvider() {
+ // / ? < > \ : * | " are illegal characters in path on windows
+ return array(
+ array('dir/sub/foo.txt'),
+ array('bar.txt'),
+ array("single'quote'/sub/foo.txt"),
+ array('日本語/url %2F +encode/asd.txt'),
+ array(
+ 'a somewhat longer folder than the other with more charaters as the all the other filenames/' .
+ 'followed by a somewhat long file name after that.txt'
+ )
+ );
+ }
+
+ /**
+ * @dataProvider pathProvider
+ */
+ public function testSubDirs($path) {
+ $dirs = explode('/', $path);
+ $name = array_pop($dirs);
+ $fullPath = '';
+ foreach ($dirs as $dir) {
+ $fullPath .= '/' . $dir;
+ $this->share->mkdir($this->root . $fullPath);
+ }
+ $txtFile = $this->getTextFile();
+ $size = filesize($txtFile);
+ $this->share->put($txtFile, $this->root . $fullPath . '/' . $name);
+ unlink($txtFile);
+ $info = $this->share->stat($this->root . $fullPath . '/' . $name);
+ $this->assertEquals($size, $info->getSize());
+ $this->assertFalse($info->isHidden());
+ }
+
+ public function testDelAfterStat() {
+ $name = 'foo.txt';
+ $txtFile = $this->getTextFile();
+
+ $this->share->put($txtFile, $this->root . '/' . $name);
+ unlink($txtFile);
+
+ $this->share->stat($this->root . '/' . $name);
+ $this->share->del($this->root . '/foo.txt');
+ }
+
+ /**
+ * @param $name
+ * @dataProvider nameProvider
+ */
+ public function testDirPaths($name) {
+ $txtFile = $this->getTextFile();
+ $this->share->mkdir($this->root . '/' . $name);
+ $this->share->put($txtFile, $this->root . '/' . $name . '/' . $name);
+ unlink($txtFile);
+
+ $content = $this->share->dir($this->root . '/' . $name);
+ $this->assertCount(1, $content);
+ $this->assertEquals($name, $content[0]->getName());
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/tests/NativeShare.php
new file mode 100644
index 00000000000..d8e10235c12
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/NativeShare.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+use Icewind\SMB\NativeServer;
+
+class NativeShare extends AbstractShare {
+ public function setUp() {
+ if (!function_exists('smbclient_state_new')) {
+ $this->markTestSkipped('libsmbclient php extension not installed');
+ }
+ $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
+ $this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
+ $this->share = $this->server->getShare($this->config->share);
+ if ($this->config->root) {
+ $this->root = '/' . $this->config->root . '/' . uniqid();
+ } else {
+ $this->root = '/' . uniqid();
+ }
+ $this->share->mkdir($this->root);
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/NativeStream.php b/apps/files_external/3rdparty/icewind/smb/tests/NativeStream.php
new file mode 100644
index 00000000000..2d7b62fedeb
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/NativeStream.php
@@ -0,0 +1,143 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+use Icewind\SMB\NativeServer;
+
+class NativeStream extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \Icewind\SMB\Server $server
+ */
+ protected $server;
+
+ /**
+ * @var \Icewind\SMB\NativeShare $share
+ */
+ protected $share;
+
+ /**
+ * @var string $root
+ */
+ protected $root;
+
+ protected $config;
+
+ public function setUp() {
+ if (!function_exists('smbclient_state_new')) {
+ $this->markTestSkipped('libsmbclient php extension not installed');
+ }
+ $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
+ $this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
+ $this->share = $this->server->getShare($this->config->share);
+ if ($this->config->root) {
+ $this->root = '/' . $this->config->root . '/' . uniqid();
+ } else {
+ $this->root = '/' . uniqid();
+ }
+ $this->share->mkdir($this->root);
+ }
+
+ private function getTextFile() {
+ $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
+ $file = tempnam('/tmp', 'smb_test_');
+ file_put_contents($file, $text);
+ return $file;
+ }
+
+ public function testSeekTell() {
+ $sourceFile = $this->getTextFile();
+ $this->share->put($sourceFile, $this->root . '/foobar');
+ $fh = $this->share->read($this->root . '/foobar');
+ $content = fread($fh, 3);
+ $this->assertEquals('Lor', $content);
+
+ fseek($fh, -2, SEEK_CUR);
+
+ $content = fread($fh, 3);
+ $this->assertEquals('ore', $content);
+
+ fseek($fh, 3, SEEK_SET);
+
+ $content = fread($fh, 3);
+ $this->assertEquals('em ', $content);
+
+ fseek($fh, -3, SEEK_END);
+
+ $content = fread($fh, 3);
+ $this->assertEquals('qua', $content);
+
+ fseek($fh, -3, SEEK_END);
+ $this->assertEquals(120, ftell($fh));
+ }
+
+ public function testStat() {
+ $sourceFile = $this->getTextFile();
+ $this->share->put($sourceFile, $this->root . '/foobar');
+ $fh = $this->share->read($this->root . '/foobar');
+ $stat = fstat($fh);
+ $this->assertEquals(filesize($sourceFile), $stat['size']);
+ unlink($sourceFile);
+ }
+
+ public function testTruncate() {
+ if (version_compare(phpversion(), '5.4.0', '<')) {
+ $this->markTestSkipped('php <5.4 doesn\'t support truncate for stream wrappers');
+ }
+ $fh = $this->share->write($this->root . '/foobar');
+ fwrite($fh, 'foobar');
+ ftruncate($fh, 3);
+ fclose($fh);
+
+ $fh = $this->share->read($this->root . '/foobar');
+ $this->assertEquals('foo', stream_get_contents($fh));
+ }
+
+ public function testEOF() {
+ if (version_compare(phpversion(), '5.4.0', '<')) {
+ $this->markTestSkipped('php <5.4 doesn\'t support truncate for stream wrappers');
+ }
+ $fh = $this->share->write($this->root . '/foobar');
+ fwrite($fh, 'foobar');
+ fclose($fh);
+
+ $fh = $this->share->read($this->root . '/foobar');
+ fread($fh, 3);
+ $this->assertFalse(feof($fh));
+ fread($fh, 5);
+ $this->assertTrue(feof($fh));
+ }
+
+ public function testLockUnsupported() {
+ $fh = $this->share->write($this->root . '/foobar');
+ $this->assertFalse(flock($fh, LOCK_SH));
+ }
+
+ public function testSetOptionUnsupported() {
+ $fh = $this->share->write($this->root . '/foobar');
+ $this->assertFalse(stream_set_blocking($fh, false));
+ }
+
+ public function tearDown() {
+ if ($this->share) {
+ $this->cleanDir($this->root);
+ }
+ unset($this->share);
+ }
+
+ public function cleanDir($dir) {
+ $content = $this->share->dir($dir);
+ foreach ($content as $metadata) {
+ if ($metadata->isDirectory()) {
+ $this->cleanDir($metadata->getPath());
+ } else {
+ $this->share->del($metadata->getPath());
+ }
+ }
+ $this->share->rmdir($dir);
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/Parser.php b/apps/files_external/3rdparty/icewind/smb/tests/Parser.php
new file mode 100644
index 00000000000..0dd06d6af33
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/Parser.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+
+use Icewind\SMB\FileInfo;
+
+class Parser extends \PHPUnit_Framework_TestCase {
+ public function modeProvider() {
+ return array(
+ array('D', FileInfo::MODE_DIRECTORY),
+ array('A', FileInfo::MODE_ARCHIVE),
+ array('S', FileInfo::MODE_SYSTEM),
+ array('H', FileInfo::MODE_HIDDEN),
+ array('R', FileInfo::MODE_READONLY),
+ array('N', FileInfo::MODE_NORMAL),
+ array('RA', FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE),
+ array('RAH', FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE | FileInfo::MODE_HIDDEN)
+ );
+ }
+
+ /**
+ * @dataProvider modeProvider
+ */
+ public function testParseMode($string, $mode) {
+ $parser = new \Icewind\SMB\Parser('UTC');
+ $this->assertEquals($mode, $parser->parseMode($string), 'Failed parsing ' . $string);
+ }
+
+ public function statProvider() {
+ return array(
+ array(
+ array(
+ 'altname: test.txt',
+ 'create_time: Sat Oct 12 07:05:58 PM 2013 CEST',
+ 'access_time: Tue Oct 15 02:58:48 PM 2013 CEST',
+ 'write_time: Sat Oct 12 07:05:58 PM 2013 CEST',
+ 'change_time: Sat Oct 12 07:05:58 PM 2013 CEST',
+ 'attributes: (80)',
+ 'stream: [::$DATA], 29634 bytes'
+ ),
+ array(
+ 'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'),
+ 'mode' => FileInfo::MODE_NORMAL,
+ 'size' => 29634
+ ))
+ );
+ }
+
+ /**
+ * @dataProvider statProvider
+ */
+ public function testStat($output, $stat) {
+ $parser = new \Icewind\SMB\Parser('UTC');
+ $this->assertEquals($stat, $parser->parseStat($output));
+ }
+
+ public function dirProvider() {
+ return array(
+ array(
+ array(
+ ' . D 0 Tue Aug 26 19:11:56 2014',
+ ' .. DR 0 Sun Oct 28 15:24:02 2012',
+ ' c.pdf N 29634 Sat Oct 12 19:05:58 2013',
+ '',
+ ' 62536 blocks of size 8388608. 57113 blocks available'
+ ),
+ array(
+ new FileInfo('/c.pdf', 'c.pdf', 29634, strtotime('12 Oct 2013 19:05:58 CEST'), FileInfo::MODE_NORMAL)
+ )
+ )
+ );
+ }
+
+ /**
+ * @dataProvider dirProvider
+ */
+ public function testDir($output, $dir) {
+ $parser = new \Icewind\SMB\Parser('CEST');
+ $this->assertEquals($dir, $parser->parseDir($output, ''));
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/Server.php b/apps/files_external/3rdparty/icewind/smb/tests/Server.php
new file mode 100644
index 00000000000..9f62886654f
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/Server.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+class Server extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \Icewind\SMB\Server $server
+ */
+ private $server;
+
+ private $config;
+
+ public function setUp() {
+ $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
+ $this->server = new \Icewind\SMB\Server($this->config->host, $this->config->user, $this->config->password);
+ }
+
+ public function testListShares() {
+ $shares = $this->server->listShares();
+ foreach ($shares as $share) {
+ if ($share->getName() === $this->config->share) {
+ return;
+ }
+ }
+ $this->fail('Share "' . $this->config->share . '" not found');
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\AuthenticationException
+ */
+ public function testWrongUserName() {
+ $this->markTestSkipped('This fails for no reason on travis');
+ $server = new \Icewind\SMB\Server($this->config->host, uniqid(), uniqid());
+ $server->listShares();
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\AuthenticationException
+ */
+ public function testWrongPassword() {
+ $server = new \Icewind\SMB\Server($this->config->host, $this->config->user, uniqid());
+ $server->listShares();
+ }
+
+ /**
+ * @expectedException \Icewind\SMB\Exception\InvalidHostException
+ */
+ public function testWrongHost() {
+ $server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
+ $server->listShares();
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/Share.php b/apps/files_external/3rdparty/icewind/smb/tests/Share.php
new file mode 100644
index 00000000000..a629914d748
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/Share.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+namespace Icewind\SMB\Test;
+
+use Icewind\SMB\Server as NormalServer;
+
+class Share extends AbstractShare {
+ public function setUp() {
+ $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
+ $this->server = new NormalServer($this->config->host, $this->config->user, $this->config->password);
+ $this->share = $this->server->getShare($this->config->share);
+ if ($this->config->root) {
+ $this->root = '/' . $this->config->root . '/' . uniqid();
+ } else {
+ $this->root = '/' . uniqid();
+ }
+ $this->share->mkdir($this->root);
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/bootstrap.php b/apps/files_external/3rdparty/icewind/smb/tests/bootstrap.php
new file mode 100644
index 00000000000..dc2e34b183e
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/bootstrap.php
@@ -0,0 +1,9 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Licensed under the MIT license:
+ * http://opensource.org/licenses/MIT
+ */
+
+date_default_timezone_set('UTC');
+require_once __DIR__.'/../vendor/autoload.php';
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/config.json b/apps/files_external/3rdparty/icewind/smb/tests/config.json
new file mode 100644
index 00000000000..0ecd7e3715d
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/config.json
@@ -0,0 +1,7 @@
+{
+ "host": "localhost",
+ "user": "test",
+ "password": "test",
+ "share": "test",
+ "root": "test"
+}
diff --git a/apps/files_external/3rdparty/icewind/smb/tests/phpunit.xml b/apps/files_external/3rdparty/icewind/smb/tests/phpunit.xml
new file mode 100644
index 00000000000..3ab244dd34f
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/smb/tests/phpunit.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit bootstrap="bootstrap.php">
+ <testsuite name='SMB'>
+ <directory suffix='.php'>./</directory>
+ </testsuite>
+</phpunit>