summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-12-10 15:59:41 +0100
committerVincent Petry <pvince81@owncloud.com>2014-12-11 12:22:28 +0100
commit745d8706b973ff0494af54f183acc0da361f0e83 (patch)
tree33830b5690368c6c1e66a6bf1125635975a2490e /tests
parent5101bc54faea28d1210eb24f72abd76944c83af6 (diff)
downloadnextcloud-server-745d8706b973ff0494af54f183acc0da361f0e83.tar.gz
nextcloud-server-745d8706b973ff0494af54f183acc0da361f0e83.zip
Add user parameter to tag manager
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/tags.php62
1 files changed, 38 insertions, 24 deletions
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));
}
}