From 3e5d725502e403df5a5af4a197f4b94d147efccf Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Tue, 30 Sep 2014 12:19:08 +0200 Subject: [PATCH] Test addMultiple() with $sync=true. --- lib/private/tags.php | 1 + tests/lib/tags.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/private/tags.php b/lib/private/tags.php index 0e58789ecd5..ca04953e42c 100644 --- a/lib/private/tags.php +++ b/lib/private/tags.php @@ -357,6 +357,7 @@ class Tags implements \OCP\ITags { \OCP\Util::ERROR); } } + // reload tags to get the proper ids. $this->loadTags(); // Loop through temporarily cached objectid/tagname pairs diff --git a/tests/lib/tags.php b/tests/lib/tags.php index 3eba470a509..9195587f1dd 100644 --- a/tests/lib/tags.php +++ b/tests/lib/tags.php @@ -84,7 +84,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() { -- 2.39.5