diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-10 11:31:03 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-24 11:26:54 +0200 |
commit | a1e872aad6c2483e7349609690f9172192f4559a (patch) | |
tree | fce82d98c264df866e1aa4f8aad44bec4df03702 /apps/updatenotification/tests | |
parent | 12ec0dfe3cb9d960aabed5d1c92ded7c0a745b02 (diff) | |
download | nextcloud-server-a1e872aad6c2483e7349609690f9172192f4559a.tar.gz nextcloud-server-a1e872aad6c2483e7349609690f9172192f4559a.zip |
Add a URL to the notifications
Diffstat (limited to 'apps/updatenotification/tests')
-rw-r--r-- | apps/updatenotification/tests/Notification/BackgroundJobTest.php | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php index 9b920ec4ce7..d1076e10be5 100644 --- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php +++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php @@ -22,14 +22,12 @@ namespace OCA\UpdateNotification\Tests\Notification; -use OC\Installer; -use OC\Updater\VersionCheck; use OCA\UpdateNotification\Notification\BackgroundJob; use OCP\App\IAppManager; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\IGroup; use OCP\IGroupManager; +use OCP\IURLGenerator; use OCP\IUser; use OCP\Notification\IManager; use Test\TestCase; @@ -46,6 +44,8 @@ class BackgroundJobTest extends TestCase { protected $appManager; /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */ protected $client; + /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ + protected $urlGenerator; public function setUp() { parent::setUp(); @@ -55,6 +55,7 @@ class BackgroundJobTest extends TestCase { $this->groupManager = $this->getMock('OCP\IGroupManager'); $this->appManager = $this->getMock('OCP\App\IAppManager'); $this->client = $this->getMock('OCP\Http\Client\IClientService'); + $this->urlGenerator = $this->getMock('OCP\IURLGenerator'); } /** @@ -68,7 +69,8 @@ class BackgroundJobTest extends TestCase { $this->notificationManager, $this->groupManager, $this->appManager, - $this->client + $this->client, + $this->urlGenerator ); } { return $this->getMockBuilder('OCA\UpdateNotification\Notification\BackgroundJob') @@ -78,6 +80,7 @@ class BackgroundJobTest extends TestCase { $this->groupManager, $this->appManager, $this->client, + $this->urlGenerator, ]) ->setMethods($methods) ->getMock(); @@ -134,7 +137,7 @@ class BackgroundJobTest extends TestCase { $job->expects($this->once()) ->method('getChannel') ->willReturn($channel); - + if ($versionCheck === null) { $job->expects($this->never()) ->method('createVersionCheck'); @@ -152,12 +155,20 @@ class BackgroundJobTest extends TestCase { } if ($notification === null) { + $this->urlGenerator->expects($this->never()) + ->method('linkToRouteAbsolute'); + $job->expects($this->never()) ->method('createNotifications'); } else { + $this->urlGenerator->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with('settings_admin') + ->willReturn('admin-url'); + $job->expects($this->once()) ->method('createNotifications') - ->willReturn('core', $notification); + ->willReturn('core', $notification, 'admin-url#updater'); } $this->invokePrivate($job, 'checkCoreUpdate'); @@ -172,7 +183,7 @@ class BackgroundJobTest extends TestCase { ['app2', '1.9.2'], ], [ - ['app2', '1.9.2'], + ['app2', '1.9.2', 'apps-url#app-app2'], ], ], ]; @@ -199,6 +210,11 @@ class BackgroundJobTest extends TestCase { ->method('isUpdateAvailable') ->willReturnMap($isUpdateAvailable); + $this->urlGenerator->expects($this->exactly(sizeof($notifications))) + ->method('linkToRouteAbsolute') + ->with('settings.AppSettings.viewApps') + ->willReturn('apps-url'); + $mockedMethod = $job->expects($this->exactly(sizeof($notifications))) ->method('createNotifications'); call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications); @@ -208,9 +224,9 @@ class BackgroundJobTest extends TestCase { public function dataCreateNotifications() { return [ - ['app1', '1.0.0', '1.0.0', false, false, null, null], - ['app2', '1.0.1', '1.0.0', '1.0.0', true, ['user1'], [['user1']]], - ['app3', '1.0.1', false, false, true, ['user2', 'user3'], [['user2'], ['user3']]], + ['app1', '1.0.0', 'link1', '1.0.0', false, false, null, null], + ['app2', '1.0.1', 'link2', '1.0.0', '1.0.0', true, ['user1'], [['user1']]], + ['app3', '1.0.1', 'link3', false, false, true, ['user2', 'user3'], [['user2'], ['user3']]], ]; } @@ -219,13 +235,14 @@ class BackgroundJobTest extends TestCase { * * @param string $app * @param string $version + * @param string $url * @param string|false $lastNotification * @param string|false $callDelete * @param bool $createNotification * @param string[]|null $users * @param array|null $userNotifications */ - public function testCreateNotifications($app, $version, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) { + public function testCreateNotifications($app, $version, $url, $lastNotification, $callDelete, $createNotification, $users, $userNotifications) { $job = $this->getJob([ 'deleteOutdatedNotifications', 'getUsersToNotify', @@ -277,6 +294,10 @@ class BackgroundJobTest extends TestCase { ->method('setSubject') ->with('update_available') ->willReturnSelf(); + $notification->expects($this->once()) + ->method('setLink') + ->with($url) + ->willReturnSelf(); if ($userNotifications !== null) { $mockedMethod = $notification->expects($this->exactly(sizeof($userNotifications))) @@ -297,7 +318,7 @@ class BackgroundJobTest extends TestCase { ->method('createNotification'); } - $this->invokePrivate($job, 'createNotifications', [$app, $version]); + $this->invokePrivate($job, 'createNotifications', [$app, $version, $url]); } public function dataGetUsersToNotify() { |