From ba472f7ce05529b0fa1610d593b19cd30b099b18 Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Thu, 2 Mar 2017 09:11:47 +0100
Subject: [PATCH] Fix table name and add a test for more than 1 entries

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 .../Repair/NC12/UpdateLanguageCodes.php       |  2 +-
 .../Repair/NC12/UpdateLanguageCodesTest.php   | 43 ++++++++++---------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/private/Repair/NC12/UpdateLanguageCodes.php b/lib/private/Repair/NC12/UpdateLanguageCodes.php
index e34491beb31..ed65a5cbbe3 100644
--- a/lib/private/Repair/NC12/UpdateLanguageCodes.php
+++ b/lib/private/Repair/NC12/UpdateLanguageCodes.php
@@ -69,7 +69,7 @@ class UpdateLanguageCodes implements IRepairStep {
 				->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode)))
 				->execute();
 
-			$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in properties table.');
+			$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
 		}
 	}
 }
diff --git a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php
index 61f2fd504f6..95ccd0935a1 100644
--- a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php
+++ b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php
@@ -54,20 +54,25 @@ class UpdateLanguageCodesTest extends TestCase {
 			['userid' => 'user5', 'configvalue' => 'bg_BG'],
 			['userid' => 'user6', 'configvalue' => 'ja'],
 			['userid' => 'user7', 'configvalue' => 'th_TH'],
+			['userid' => 'user8', 'configvalue' => 'th_TH'],
 		];
 
 		// insert test data
 		$qb = $this->connection->getQueryBuilder();
-		$sql = $qb->insert('preferences')
+		$qb->insert('preferences')
 				->values([
-					'userid' => '?',
-					'appid' => '?',
-					'configkey' => '?',
-					'configvalue' => '?',
-				])
-				->getSQL();
+					'userid' => $qb->createParameter('userid'),
+					'appid' => $qb->createParameter('appid'),
+					'configkey' => $qb->createParameter('configkey'),
+					'configvalue' => $qb->createParameter('configvalue'),
+				]);
 		foreach ($users as $user) {
-			$this->connection->executeUpdate($sql, [$user['userid'], 'core', 'lang', $user['configvalue']]);
+			$qb->setParameters([
+				'userid' => $user['userid'],
+				'appid' => 'core',
+				'configkey' => 'lang',
+				'configvalue' => $user['configvalue'],
+			])->execute();
 		}
 
 		// check if test data is written to DB
@@ -83,32 +88,29 @@ class UpdateLanguageCodesTest extends TestCase {
 
 		$this->assertSame($users, $rows, 'Asserts that the entries are the ones from the test data set');
 
-		/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
-		$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
-			->disableOriginalConstructor()
-			->getMock();
-
+		/** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */
+		$outputMock = $this->createMock(IOutput::class);
 		$outputMock->expects($this->at(0))
 			->method('info')
-			->with('Changed 1 setting(s) from "bg_BG" to "bg" in properties table.');
+			->with('Changed 1 setting(s) from "bg_BG" to "bg" in preferences table.');
 		$outputMock->expects($this->at(1))
 			->method('info')
-			->with('Changed 0 setting(s) from "cs_CZ" to "cs" in properties table.');
+			->with('Changed 0 setting(s) from "cs_CZ" to "cs" in preferences table.');
 		$outputMock->expects($this->at(2))
 			->method('info')
-			->with('Changed 1 setting(s) from "fi_FI" to "fi" in properties table.');
+			->with('Changed 1 setting(s) from "fi_FI" to "fi" in preferences table.');
 		$outputMock->expects($this->at(3))
 			->method('info')
-			->with('Changed 0 setting(s) from "hu_HU" to "hu" in properties table.');
+			->with('Changed 0 setting(s) from "hu_HU" to "hu" in preferences table.');
 		$outputMock->expects($this->at(4))
 			->method('info')
-			->with('Changed 0 setting(s) from "nb_NO" to "nb" in properties table.');
+			->with('Changed 0 setting(s) from "nb_NO" to "nb" in preferences table.');
 		$outputMock->expects($this->at(5))
 			->method('info')
-			->with('Changed 0 setting(s) from "sk_SK" to "sk" in properties table.');
+			->with('Changed 0 setting(s) from "sk_SK" to "sk" in preferences table.');
 		$outputMock->expects($this->at(6))
 			->method('info')
-			->with('Changed 1 setting(s) from "th_TH" to "th" in properties table.');
+			->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.');
 
 		// run repair step
 		$repair = new UpdateLanguageCodes($this->connection);
@@ -130,6 +132,7 @@ class UpdateLanguageCodesTest extends TestCase {
 		$users[0]['configvalue'] = 'fi';
 		$users[4]['configvalue'] = 'bg';
 		$users[6]['configvalue'] = 'th';
+		$users[7]['configvalue'] = 'th';
 		$this->assertSame($users, $rows, 'Asserts that the entries are updated correctly.');
 
 		// remove test data
-- 
GitLab