From 16e5c15c283c40fd9c7a3f009f054b825bcadbb7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Aug 2015 16:31:54 +0200 Subject: [PATCH] Add tests for "getRemote()" --- apps/files_sharing/tests/api/sharees.php | 85 +++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/api/sharees.php b/apps/files_sharing/tests/api/sharees.php index 25074e4e8c..04b8ef5025 100644 --- a/apps/files_sharing/tests/api/sharees.php +++ b/apps/files_sharing/tests/api/sharees.php @@ -34,6 +34,9 @@ class ShareesTest extends TestCase { /** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ protected $groupManager; + /** @var \OCP\Contacts\IManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $contactsManager; + /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $session; @@ -48,6 +51,10 @@ class ShareesTest extends TestCase { ->disableOriginalConstructor() ->getMock(); + $this->contactsManager = $this->getMockBuilder('OCP\Contacts\IManager') + ->disableOriginalConstructor() + ->getMock(); + $this->session = $this->getMockBuilder('OCP\IUserSession') ->disableOriginalConstructor() ->getMock(); @@ -55,7 +62,7 @@ class ShareesTest extends TestCase { $this->sharees = new Sharees( $this->groupManager, $this->userManager, - $this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock(), + $this->contactsManager, $this->getMockBuilder('OCP\IAppConfig')->disableOriginalConstructor()->getMock(), $this->session, $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock() @@ -261,6 +268,82 @@ class ShareesTest extends TestCase { $this->assertEquals($expected, $users); } + public function dataGetRemote() { + return [ + ['test', [], []], + [ + 'test@remote', + [], + [ + ['label' => 'test@remote', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']], + ], + ], + [ + 'test', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'CLOUD' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'CLOUD' => [ + 'username@localhost', + ], + ], + ], + [ + ['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost']], + ], + ], + [ + 'test@remote', + [ + [ + 'FN' => 'User3 @ Localhost', + ], + [ + 'FN' => 'User2 @ Localhost', + 'CLOUD' => [ + ], + ], + [ + 'FN' => 'User @ Localhost', + 'CLOUD' => [ + 'username@localhost', + ], + ], + ], + [ + ['label' => 'test@remote', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']], + ['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost']], + ], + ], + ]; + } + + /** + * @dataProvider dataGetRemote + * + * @param string $searchTerm + * @param array $contacts + * @param array $expected + */ + public function testGetRemote($searchTerm, $contacts, $expected) { + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($searchTerm, ['CLOUD', 'FN']) + ->willReturn($contacts); + + $users = $this->invokePrivate($this->sharees, 'getRemote', [$searchTerm]); + + $this->assertEquals($expected, $users); + } + // public function testArguments() { // // }