summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-02-07 12:01:28 +0100
committerJoas Schilling <coding@schilljs.com>2017-02-07 12:01:28 +0100
commitd79838ac9b2feb61ab2d07961f7679d882383c9e (patch)
treee92067884f7497ef8afee2ae1e5396e3e5cc2c53
parent881c7275a2d91eb5c9ab78051d7c1b5f2d5f6718 (diff)
downloadnextcloud-server-d79838ac9b2feb61ab2d07961f7679d882383c9e.tar.gz
nextcloud-server-d79838ac9b2feb61ab2d07961f7679d882383c9e.zip
Add tests for getUser()
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/files/tests/Activity/ProviderTest.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/files/tests/Activity/ProviderTest.php b/apps/files/tests/Activity/ProviderTest.php
index a79e476df9a..6cb89961a1b 100644
--- a/apps/files/tests/Activity/ProviderTest.php
+++ b/apps/files/tests/Activity/ProviderTest.php
@@ -27,6 +27,7 @@ use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
use OCP\IURLGenerator;
+use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use Test\TestCase;
@@ -134,4 +135,74 @@ class ProviderTest extends TestCase {
$provider = $this->getProvider();
self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]);
}
+
+ public function dataGetUser() {
+ return [
+ ['test', [], false, 'Test'],
+ ['foo', ['admin' => 'Admin'], false, 'Bar'],
+ ['admin', ['admin' => 'Administrator'], true, 'Administrator'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetUser
+ * @param string $uid
+ * @param array $cache
+ * @param bool $cacheHit
+ * @param string $name
+ */
+ public function testGetUser($uid, $cache, $cacheHit, $name) {
+ $provider = $this->getProvider(['getDisplayName']);
+
+ self::invokePrivate($provider, 'displayNames', [$cache]);
+
+ if (!$cacheHit) {
+ $provider->expects($this->once())
+ ->method('getDisplayName')
+ ->with($uid)
+ ->willReturn($name);
+ } else {
+ $provider->expects($this->never())
+ ->method('getDisplayName');
+ }
+
+ $result = self::invokePrivate($provider, 'getUser', [$uid]);
+ $this->assertSame('user', $result['type']);
+ $this->assertSame($uid, $result['id']);
+ $this->assertSame($name, $result['name']);
+ }
+
+ public function dataGetDisplayName() {
+ return [
+ ['test', true, 'Test'],
+ ['foo', false, 'foo'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetDisplayName
+ * @param string $uid
+ * @param string $name
+ */
+ public function testGetDisplayNamer($uid, $validUser, $name) {
+ $provider = $this->getProvider();
+
+ if ($validUser) {
+ $user = $this->createMock(IUser::class);
+ $user->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn($name);
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with($uid)
+ ->willReturn($user);
+ } else {
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with($uid)
+ ->willReturn(null);
+ }
+
+ $this->assertSame($name, self::invokePrivate($provider, 'getDisplayName', [$uid]));
+ }
}