summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/l10n/ru.json3
-rw-r--r--tests/lib/activitymanager.php20
-rw-r--r--tests/lib/datetimeformatter.php6
-rw-r--r--tests/lib/files/cache/cache.php57
-rw-r--r--tests/lib/files/node/folder.php39
-rw-r--r--tests/lib/l10n.php18
-rw-r--r--tests/lib/largefilehelpergetfilesize.php9
-rw-r--r--tests/lib/tags.php62
-rw-r--r--tests/lib/testcase.php21
-rw-r--r--tests/lib/user/manager.php11
-rw-r--r--tests/settings/controller/userscontrollertest.php103
11 files changed, 315 insertions, 34 deletions
diff --git a/tests/data/l10n/ru.json b/tests/data/l10n/ru.json
index 177b14a6b20..7041205e761 100644
--- a/tests/data/l10n/ru.json
+++ b/tests/data/l10n/ru.json
@@ -1,6 +1,7 @@
{
"translations" : {
- "_%n file_::_%n files_" : ["%n файл", "%n файла", "%n файлов"]
+ "_%n file_::_%n files_" : ["%n файл", "%n файла", "%n файлов"],
+ "_%n missing plural_::_%n missing plurals_" : ["", "", ""]
},
"pluralForm" : "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"
}
diff --git a/tests/lib/activitymanager.php b/tests/lib/activitymanager.php
index 0683eb68193..6a5af7b259b 100644
--- a/tests/lib/activitymanager.php
+++ b/tests/lib/activitymanager.php
@@ -59,6 +59,14 @@ class Test_ActivityManager extends \Test\TestCase {
$this->assertFalse($result);
}
+ public function testGetSpecialParameterList() {
+ $result = $this->activityManager->getSpecialParameterList('APP0', '');
+ $this->assertEquals(array(0 => 'file', 1 => 'username'), $result);
+
+ $result = $this->activityManager->getSpecialParameterList('APP1', '');
+ $this->assertFalse($result);
+ }
+
public function testTypeIcon() {
$result = $this->activityManager->getTypeIcon('NT1');
$this->assertEquals('icon-nt-one', $result);
@@ -132,6 +140,14 @@ class SimpleExtension implements \OCP\Activity\IExtension {
return false;
}
+ public function getSpecialParameterList($app, $text) {
+ if ($app === 'APP0') {
+ return array(0 => 'file', 1 => 'username');
+ }
+
+ return false;
+ }
+
public function getTypeIcon($type) {
if ($type === 'NT1') {
return 'icon-nt-one';
@@ -185,6 +201,10 @@ class NoOpExtension implements \OCP\Activity\IExtension {
return false;
}
+ public function getSpecialParameterList($app, $text) {
+ return false;
+ }
+
public function getTypeIcon($type) {
return false;
}
diff --git a/tests/lib/datetimeformatter.php b/tests/lib/datetimeformatter.php
index 4b91c3a1cc7..9a50ee4a257 100644
--- a/tests/lib/datetimeformatter.php
+++ b/tests/lib/datetimeformatter.php
@@ -42,8 +42,7 @@ class DateTimeFormatter extends TestCase {
}
public function formatTimeSpanData() {
- // use the same time all the time, so the tests are reliable when time would switch
- $time = time();
+ $time = 1416916800; // Use a fixed timestamp so we dont switch days/years with the getTimestampAgo
$deL10N = new \OC_L10N('lib', 'de');
return array(
array('seconds ago', $time, $time),
@@ -81,8 +80,7 @@ class DateTimeFormatter extends TestCase {
}
public function formatDateSpanData() {
- // use the same time all the time, so the tests are reliable when time would switch
- $time = time();
+ $time = 1416916800; // Use a fixed timestamp so we dont switch days/years with the getTimestampAgo
$deL10N = new \OC_L10N('lib', 'de');
return array(
// Normal testing
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 7e44cb898ac..1af8e4da960 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -270,6 +270,63 @@ class Cache extends \Test\TestCase {
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
+ function testSearchByTag() {
+ $userId = $this->getUniqueId('user');
+ \OC_User::createUser($userId, $userId);
+ $this->loginAsUser($userId);
+ $user = new \OC\User\User($userId, null);
+
+ $file1 = 'folder';
+ $file2 = 'folder/foobar';
+ $file3 = 'folder/foo';
+ $file4 = 'folder/foo2';
+ $file5 = 'folder/foo3';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $fileData = array();
+ $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file');
+ $fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file');
+
+ $id1 = $this->cache->put($file1, $data1);
+ $id2 = $this->cache->put($file2, $fileData['foobar']);
+ $id3 = $this->cache->put($file3, $fileData['foo']);
+ $id4 = $this->cache->put($file4, $fileData['foo2']);
+ $id5 = $this->cache->put($file5, $fileData['foo3']);
+
+ $tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId);
+ $this->assertTrue($tagManager->tagAs($id1, 'tag1'));
+ $this->assertTrue($tagManager->tagAs($id1, 'tag2'));
+ $this->assertTrue($tagManager->tagAs($id2, 'tag2'));
+ $this->assertTrue($tagManager->tagAs($id3, 'tag1'));
+ $this->assertTrue($tagManager->tagAs($id4, 'tag2'));
+
+ // use tag name
+ $results = $this->cache->searchByTag('tag1', $userId);
+
+ $this->assertEquals(2, count($results));
+
+ $this->assertEquals('folder', $results[0]['name']);
+ $this->assertEquals('foo', $results[1]['name']);
+
+ // use tag id
+ $tags = $tagManager->getTagsForUser($userId);
+ $this->assertNotEmpty($tags);
+ $tags = array_filter($tags, function($tag) { return $tag->getName() === 'tag2'; });
+ $results = $this->cache->searchByTag(current($tags)->getId(), $userId);
+ $this->assertEquals(3, count($results));
+
+ $this->assertEquals('folder', $results[0]['name']);
+ $this->assertEquals('foobar', $results[1]['name']);
+ $this->assertEquals('foo2', $results[2]['name']);
+
+ $tagManager->delete('tag1');
+ $tagManager->delete('tag2');
+
+ $this->logout();
+ \OC_User::deleteUser($userId);
+ }
+
function testMove() {
$file1 = 'folder';
$file2 = 'folder/bar';
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index d8c047a2b75..e69a2776979 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -405,6 +405,45 @@ class Folder extends \Test\TestCase {
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
+ public function testSearchByTag() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $root->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+
+ $storage->expects($this->once())
+ ->method('getCache')
+ ->will($this->returnValue($cache));
+
+ $cache->expects($this->once())
+ ->method('searchByTag')
+ ->with('tag1', 'user1')
+ ->will($this->returnValue(array(
+ array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
+ )));
+
+ $root->expects($this->once())
+ ->method('getMountsIn')
+ ->with('/bar/foo')
+ ->will($this->returnValue(array()));
+
+ $view->expects($this->once())
+ ->method('resolvePath')
+ ->will($this->returnValue(array($storage, 'foo')));
+
+ $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $result = $node->searchByTag('tag1', 'user1');
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
+ }
+
public function testSearchSubStorages() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php
index 68f43b76f51..2235581add8 100644
--- a/tests/lib/l10n.php
+++ b/tests/lib/l10n.php
@@ -42,6 +42,24 @@ class Test_L10n extends \Test\TestCase {
*/
}
+ public function russianMissingPluralTranslationsData() {
+ return array(
+ array(1, '1 missing plural'),
+ array(2, '2 missing plurals'),
+ array(6, '6 missing plurals'),
+ );
+ }
+
+ /**
+ * @dataProvider russianMissingPluralTranslationsData
+ */
+ public function testRussianMissingPluralTranslations($count, $expected) {
+ $l = new OC_L10N('test');
+ $l->load(OC::$SERVERROOT.'/tests/data/l10n/ru.json');
+
+ $this->assertEquals($expected, (string)$l->n('%n missing plural', '%n missing plurals', $count));
+ }
+
public function testCzechPluralTranslations() {
$l = new OC_L10N('test');
$transFile = OC::$SERVERROOT.'/tests/data/l10n/cs.json';
diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php
index c97b7b32b0f..57bc2381966 100644
--- a/tests/lib/largefilehelpergetfilesize.php
+++ b/tests/lib/largefilehelpergetfilesize.php
@@ -13,6 +13,10 @@ namespace Test;
* Large files are not considered yet.
*/
class LargeFileHelperGetFileSize extends TestCase {
+ /** @var string */
+ protected $filename;
+ /** @var int */
+ protected $fileSize;
/** @var \OC\LargeFileHelper */
protected $helper;
@@ -41,6 +45,11 @@ class LargeFileHelperGetFileSize extends TestCase {
'The PHP curl extension is required for this test.'
);
}
+ if (\OC::$server->getIniWrapper()->getString('open_basedir') !== '') {
+ $this->markTestSkipped(
+ 'The PHP curl extension does not work with the file:// protocol when open_basedir is enabled.'
+ );
+ }
$this->assertSame(
$fileSize,
$this->helper->getFileSizeViaCurl($filename)
diff --git a/tests/lib/tags.php b/tests/lib/tags.php
index 78f5085df39..71296d2e346 100644
--- a/tests/lib/tags.php
+++ b/tests/lib/tags.php
@@ -23,7 +23,10 @@
class Test_Tags extends \Test\TestCase {
protected $objectType;
+ /** @var \OC\IUser */
protected $user;
+ /** @var \OC\IUserSession */
+ protected $userSession;
protected $backupGlobals = FALSE;
/** @var \OC\Tagging\TagMapper */
protected $tagMapper;
@@ -35,12 +38,19 @@ class Test_Tags extends \Test\TestCase {
OC_User::clearBackends();
OC_User::useBackend('dummy');
- $this->user = $this->getUniqueID('user_');
+ $userId = $this->getUniqueID('user_');
+ OC_User::createUser($userId, 'pass');
+ OC_User::setUserId($userId);
+ $this->user = new OC\User\User($userId, null);
+ $this->userSession = $this->getMock('\OCP\IUserSession');
+ $this->userSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+
$this->objectType = $this->getUniqueID('type_');
- OC_User::createUser($this->user, 'pass');
- OC_User::setUserId($this->user);
$this->tagMapper = new OC\Tagging\TagMapper(\OC::$server->getDb());
- $this->tagMgr = new OC\TagManager($this->tagMapper, $this->user);
+ $this->tagMgr = new OC\TagManager($this->tagMapper, $this->userSession);
}
@@ -166,7 +176,7 @@ class Test_Tags extends \Test\TestCase {
);
}
- public function testdeleteTags() {
+ public function testDeleteTags() {
$defaultTags = array('Friends', 'Family', 'Work', 'Other');
$tagger = $this->tagMgr->load($this->objectType, $defaultTags);
@@ -177,7 +187,6 @@ class Test_Tags extends \Test\TestCase {
$tagger->delete(array('Friends', 'Work', 'Other'));
$this->assertEquals(0, count($tagger->getTags()));
-
}
public function testRenameTag() {
@@ -233,27 +242,32 @@ class Test_Tags extends \Test\TestCase {
}
public function testShareTags() {
- $test_tag = 'TestTag';
+ $testTag = 'TestTag';
OCP\Share::registerBackend('test', 'Test_Share_Backend');
$tagger = $this->tagMgr->load('test');
- $tagger->tagAs(1, $test_tag);
-
- $other_user = $this->getUniqueID('user2_');
- OC_User::createUser($other_user, 'pass');
-
- OC_User::setUserId($other_user);
- $other_tagMgr = new OC\TagManager($this->tagMapper, $other_user);
- $other_tagger = $other_tagMgr->load('test');
- $this->assertFalse($other_tagger->hasTag($test_tag));
-
- OC_User::setUserId($this->user);
- OCP\Share::shareItem('test', 1, OCP\Share::SHARE_TYPE_USER, $other_user, \OCP\Constants::PERMISSION_READ);
-
- OC_User::setUserId($other_user);
- $other_tagger = $other_tagMgr->load('test', array(), true); // Update tags, load shared ones.
- $this->assertTrue($other_tagger->hasTag($test_tag));
- $this->assertContains(1, $other_tagger->getIdsForTag($test_tag));
+ $tagger->tagAs(1, $testTag);
+
+ $otherUserId = $this->getUniqueID('user2_');
+ OC_User::createUser($otherUserId, 'pass');
+ OC_User::setUserId($otherUserId);
+ $otherUserSession = $this->getMock('\OCP\IUserSession');
+ $otherUserSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue(new OC\User\User($otherUserId, null)));
+
+ $otherTagMgr = new OC\TagManager($this->tagMapper, $otherUserSession);
+ $otherTagger = $otherTagMgr->load('test');
+ $this->assertFalse($otherTagger->hasTag($testTag));
+
+ OC_User::setUserId($this->user->getUID());
+ OCP\Share::shareItem('test', 1, OCP\Share::SHARE_TYPE_USER, $otherUserId, \OCP\Constants::PERMISSION_READ);
+
+ OC_User::setUserId($otherUserId);
+ $otherTagger = $otherTagMgr->load('test', array(), true); // Update tags, load shared ones.
+ $this->assertTrue($otherTagger->hasTag($testTag));
+ $this->assertContains(1, $otherTagger->getIdsForTag($testTag));
}
}
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 27c28329535..1ea3aa13547 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -148,4 +148,25 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
\OC_FileProxy::$enabled = true;
\OC_FileProxy::clearProxies();
}
+
+ /**
+ * Login and setup FS as a given user,
+ * sets the given user as the current user.
+ *
+ * @param string $user user id
+ */
+ static protected function loginAsUser($user) {
+ self::logout();
+ \OC\Files\Filesystem::tearDown();
+ \OC_User::setUserId($user);
+ \OC_Util::setupFS($user);
+ }
+
+ /**
+ * Logout the current user and tear down the filesystem.
+ */
+ static protected function logout() {
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ }
}
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index c825ec05775..9cb9374d89f 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -10,6 +10,17 @@
namespace Test\User;
class Manager extends \Test\TestCase {
+ public function testGetBackends() {
+ $userDummyBackend = $this->getMock('\OC_User_Dummy');
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($userDummyBackend);
+ $this->assertEquals([$userDummyBackend], $manager->getBackends());
+ $dummyDatabaseBackend = $this->getMock('\OC_User_Database');
+ $manager->registerBackend($dummyDatabaseBackend);
+ $this->assertEquals([$userDummyBackend, $dummyDatabaseBackend], $manager->getBackends());
+ }
+
+
public function testUserExistsSingleBackendExists() {
/**
* @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index eb48babadc8..0ac6d3f0c01 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -126,9 +126,20 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUserGroupIds')
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users')));
$this->container['UserManager']
- ->expects($this->exactly(3))
+ ->expects($this->at(0))
+ ->method('get')
+ ->with('foo')
+ ->will($this->returnValue($foo));
+ $this->container['UserManager']
+ ->expects($this->at(1))
+ ->method('get')
+ ->with('admin')
+ ->will($this->returnValue($admin));
+ $this->container['UserManager']
+ ->expects($this->at(2))
->method('get')
- ->will($this->onConsecutiveCalls($foo, $admin, $bar));
+ ->with('bar')
+ ->will($this->returnValue($bar));
$this->container['Config']
->expects($this->exactly(3))
->method('getUserValue')
@@ -168,7 +179,79 @@ class UsersControllerTest extends \Test\TestCase {
),
)
);
- $response = $this->usersController->index(0, 10, 'pattern');
+ $response = $this->usersController->index(0, 10, 'gid', 'pattern');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testIndexWithBackend() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $user
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('M. Foo'));
+ $user
+ ->method('getLastLogin')
+ ->will($this->returnValue(500));
+ $user
+ ->method('getHome')
+ ->will($this->returnValue('/home/foo'));
+ $user
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('OC_User_Database'));
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('getBackends')
+ ->will($this->returnValue([new \OC_User_Dummy(), new \OC_User_Database()]));
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('clearBackends');
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('registerBackend')
+ ->with(new \OC_User_Dummy());
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue([$user]));
+
+ $expectedResponse = new DataResponse(
+ array(
+ 0 => array(
+ 'name' => 'foo',
+ 'displayname' => 'M. Foo',
+ 'groups' => null,
+ 'subadmin' => array(),
+ 'quota' => null,
+ 'storageLocation' => '/home/foo',
+ 'lastLogin' => 500,
+ 'backend' => 'OC_User_Database'
+ )
+ )
+ );
+ $response = $this->usersController->index(0, 10, '','', 'OC_User_Dummy');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testIndexWithBackendNoUser() {
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('getBackends')
+ ->will($this->returnValue([new \OC_User_Dummy(), new \OC_User_Database()]));
+ $this->container['UserManager']
+ ->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue([]));
+
+ $expectedResponse = new DataResponse([]);
+ $response = $this->usersController->index(0, 10, '','', 'OC_User_Dummy');
$this->assertEquals($expectedResponse, $response);
}
@@ -182,6 +265,10 @@ class UsersControllerTest extends \Test\TestCase {
$user
->method('getHome')
->will($this->returnValue('/home/user'));
+ $user
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('bar'));
$this->container['UserManager']
->expects($this->once())
@@ -193,7 +280,8 @@ class UsersControllerTest extends \Test\TestCase {
array(
'username' => 'foo',
'groups' => null,
- 'storageLocation' => '/home/user'
+ 'storageLocation' => '/home/user',
+ 'backend' => 'bar'
),
Http::STATUS_CREATED
);
@@ -214,6 +302,10 @@ class UsersControllerTest extends \Test\TestCase {
$user
->method('getHome')
->will($this->returnValue('/home/user'));
+ $user
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('bar'));
$existingGroup = $this->getMockBuilder('\OCP\IGroup')
->disableOriginalConstructor()->getMock();
$existingGroup
@@ -250,7 +342,8 @@ class UsersControllerTest extends \Test\TestCase {
array(
'username' => 'foo',
'groups' => array('NewGroup', 'ExistingGroup'),
- 'storageLocation' => '/home/user'
+ 'storageLocation' => '/home/user',
+ 'backend' => 'bar'
),
Http::STATUS_CREATED
);