diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-10-16 15:36:04 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-10-16 15:36:04 +0200 |
commit | 5f3ddf5c803a3071e21282e98b9bb75d905b8833 (patch) | |
tree | 21480cec842ec128ab754ce63fdc63fd57f2b922 /tests | |
parent | 8553e04a7888b9cfaac906dad439f940475695c1 (diff) | |
parent | b416f7d8acabebec94e771394b9e3d69c69cadd5 (diff) | |
download | nextcloud-server-5f3ddf5c803a3071e21282e98b9bb75d905b8833.tar.gz nextcloud-server-5f3ddf5c803a3071e21282e98b9bb75d905b8833.zip |
Merge pull request #11383 from ockham/share-tags2
Share tags
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share/backend.php | 3 | ||||
-rw-r--r-- | tests/lib/tags.php | 64 |
2 files changed, 62 insertions, 5 deletions
diff --git a/tests/lib/share/backend.php b/tests/lib/share/backend.php index 50ce24e07b6..61b8f262a42 100644 --- a/tests/lib/share/backend.php +++ b/tests/lib/share/backend.php @@ -29,9 +29,10 @@ class Test_Share_Backend implements OCP\Share_Backend { private $testItem1 = 'test.txt'; private $testItem2 = 'share.txt'; + private $testId = 1; public function isValidSource($itemSource, $uidOwner) { - if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2) { + if ($itemSource == $this->testItem1 || $itemSource == $this->testItem2 || $itemSource == 1) { return true; } } diff --git a/tests/lib/tags.php b/tests/lib/tags.php index 976b4b4fdc8..2f7a1e817f8 100644 --- a/tests/lib/tags.php +++ b/tests/lib/tags.php @@ -34,7 +34,8 @@ class Test_Tags extends PHPUnit_Framework_TestCase { $this->objectType = uniqid('type_'); OC_User::createUser($this->user, 'pass'); OC_User::setUserId($this->user); - $this->tagMgr = new OC\TagManager($this->user); + $this->tagMapper = new OC\Tagging\TagMapper(new OC\AppFramework\Db\Db()); + $this->tagMgr = new OC\TagManager($this->tagMapper, $this->user); } @@ -84,7 +85,36 @@ class Test_Tags extends PHPUnit_Framework_TestCase { $this->assertTrue($tagger->hasTag($tag)); } - $this->assertCount(4, $tagger->getTags(), 'Not all tags added'); + $tagMaps = $tagger->getTags(); + $this->assertCount(4, $tagMaps, 'Not all tags added'); + foreach($tagMaps as $tagMap) { + $this->assertEquals(null, $tagMap['id']); + } + + // As addMultiple has been called without $sync=true, the tags aren't + // saved to the database, so they're gone when we reload $tagger: + + $tagger = $this->tagMgr->load($this->objectType); + $this->assertEquals(0, count($tagger->getTags())); + + // Now, we call addMultiple() with $sync=true so the tags will be + // be saved to the database. + $result = $tagger->addMultiple($tags, true); + $this->assertTrue((bool)$result); + + $tagMaps = $tagger->getTags(); + foreach($tagMaps as $tagMap) { + $this->assertNotEquals(null, $tagMap['id']); + } + + // Reload the tagger. + $tagger = $this->tagMgr->load($this->objectType); + + foreach($tags as $tag) { + $this->assertTrue($tagger->hasTag($tag)); + } + + $this->assertCount(4, $tagger->getTags(), 'Not all previously saved tags found'); } public function testIsEmpty() { @@ -120,8 +150,8 @@ class Test_Tags extends PHPUnit_Framework_TestCase { $this->assertTrue($tagger->rename('Wrok', 'Work')); $this->assertTrue($tagger->hasTag('Work')); $this->assertFalse($tagger->hastag('Wrok')); - $this->assertFalse($tagger->rename('Wrok', 'Work')); - + $this->assertFalse($tagger->rename('Wrok', 'Work')); // Rename non-existant tag. + $this->assertFalse($tagger->rename('Work', 'Family')); // Collide with existing tag. } public function testTagAs() { @@ -160,7 +190,33 @@ class Test_Tags extends PHPUnit_Framework_TestCase { public function testFavorite() { $tagger = $this->tagMgr->load($this->objectType); $this->assertTrue($tagger->addToFavorites(1)); + $this->assertEquals(array(1), $tagger->getFavorites()); $this->assertTrue($tagger->removeFromFavorites(1)); + $this->assertEquals(array(), $tagger->getFavorites()); + } + + public function testShareTags() { + $test_tag = 'TestTag'; + OCP\Share::registerBackend('test', 'Test_Share_Backend'); + + $tagger = $this->tagMgr->load('test'); + $tagger->tagAs(1, $test_tag); + + $other_user = uniqid('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\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)); } } |