|  |  | @ -28,10 +28,12 @@ use OCP\App\IAppManager; | 
			
		
	
		
			
				
					|  |  |  | use OCP\Http\Client\IClientService; | 
			
		
	
		
			
				
					|  |  |  | use OCP\IConfig; | 
			
		
	
		
			
				
					|  |  |  | use OCP\IGroupManager; | 
			
		
	
		
			
				
					|  |  |  | use OCP\IURLGenerator; | 
			
		
	
		
			
				
					|  |  |  | use OCP\IUser; | 
			
		
	
		
			
				
					|  |  |  | use OCP\Notification\IManager; | 
			
		
	
		
			
				
					|  |  |  | use Test\TestCase; | 
			
		
	
		
			
				
					|  |  |  | use OC\Updater\VersionCheck; | 
			
		
	
		
			
				
					|  |  |  | use OCP\Notification\INotification; | 
			
		
	
		
			
				
					|  |  |  | use OCP\IGroup; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -49,11 +51,11 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 	public function setUp() { | 
			
		
	
		
			
				
					|  |  |  | 		parent::setUp(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$this->config = $this->createMock(\OCP\IConfig::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->notificationManager = $this->createMock(\OCP\Notification\IManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->groupManager = $this->createMock(\OCP\IGroupManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->appManager = $this->createMock(\OCP\App\IAppManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->client = $this->createMock(\OCP\Http\Client\IClientService::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->config = $this->createMock(IConfig::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->notificationManager = $this->createMock(IManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->groupManager = $this->createMock(IGroupManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->appManager = $this->createMock(IAppManager::class); | 
			
		
	
		
			
				
					|  |  |  | 		$this->client = $this->createMock(IClientService::class); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
	
		
			
				
					|  |  | @ -70,7 +72,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 				$this->client | 
			
		
	
		
			
				
					|  |  |  | 			); | 
			
		
	
		
			
				
					|  |  |  | 		} { | 
			
		
	
		
			
				
					|  |  |  | 			return $this->getMockBuilder('OCA\UpdateNotification\Notification\BackgroundJob') | 
			
		
	
		
			
				
					|  |  |  | 			return $this->getMockBuilder(BackgroundJob::class) | 
			
		
	
		
			
				
					|  |  |  | 				->setConstructorArgs([ | 
			
		
	
		
			
				
					|  |  |  | 					$this->config, | 
			
		
	
		
			
				
					|  |  |  | 					$this->notificationManager, | 
			
		
	
	
		
			
				
					|  |  | @ -94,28 +96,34 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 		$job->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 			->method('checkAppUpdates'); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$this->invokePrivate($job, 'run', [null]); | 
			
		
	
		
			
				
					|  |  |  | 		self::invokePrivate($job, 'run', [null]); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	public function dataCheckCoreUpdate() { | 
			
		
	
		
			
				
					|  |  |  | 		return [ | 
			
		
	
		
			
				
					|  |  |  | 			['daily', null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['git', null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['beta', false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['daily', null, null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['git', null, null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['beta', [], null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['beta', false, false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['beta', false, false, null, 13], | 
			
		
	
		
			
				
					|  |  |  | 			['beta', [ | 
			
		
	
		
			
				
					|  |  |  | 				'version' => '9.2.0', | 
			
		
	
		
			
				
					|  |  |  | 				'versionstring' => 'Nextcloud 11.0.0', | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0'], | 
			
		
	
		
			
				
					|  |  |  | 			['stable', false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0', null], | 
			
		
	
		
			
				
					|  |  |  | 			['stable', [], null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['stable', false, false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['stable', false, false, null, 6], | 
			
		
	
		
			
				
					|  |  |  | 			['stable', [ | 
			
		
	
		
			
				
					|  |  |  | 				'version' => '9.2.0', | 
			
		
	
		
			
				
					|  |  |  | 				'versionstring' => 'Nextcloud 11.0.0', | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0'], | 
			
		
	
		
			
				
					|  |  |  | 			['production', false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0', null], | 
			
		
	
		
			
				
					|  |  |  | 			['production', [], null, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['production', false, false, null, null], | 
			
		
	
		
			
				
					|  |  |  | 			['production', false, false, null, 2], | 
			
		
	
		
			
				
					|  |  |  | 			['production', [ | 
			
		
	
		
			
				
					|  |  |  | 				'version' => '9.2.0', | 
			
		
	
		
			
				
					|  |  |  | 				'versionstring' => 'Nextcloud 11.0.0', | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0'], | 
			
		
	
		
			
				
					|  |  |  | 			], '9.2.0', 'Nextcloud 11.0.0', null], | 
			
		
	
		
			
				
					|  |  |  | 		]; | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -124,14 +132,17 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 	 * | 
			
		
	
		
			
				
					|  |  |  | 	 * @param string $channel | 
			
		
	
		
			
				
					|  |  |  | 	 * @param mixed $versionCheck | 
			
		
	
		
			
				
					|  |  |  | 	 * @param null|string $notification | 
			
		
	
		
			
				
					|  |  |  | 	 * @param null|string $version | 
			
		
	
		
			
				
					|  |  |  | 	 * @param null|string $readableVersion | 
			
		
	
		
			
				
					|  |  |  | 	 * @param null|int $errorDays | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	public function testCheckCoreUpdate($channel, $versionCheck, $notification, $readableVersion) { | 
			
		
	
		
			
				
					|  |  |  | 	public function testCheckCoreUpdate($channel, $versionCheck, $version, $readableVersion, $errorDays) { | 
			
		
	
		
			
				
					|  |  |  | 		$job = $this->getJob([ | 
			
		
	
		
			
				
					|  |  |  | 			'getChannel', | 
			
		
	
		
			
				
					|  |  |  | 			'createVersionCheck', | 
			
		
	
		
			
				
					|  |  |  | 			'createNotifications', | 
			
		
	
		
			
				
					|  |  |  | 			'clearErrorNotifications', | 
			
		
	
		
			
				
					|  |  |  | 			'sendErrorNotifications', | 
			
		
	
		
			
				
					|  |  |  | 		]); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$job->expects($this->once()) | 
			
		
	
	
		
			
				
					|  |  | @ -142,9 +153,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('createVersionCheck'); | 
			
		
	
		
			
				
					|  |  |  | 		} else { | 
			
		
	
		
			
				
					|  |  |  | 			$check = $this->getMockBuilder('OC\Updater\VersionCheck') | 
			
		
	
		
			
				
					|  |  |  | 				->disableOriginalConstructor() | 
			
		
	
		
			
				
					|  |  |  | 				->getMock(); | 
			
		
	
		
			
				
					|  |  |  | 			$check = $this->createMock(VersionCheck::class); | 
			
		
	
		
			
				
					|  |  |  | 			$check->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('check') | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn($versionCheck); | 
			
		
	
	
		
			
				
					|  |  | @ -154,16 +163,38 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn($check); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		if ($notification === null) { | 
			
		
	
		
			
				
					|  |  |  | 		if ($version === null) { | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('createNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('clearErrorNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 		} else if ($version === false) { | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('createNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('clearErrorNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 			$this->config->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('getAppValue') | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn($errorDays); | 
			
		
	
		
			
				
					|  |  |  | 			$this->config->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('setAppValue') | 
			
		
	
		
			
				
					|  |  |  | 				->with('updatenotification', 'update_check_errors', $errorDays + 1); | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($errorDays !== null ? $this->once() : $this->never()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('sendErrorNotifications') | 
			
		
	
		
			
				
					|  |  |  | 				->with($errorDays + 1); | 
			
		
	
		
			
				
					|  |  |  | 		} else { | 
			
		
	
		
			
				
					|  |  |  | 			$this->config->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('setAppValue') | 
			
		
	
		
			
				
					|  |  |  | 				->with('updatenotification', 'update_check_errors', 0); | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('clearErrorNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 			$job->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('createNotifications') | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn('core', $notification, $readableVersion); | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn('core', $version, $readableVersion); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$this->invokePrivate($job, 'checkCoreUpdate'); | 
			
		
	
		
			
				
					|  |  |  | 		self::invokePrivate($job, 'checkCoreUpdate'); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	public function dataCheckAppUpdates() { | 
			
		
	
	
		
			
				
					|  |  | @ -198,15 +229,15 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 			->method('getInstalledApps') | 
			
		
	
		
			
				
					|  |  |  | 			->willReturn($apps); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$job->expects($this->exactly(sizeof($apps))) | 
			
		
	
		
			
				
					|  |  |  | 		$job->expects($this->exactly(count($apps))) | 
			
		
	
		
			
				
					|  |  |  | 			->method('isUpdateAvailable') | 
			
		
	
		
			
				
					|  |  |  | 			->willReturnMap($isUpdateAvailable); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$mockedMethod = $job->expects($this->exactly(sizeof($notifications))) | 
			
		
	
		
			
				
					|  |  |  | 		$mockedMethod = $job->expects($this->exactly(count($notifications))) | 
			
		
	
		
			
				
					|  |  |  | 			->method('createNotifications'); | 
			
		
	
		
			
				
					|  |  |  | 		call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$this->invokePrivate($job, 'checkAppUpdates'); | 
			
		
	
		
			
				
					|  |  |  | 		self::invokePrivate($job, 'checkAppUpdates'); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	public function dataCreateNotifications() { | 
			
		
	
	
		
			
				
					|  |  | @ -264,7 +295,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		if ($createNotification) { | 
			
		
	
		
			
				
					|  |  |  | 			$notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock(); | 
			
		
	
		
			
				
					|  |  |  | 			$notification = $this->createMock(INotification::class); | 
			
		
	
		
			
				
					|  |  |  | 			$notification->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('setApp') | 
			
		
	
		
			
				
					|  |  |  | 				->with('updatenotification') | 
			
		
	
	
		
			
				
					|  |  | @ -282,12 +313,12 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 				->willReturnSelf(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 			if ($userNotifications !== null) { | 
			
		
	
		
			
				
					|  |  |  | 				$mockedMethod = $notification->expects($this->exactly(sizeof($userNotifications))) | 
			
		
	
		
			
				
					|  |  |  | 				$mockedMethod = $notification->expects($this->exactly(count($userNotifications))) | 
			
		
	
		
			
				
					|  |  |  | 					->method('setUser') | 
			
		
	
		
			
				
					|  |  |  | 					->willReturnSelf(); | 
			
		
	
		
			
				
					|  |  |  | 				call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 				$this->notificationManager->expects($this->exactly(sizeof($userNotifications))) | 
			
		
	
		
			
				
					|  |  |  | 				$this->notificationManager->expects($this->exactly(count($userNotifications))) | 
			
		
	
		
			
				
					|  |  |  | 					->method('notify') | 
			
		
	
		
			
				
					|  |  |  | 					->willReturn($notification); | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
	
		
			
				
					|  |  | @ -300,7 +331,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 				->method('createNotification'); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$this->invokePrivate($job, 'createNotifications', [$app, $version]); | 
			
		
	
		
			
				
					|  |  |  | 		self::invokePrivate($job, 'createNotifications', [$app, $version]); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	public function dataGetUsersToNotify() { | 
			
		
	
	
		
			
				
					|  |  | @ -336,15 +367,15 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  | 			$groupMap[] = [$gid, $group]; | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 		$this->groupManager->expects($this->exactly(sizeof($groups))) | 
			
		
	
		
			
				
					|  |  |  | 		$this->groupManager->expects($this->exactly(count($groups))) | 
			
		
	
		
			
				
					|  |  |  | 			->method('get') | 
			
		
	
		
			
				
					|  |  |  | 			->willReturnMap($groupMap); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$result = $this->invokePrivate($job, 'getUsersToNotify'); | 
			
		
	
		
			
				
					|  |  |  | 		$result = self::invokePrivate($job, 'getUsersToNotify'); | 
			
		
	
		
			
				
					|  |  |  | 		$this->assertEquals($expected, $result); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		// Test caching
 | 
			
		
	
		
			
				
					|  |  |  | 		$result = $this->invokePrivate($job, 'getUsersToNotify'); | 
			
		
	
		
			
				
					|  |  |  | 		$result = self::invokePrivate($job, 'getUsersToNotify'); | 
			
		
	
		
			
				
					|  |  |  | 		$this->assertEquals($expected, $result); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -361,7 +392,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 	 * @param string $version | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	public function testDeleteOutdatedNotifications($app, $version) { | 
			
		
	
		
			
				
					|  |  |  | 		$notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock(); | 
			
		
	
		
			
				
					|  |  |  | 		$notification = $this->createMock(INotification::class); | 
			
		
	
		
			
				
					|  |  |  | 		$notification->expects($this->once()) | 
			
		
	
		
			
				
					|  |  |  | 			->method('setApp') | 
			
		
	
		
			
				
					|  |  |  | 			->with('updatenotification') | 
			
		
	
	
		
			
				
					|  |  | @ -379,7 +410,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 			->with($notification); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$job = $this->getJob(); | 
			
		
	
		
			
				
					|  |  |  | 		$this->invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]); | 
			
		
	
		
			
				
					|  |  |  | 		self::invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
	
		
			
				
					|  |  | @ -389,7 +420,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 	protected function getUsers(array $userIds) { | 
			
		
	
		
			
				
					|  |  |  | 		$users = []; | 
			
		
	
		
			
				
					|  |  |  | 		foreach ($userIds as $uid) { | 
			
		
	
		
			
				
					|  |  |  | 			$user = $this->getMockBuilder('OCP\IUser')->getMock(); | 
			
		
	
		
			
				
					|  |  |  | 			$user = $this->createMock(IUser::class); | 
			
		
	
		
			
				
					|  |  |  | 			$user->expects($this->any()) | 
			
		
	
		
			
				
					|  |  |  | 				->method('getUID') | 
			
		
	
		
			
				
					|  |  |  | 				->willReturn($uid); | 
			
		
	
	
		
			
				
					|  |  | @ -403,7 +434,7 @@ class BackgroundJobTest extends TestCase { | 
			
		
	
		
			
				
					|  |  |  | 	 * @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	protected function getGroup($gid) { | 
			
		
	
		
			
				
					|  |  |  | 		$group = $this->getMockBuilder('OCP\IGroup')->getMock(); | 
			
		
	
		
			
				
					|  |  |  | 		$group = $this->createMock(IGroup::class); | 
			
		
	
		
			
				
					|  |  |  | 		$group->expects($this->any()) | 
			
		
	
		
			
				
					|  |  |  | 			->method('getGID') | 
			
		
	
		
			
				
					|  |  |  | 			->willReturn($gid); | 
			
		
	
	
		
			
				
					|  |  | 
 |