diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-08-22 18:46:47 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-08-29 12:03:13 +0200 |
commit | eea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10 (patch) | |
tree | 0275cd987792cc020717495203b08845e9f43085 /apps/files/tests/HelperTest.php | |
parent | 141bee931f0e1f51cd81772c5ac60274bc0df8d7 (diff) | |
download | nextcloud-server-eea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10.tar.gz nextcloud-server-eea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10.zip |
Correctly format OCS response with favorites
The helper funtion did not handle the response correctly and basically
only returned the last share with tags.
This is a simple rewrite. That is still understandable. Loops maybe more
than strictly required. But preformance is not the issue here.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files/tests/HelperTest.php')
-rw-r--r-- | apps/files/tests/HelperTest.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/apps/files/tests/HelperTest.php b/apps/files/tests/HelperTest.php index 8afd52abd95..901e86ddb20 100644 --- a/apps/files/tests/HelperTest.php +++ b/apps/files/tests/HelperTest.php @@ -112,4 +112,35 @@ class HelperTest extends \Test\TestCase { ); } + public function testPopulateTags() { + $tagManager = $this->createMock(\OCP\ITagManager::class); + $tagger = $this->createMock(\OCP\ITags::class); + + $tagManager->method('load') + ->with('files') + ->willReturn($tagger); + + $data = [ + ['id' => 10], + ['id' => 22, 'foo' => 'bar'], + ['id' => 42, 'x' => 'y'], + ]; + + $tags = [ + 10 => ['tag3'], + 42 => ['tag1', 'tag2'], + ]; + + $tagger->method('getTagsForObjects') + ->with([10, 22, 42]) + ->willReturn($tags); + + $result = \OCA\Files\Helper::populateTags($data, 'id', $tagManager); + + $this->assertSame([ + ['id' => 10, 'tags' => ['tag3']], + ['id' => 22, 'foo' => 'bar', 'tags' => []], + ['id' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], + ], $result); + } } |