summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/enable_all.php1
-rw-r--r--tests/lib/api.php35
-rw-r--r--tests/lib/files/cache/cache.php45
-rw-r--r--tests/lib/files/cache/homecache.php18
-rw-r--r--tests/lib/files/cache/scanner.php2
-rw-r--r--tests/lib/files/cache/updater.php2
-rw-r--r--tests/lib/files/view.php59
-rw-r--r--tests/lib/request.php50
-rw-r--r--tests/lib/user/manager.php72
-rw-r--r--tests/testcleanuplistener.php6
10 files changed, 268 insertions, 22 deletions
diff --git a/tests/enable_all.php b/tests/enable_all.php
index 43ee16a72f8..4f2fe5cdb60 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -10,6 +10,7 @@ require_once __DIR__.'/../lib/base.php';
OC_App::enable('files_sharing');
OC_App::enable('files_encryption');
+OC_App::enable('user_ldap');
OC_App::enable('calendar');
OC_App::enable('contacts');
OC_App::enable('apptemplateadvanced');
diff --git a/tests/lib/api.php b/tests/lib/api.php
index 95d75f15311..9c4324e63e0 100644
--- a/tests/lib/api.php
+++ b/tests/lib/api.php
@@ -7,12 +7,12 @@
*/
class Test_API extends PHPUnit_Framework_TestCase {
-
+
// Helps build a response variable
- function buildResponse($shipped, $data, $code) {
+ function buildResponse($shipped, $data, $code, $message=null) {
return array(
'shipped' => $shipped,
- 'response' => new OC_OCS_Result($data, $code),
+ 'response' => new OC_OCS_Result($data, $code, $message),
'app' => uniqid('testapp_', true),
);
}
@@ -64,24 +64,24 @@ class Test_API extends PHPUnit_Framework_TestCase {
// Two shipped success results
array(true, 100, true, 100, true),
// Two shipped results, one success and one failure
- array(true, 100, true, 997, false),
+ array(true, 100, true, 998, false),
// Two shipped results, both failure
- array(true, 997, true, 997, false),
+ array(true, 997, true, 998, false),
// Two third party success results
array(false, 100, false, 100, true),
// Two third party results, one success and one failure
- array(false, 100, false, 997, false),
+ array(false, 100, false, 998, false),
// Two third party results, both failure
- array(false, 997, false, 997, false),
+ array(false, 997, false, 998, false),
// One of each, both success
array(false, 100, true, 100, true),
array(true, 100, false, 100, true),
// One of each, both failure
- array(false, 997, true, 997, false),
+ array(false, 997, true, 998, false),
// One of each, shipped success
array(false, 997, true, 100, true),
// One of each, third party success
- array(false, 100, true, 997, false),
+ array(false, 100, true, 998, false),
);
}
/**
@@ -117,12 +117,25 @@ class Test_API extends PHPUnit_Framework_TestCase {
// Two shipped success results
$result = OC_API::mergeResponses(array(
- $this->buildResponse($shipped1, $data1, $statusCode1),
- $this->buildResponse($shipped2, $data2, $statusCode2),
+ $this->buildResponse($shipped1, $data1, $statusCode1, "message1"),
+ $this->buildResponse($shipped2, $data2, $statusCode2, "message2"),
));
$this->checkResult($result, $succeeded);
$resultData = $result->getData();
+ $resultMeta = $result->getMeta();
+ $resultStatusCode = $result->getStatusCode();
+
$this->assertArrayHasKey('jan', $resultData['users']);
+
+ // check if the returned status message matches the selected status code
+ if ($resultStatusCode === 997) {
+ $this->assertEquals('message1', $resultMeta['message']);
+ } elseif ($resultStatusCode === 998) {
+ $this->assertEquals('message2', $resultMeta['message']);
+ } elseif ($resultStatusCode === 100) {
+ $this->assertEquals(null, $resultMeta['message']);
+ }
+
}
}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 052d70dd0b4..7d9329328a3 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -137,6 +137,51 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar'));
}
+ public function testEncryptedFolder() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+ $fileData = array();
+ $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['bar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $content = $this->cache->getFolderContents($file1);
+ $this->assertEquals(count($content), 2);
+ foreach ($content as $cachedData) {
+ $data = $fileData[$cachedData['name']];
+ // indirect retrieval swaps unencrypted_size and size
+ $this->assertEquals($data['unencrypted_size'], $cachedData['size']);
+ }
+
+ $file4 = 'folder/unkownSize';
+ $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(-1, $this->cache->calculateFolderSize($file1));
+
+ $fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(916, $this->cache->calculateFolderSize($file1));
+ // direct cache entry retrieval returns the original values
+ $this->assertEquals(1025, $this->cache->get($file1)['size']);
+ $this->assertEquals(916, $this->cache->get($file1)['unencrypted_size']);
+
+ $this->cache->remove($file2);
+ $this->cache->remove($file3);
+ $this->cache->remove($file4);
+ $this->assertEquals(0, $this->cache->calculateFolderSize($file1));
+
+ $this->cache->remove('folder');
+ $this->assertFalse($this->cache->inCache('folder/foo'));
+ $this->assertFalse($this->cache->inCache('folder/bar'));
+ }
+
public function testRootFolderSizeForNonHomeStorage() {
$dir1 = 'knownsize';
$dir2 = 'unknownsize';
diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php
index 2fa7f1ba92e..87fd0dba4c6 100644
--- a/tests/lib/files/cache/homecache.php
+++ b/tests/lib/files/cache/homecache.php
@@ -62,33 +62,39 @@ class HomeCache extends \PHPUnit_Framework_TestCase {
}
/**
- * Tests that the root folder size calculation ignores the subdirs that have an unknown
- * size. This makes sure that quota calculation still works as it's based on the root
- * folder size.
+ * Tests that the root and files folder size calculation ignores the subdirs
+ * that have an unknown size. This makes sure that quota calculation still
+ * works as it's based on the "files" folder size.
*/
public function testRootFolderSizeIgnoresUnknownUpdate() {
- $dir1 = 'knownsize';
- $dir2 = 'unknownsize';
+ $dir1 = 'files/knownsize';
+ $dir2 = 'files/unknownsize';
$fileData = array();
$fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
$this->cache->put('', $fileData['']);
+ $this->cache->put('files', $fileData['files']);
$this->cache->put($dir1, $fileData[$dir1]);
$this->cache->put($dir2, $fileData[$dir2]);
+ $this->assertTrue($this->cache->inCache('files'));
$this->assertTrue($this->cache->inCache($dir1));
$this->assertTrue($this->cache->inCache($dir2));
- // check that root size ignored the unknown sizes
+ // check that files and root size ignored the unknown sizes
+ $this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
$this->assertEquals(1000, $this->cache->calculateFolderSize(''));
// clean up
$this->cache->remove('');
+ $this->cache->remove('files');
$this->cache->remove($dir1);
$this->cache->remove($dir2);
+ $this->assertFalse($this->cache->inCache('files'));
$this->assertFalse($this->cache->inCache($dir1));
$this->assertFalse($this->cache->inCache($dir2));
}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index 3f3a045377a..3f5604b4d45 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -147,7 +147,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->scanner->scan('');
$oldData = $this->cache->get('');
$this->storage->unlink('folder/bar.txt');
- $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder')));
+ $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder')));
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertNotEquals($oldData['etag'], $newData['etag']);
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 91e384e12af..48986149a73 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -88,7 +88,7 @@ class Updater extends \PHPUnit_Framework_TestCase {
public function testWrite() {
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $this->cache->put('foo.txt', array('mtime' => 100));
+ $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 150));
$rootCachedData = $this->cache->get('');
$this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index b59cef9f0da..72a2f854cb2 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -309,6 +309,48 @@ class View extends \PHPUnit_Framework_TestCase {
/**
* @medium
*/
+ function testUnlink() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->file_put_contents('/foo.txt', 'asd');
+ $rootView->file_put_contents('/substorage/bar.txt', 'asd');
+
+ $this->assertTrue($rootView->file_exists('foo.txt'));
+ $this->assertTrue($rootView->file_exists('substorage/bar.txt'));
+
+ $this->assertTrue($rootView->unlink('foo.txt'));
+ $this->assertTrue($rootView->unlink('substorage/bar.txt'));
+
+ $this->assertFalse($rootView->file_exists('foo.txt'));
+ $this->assertFalse($rootView->file_exists('substorage/bar.txt'));
+ }
+
+ /**
+ * @medium
+ */
+ function testUnlinkRootMustFail() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->file_put_contents('/foo.txt', 'asd');
+ $rootView->file_put_contents('/substorage/bar.txt', 'asd');
+
+ $this->assertFalse($rootView->unlink(''));
+ $this->assertFalse($rootView->unlink('/'));
+ $this->assertFalse($rootView->unlink('substorage'));
+ $this->assertFalse($rootView->unlink('/substorage'));
+ }
+
+ /**
+ * @medium
+ */
function testTouch() {
$storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');
@@ -503,4 +545,21 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertContains($item['name'], $names);
}
}
+
+ public function testTouchNotSupported() {
+ $storage = new TemporaryNoTouch(array());
+ $scanner = $storage->getScanner();
+ \OC\Files\Filesystem::mount($storage, array(), '/test/');
+ $past = time() - 100;
+ $storage->file_put_contents('test', 'foobar');
+ $scanner->scan('');
+ $view = new \OC\Files\View('');
+ $info = $view->getFileInfo('/test/test');
+
+ $view->touch('/test/test', $past);
+ $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
+
+ $info2 = $view->getFileInfo('/test/test');
+ $this->assertEquals($info['etag'], $info2['etag']);
+ }
}
diff --git a/tests/lib/request.php b/tests/lib/request.php
index 090cebc9231..c6401a57144 100644
--- a/tests/lib/request.php
+++ b/tests/lib/request.php
@@ -70,4 +70,54 @@ class Test_Request extends PHPUnit_Framework_TestCase {
array('/oc/core1', '/oc/core/index.php'),
);
}
+
+ /**
+ * @dataProvider userAgentProvider
+ */
+ public function testUserAgent($testAgent, $userAgent, $matches) {
+ $_SERVER['HTTP_USER_AGENT'] = $testAgent;
+ $this->assertEquals($matches, OC_Request::isUserAgent($userAgent));
+ }
+
+ function userAgentProvider() {
+ return array(
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ OC_Request::USER_AGENT_IE,
+ true
+ ),
+ array(
+ 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
+ OC_Request::USER_AGENT_IE,
+ false
+ ),
+ array(
+ 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ true
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ false
+ ),
+ // test two values
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ array(
+ OC_Request::USER_AGENT_IE,
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ ),
+ true
+ ),
+ array(
+ 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
+ array(
+ OC_Request::USER_AGENT_IE,
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ ),
+ true
+ ),
+ );
+ }
}
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index 00901dd4115..ad1ac9e12f2 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -346,4 +346,76 @@ class Manager extends \PHPUnit_Framework_TestCase {
$manager->createUser('foo', 'bar');
}
+
+ public function testCountUsersNoBackend() {
+ $manager = new \OC\User\Manager();
+
+ $result = $manager->countUsers();
+ $this->assertTrue(is_array($result));
+ $this->assertTrue(empty($result));
+ }
+
+ public function testCountUsersOneBackend() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $result = $manager->countUsers();
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ $this->assertEquals(7, $users);
+ }
+
+ public function testCountUsersTwoBackends() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend1 = $this->getMock('\OC_User_Dummy');
+ $backend1->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend1->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $backend2 = $this->getMock('\OC_User_Dummy');
+ $backend2->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(16));
+
+ $backend2->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend1);
+ $manager->registerBackend($backend2);
+
+ $result = $manager->countUsers();
+ //because the backends have the same class name, only one value expected
+ $this->assertEquals(1, count($result));
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ //users from backends shall be summed up
+ $this->assertEquals(7+16, $users);
+ }
}
diff --git a/tests/testcleanuplistener.php b/tests/testcleanuplistener.php
index 368ea7bc8f4..a969ece6dd5 100644
--- a/tests/testcleanuplistener.php
+++ b/tests/testcleanuplistener.php
@@ -58,7 +58,7 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
}
private function unlinkDir($dir) {
- if ($dh = opendir($dir)) {
+ if ($dh = @opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file === '..' || $file === '.') {
continue;
@@ -68,12 +68,12 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
$this->unlinkDir($path);
}
else {
- unlink($path);
+ @unlink($path);
}
}
closedir($dh);
}
- rmdir($dir);
+ @rmdir($dir);
}
private function cleanStrayDataFiles() {