From 1e0761c6b8f035e73f89afa66dcdcf032e5f917d Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@arthur-schiwon.de>
Date: Fri, 1 Jun 2018 10:29:46 +0200
Subject: [PATCH] adjust tests

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
---
 apps/updatenotification/lib/UpdateChecker.php        | 2 +-
 apps/updatenotification/tests/Settings/AdminTest.php | 4 ++++
 apps/updatenotification/tests/UpdateCheckerTest.php  | 6 ++++++
 lib/private/Updater/VersionCheck.php                 | 2 +-
 tests/lib/Updater/VersionCheckTest.php               | 6 ++++++
 5 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index f7b45a03f26..ec8e119049b 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -59,7 +59,7 @@ class UpdateChecker {
 			if (strpos($data['changelog'], 'https://') === 0) {
 				$result['changelog'] = $data['changelog'];
 			}
-			if($data['whatsNew'] !== null) {
+			if (is_array($data['whatsNew']) && count($data['whatsNew']) <= 3) {
 				$result['whatsNew'] = $data['whatsNew'];
 			}
 
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index d5915a9c102..3e069907507 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -99,6 +99,8 @@ class AdminTest extends TestCase {
 				'updateAvailable' => true,
 				'updateVersion' => '8.1.2',
 				'downloadLink' => 'https://downloads.nextcloud.org/server',
+				'changelog' => 'https://nextcloud.com/changelog/#8.1.2',
+				'whatsNew' => ['Autoshare to mother-in-law', 'Faster backend', 'Sparkling frontend'],
 				'updaterEnabled' => true,
 				'versionIsEol' => false,
 			]);
@@ -124,6 +126,8 @@ class AdminTest extends TestCase {
 				'channels' => $channels,
 				'newVersionString' => '8.1.2',
 				'downloadLink' => 'https://downloads.nextcloud.org/server',
+				'changelogURL' => 'https://nextcloud.com/changelog/#8.1.2',
+				'whatsNew' => ['Autoshare to mother-in-law', 'Faster backend', 'Sparkling frontend'],
 				'updaterEnabled' => true,
 				'versionIsEol' => false,
 				'isDefaultUpdateServerURL' => true,
diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php
index 6f5edf0c78c..0a82f950b9a 100644
--- a/apps/updatenotification/tests/UpdateCheckerTest.php
+++ b/apps/updatenotification/tests/UpdateCheckerTest.php
@@ -51,6 +51,8 @@ class UpdateCheckerTest extends TestCase {
 				'versionstring' => 'Nextcloud 123',
 				'web'=> 'javascript:alert(1)',
 				'url'=> 'javascript:alert(2)',
+				'changelog' => 'javascript:alert(3)',
+				'whatsNew' => 'javascript:alert(4)',
 				'autoupdater'=> '0',
 				'eol'=> '1',
 			]);
@@ -73,6 +75,8 @@ class UpdateCheckerTest extends TestCase {
 				'versionstring' => 'Nextcloud 123',
 				'web'=> 'https://docs.nextcloud.com/myUrl',
 				'url'=> 'https://downloads.nextcloud.org/server',
+				'changelog' => 'https://nextcloud.com/changelog/#123.0.0',
+				'whatsNew' => ['Brews coffee', 'Makes appointments', 'Orchestrates Terminators'],
 				'autoupdater'=> '1',
 				'eol'=> '0',
 			]);
@@ -84,6 +88,8 @@ class UpdateCheckerTest extends TestCase {
 			'versionIsEol' => false,
 			'updateLink' => 'https://docs.nextcloud.com/myUrl',
 			'downloadLink' => 'https://downloads.nextcloud.org/server',
+			'changelog' => 'https://nextcloud.com/changelog/#123.0.0',
+			'whatsNew' => ['Brews coffee', 'Makes appointments', 'Orchestrates Terminators'],
 		];
 		$this->assertSame($expected, $this->updateChecker->getUpdateState());
 	}
diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php
index 30774393ecd..bc505211634 100644
--- a/lib/private/Updater/VersionCheck.php
+++ b/lib/private/Updater/VersionCheck.php
@@ -97,7 +97,7 @@ class VersionCheck {
 				$tmp['versionstring'] = (string)$data->versionstring;
 				$tmp['url'] = (string)$data->url;
 				$tmp['web'] = (string)$data->web;
-				$tmp['changelog'] = isset($data->changelog) ? (string)$data->changelog : null;
+				$tmp['changelog'] = isset($data->changelog) ? (string)$data->changelog : '';
 				// TODO: one's it is decided, use the proper field…
 				$tmp['whatsNew'] = isset($data->whatsNew) ? ((array)$data->whatsNew)['item'] : null;
 				$tmp['whatsNew'] = isset($data->whatsNew_admin) ? ((array)$data->whatsNew_admin)['item'] : (string)$data->whatsNew;
diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php
index 216510b6628..c7165b34efe 100644
--- a/tests/lib/Updater/VersionCheckTest.php
+++ b/tests/lib/Updater/VersionCheckTest.php
@@ -84,6 +84,8 @@ class VersionCheckTest extends \Test\TestCase {
 			'versionstring' => 'ownCloud 8.0.4',
 			'url' => 'https://download.example.org/community/owncloud-8.0.4.zip',
 			'web' => 'http://doc.example.org/server/8.0/admin_manual/maintenance/upgrade.html',
+			'changelog' => '',
+			'whatsNew' => '',
 			'autoupdater' => '0',
 			'eol' => '1',
 		];
@@ -181,6 +183,8 @@ class VersionCheckTest extends \Test\TestCase {
 			'versionstring' => '',
 			'url' => '',
 			'web' => '',
+			'changelog' => '',
+			'whatsNew' => '',
 			'autoupdater' => '',
 			'eol' => '0',
 		];
@@ -275,6 +279,8 @@ class VersionCheckTest extends \Test\TestCase {
 			'versionstring' => '',
 			'url' => '',
 			'web' => '',
+			'changelog' => '',
+			'whatsNew' => '',
 			'autoupdater' => '',
 			'eol' => '0',
 		];
-- 
GitLab