1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8require_once __DIR__ . '/../../language/LanguageTranslations.php'; 9 10/** 11 * Test class for LanguageTranslations. 12 * Generated by PHPUnit on 2010-08-05 at 10:04:14. 13 */ 14class LanguageTranslationsTest extends TikiTestCase 15{ 16 /** 17 * @var LanguageTranslations 18 */ 19 protected $obj; 20 21 protected $lang; 22 23 protected $langDir; 24 25 protected $tikiroot; 26 27 protected function setUp() 28 { 29 $this->tikiroot = __DIR__ . '/../../../'; 30 $this->lang = 'test_language'; 31 $this->langDir = $this->tikiroot . 'lang/' . $this->lang; 32 33 chdir($this->tikiroot); 34 mkdir($this->langDir); 35 36 $this->obj = new LanguageTranslations($this->lang); 37 38 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Contributions by author', $this->lang, 'Contribuições por autor', 1]); 39 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Remove', $this->lang, 'Novo remover', 1]); 40 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Approved Status', $this->lang, 'Aprovado', 1]); 41 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Something', $this->lang, 'Algo', 1]); 42 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Trying to insert malicious PHP code back to the language.php file', $this->lang, 'asff"); echo \'teste\'; $dois = array(\'\',"', 1]); 43 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['Should escape "double quotes" in the source string', $this->lang, 'Deve escapar "aspas duplas" na string original', 1]); 44 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`) VALUES (?, ?, ?)', ['Not changed', $this->lang, 'Translation not changed']); 45 46 TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', ['Untranslated string 1', $this->lang]); 47 TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', ['Untranslated string 2', $this->lang]); 48 TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', ['Untranslated string 3', $this->lang]); 49 50 global ${"lang_$this->lang"}; 51 52 copy(__DIR__ . '/fixtures/language_orig.php', $this->langDir . '/language.php'); 53 54 if (! isset(${"lang_$this->lang"})) { 55 require_once('lib/init/tra.php'); 56 init_language($this->lang); 57 } 58 } 59 60 protected function tearDown() 61 { 62 if (file_exists($this->langDir . '/language.php')) { 63 unlink($this->langDir . '/language.php'); 64 } 65 66 if (file_exists($this->langDir . '/custom.php')) { 67 unlink($this->langDir . '/custom.php'); 68 } 69 70 rmdir($this->langDir); 71 72 TikiDb::get()->query('DELETE FROM `tiki_language` WHERE `lang` = ?', [$this->lang]); 73 TikiDb::get()->query('DELETE FROM `tiki_untranslated` WHERE `lang` = ?', [$this->lang]); 74 75 unset($GLOBALS['prefs']['record_untranslated']); 76 } 77 78 public function testUpdateTransShouldInsertNewTranslation() 79 { 80 $this->obj->updateTrans('New string', 'New translation'); 81 $result = TikiDb::get()->getOne('SELECT `tran` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 82 $this->assertEquals('New translation', $result); 83 TikiDb::get()->query('DELETE FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 84 } 85 86 public function testUpdateTransShouldUpdateTranslation() 87 { 88 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`) VALUES (?, ?, ?)', ['New string', $this->lang, 'Old translation']); 89 $this->obj->updateTrans('New string', 'New translation'); 90 $result = TikiDb::get()->getOne('SELECT `tran` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 91 $this->assertEquals('New translation', $result); 92 TikiDb::get()->query('DELETE FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 93 } 94 95 /* tiki_language.change seems unused, so this is superfluous as of 2017-10-06 96 public function testUpdateTransShouldNotUpdateTranslation() 97 { 98 global ${"lang_$this->lang"}; 99 ${"lang_$this->lang"}['Not changed'] = 'Translation not changed'; 100 101 $this->assertEquals(null, $this->obj->updateTrans('Not changed', 'Translation not changed')); 102 $result = TikiDb::get()->getOne('SELECT `changed` FROM `tiki_language` WHERE `lang` = ? AND binary `source` = ?', array($this->lang, 'Not changed')); 103 $this->assertEquals(null, $result); 104 }*/ 105 106 public function testUpdateTransShouldDeleteTranslation() 107 { 108 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`) VALUES (?, ?, ?)', ['New string', $this->lang, 'New translation']); 109 $this->obj->updateTrans('New string', ''); 110 $result = TikiDb::get()->getOne('SELECT `tran` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 111 $this->assertFalse($result); 112 } 113 114 public function testUpdateTransShouldNotInsertStringsThatWereNotChanged() 115 { 116 $this->obj->updateTrans('last modification time', 'data da última modificação'); 117 $this->assertFalse(TikiDb::get()->getOne('SELECT `tran` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'last modification time'])); 118 } 119 120 public function testUpdateTransShouldMarkTranslationAsChanged() 121 { 122 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`) VALUES (?, ?, ?)', ['New string', $this->lang, 'Old translation']); 123 $this->obj->updateTrans('New string', 'New translation'); 124 $result = TikiDb::get()->getOne('SELECT `changed` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 125 $this->assertEquals(1, $result); 126 TikiDb::get()->query('DELETE FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 127 } 128 129 public function testUpdateTransShouldDeleteEntryFromUntranslatedTable() 130 { 131 TikiDb::get()->query('INSERT INTO `tiki_untranslated` (`source`, `lang`) VALUES (?, ?)', ['New string', $this->lang]); 132 $this->obj->updateTrans('New string', 'New translation'); 133 $result = TikiDb::get()->getOne('SELECT `source` FROM `tiki_untranslated` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'New string']); 134 $this->assertFalse($result); 135 } 136 137 public function testUpdateTransShouldIgnoreWhenSourceAndTranslationAreEqual() 138 { 139 $this->obj->updateTrans('Source and translation are the same', 'Source and translation are the same'); 140 $result = TikiDb::get()->getOne('SELECT `source` FROM `tiki_language` WHERE `lang` = ? AND `source` = ?', [$this->lang, 'Source and translation are the same']); 141 $this->assertFalse($result); 142 } 143 144 public function testWriteLanguageFile() 145 { 146 copy(__DIR__ . '/fixtures/language_orig.php', $this->langDir . '/language.php'); 147 $this->obj->writeLanguageFile(); 148 $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_modif.php'), file_get_contents($this->langDir . '/language.php')); 149 } 150 151 public function testWriteLanguageFileCallingTwoTimes_shouldNotDuplicateStringsInTheFile() 152 { 153 copy(__DIR__ . '/fixtures/language_orig.php', $this->langDir . '/language.php'); 154 $this->obj->writeLanguageFile(); 155 $this->obj->writeLanguageFile(); 156 $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_modif.php'), file_get_contents($this->langDir . '/language.php')); 157 } 158 159 public function testWriteLanguage_shouldReturnTheNumberOfNewStringsInLanguageFile() 160 { 161 copy(__DIR__ . '/fixtures/language_orig.php', $this->langDir . '/language.php'); 162 $expectedResult = ['modif' => 2, 'new' => 4]; 163 $return = $this->obj->writeLanguageFile(); 164 $this->assertEquals($expectedResult, $return); 165 } 166 167 public function testWriteLanguage_shouldIgnoreEmptyStrings() 168 { 169 TikiDb::get()->query('INSERT INTO `tiki_language` (`source`, `lang`, `tran`, `changed`) VALUES (?, ?, ?, ?)', ['', $this->lang, '', 1]); 170 copy(__DIR__ . '/fixtures/language_orig.php', $this->langDir . '/language.php'); 171 $this->obj->writeLanguageFile(); 172 $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_modif.php'), file_get_contents($this->langDir . '/language.php')); 173 } 174 175 public function testWriteLanguage_shouldRaiseExceptionForInvalidLanguagePhp() 176 { 177 $this->setExpectedException('Language_Exception'); 178 copy(__DIR__ . '/fixtures/language_invalid.php', $this->langDir . '/language.php'); 179 $this->obj->writeLanguageFile(); 180 } 181 182 public function testDeleteTranslations() 183 { 184 $this->obj->deleteTranslations(); 185 $this->assertFalse(TikiDb::get()->getOne('SELECT * FROM `tiki_language` WHERE `lang` = ?', [$this->obj->lang])); 186 } 187 188 public function testGetFileUntranslated() 189 { 190 $cachelib = $this->getMockBuilder('Cachelib')->setMethods(['getSerialized', 'cacheItem'])->getMock(); 191 $cachelib->expects($this->once())->method('getSerialized')->with('untranslatedStrings.test_language.1234', 'untranslatedStrings')->will($this->returnValue(null)); 192 $cachelib->expects($this->once())->method('cacheItem'); 193 194 $obj = $this->getMockBuilder('LanguageTranslations') 195 ->setMethods(['_getCacheLib', '_getFileHash']) 196 ->setConstructorArgs([$this->lang]) 197 ->getMock(); 198 199 $obj->expects($this->once())->method('_getCacheLib')->will($this->returnValue($cachelib)); 200 $obj->expects($this->once())->method('_getFileHash')->will($this->returnValue(1234)); 201 202 $expectedResult = [ 203 "Kalture Video" => ['source' => "Kalture Video", 'tran' => null], 204 "Communication error" => ['source' => "Communication error", 'tran' => null], 205 "Invalid response provided by the Kaltura server. Please retry" => ['source' => "Invalid response provided by the Kaltura server. Please retry", 'tran' => null], 206 "Delete comments" => ['source' => "Delete comments", 'tran' => null], 207 "Approved Status" => ['source' => "Approved Status", 'tran' => null], 208 "Queued" => ['source' => "Queued", 'tran' => null], 209 "The file is already locked by %s" => ['source' => "The file is already locked by %s", 'tran' => null], 210 "Warning: The file is used in" => ['source' => "Warning: The file is used in", 'tran' => null], 211 "You do not have permission to edit this file" => ['source' => "You do not have permission to edit this file", 'tran' => null], 212 "Not modified since" => ['source' => "Not modified since", 'tran' => null], 213 'Test special "characters" escaping' => ['source' => 'Test special "characters" escaping', 'tran' => null], 214 ]; 215 216 $this->assertEquals($expectedResult, $obj->getFileUntranslated()); 217 } 218 219 public function testGetFileUntranslated_checkCache() 220 { 221 $expectedResult = [ 222 "Kalture Video" => ['source' => "Kalture Video", 'tran' => null], 223 "Communication error" => ['source' => "Communication error", 'tran' => null], 224 "Invalid response provided by the Kaltura server. Please retry" => ['source' => "Invalid response provided by the Kaltura server. Please retry", 'tran' => null], 225 "Delete comments" => ['source' => "Delete comments", 'tran' => null], 226 "Approved Status" => ['source' => "Approved Status", 'tran' => null], 227 "Queued" => ['source' => "Queued", 'tran' => null], 228 "The file is already locked by %s" => ['source' => "The file is already locked by %s", 'tran' => null], 229 "Warning: The file is used in" => ['source' => "Warning: The file is used in", 'tran' => null], 230 "You do not have permission to edit this file" => ['source' => "You do not have permission to edit this file", 'tran' => null], 231 "Not modified since" => ['source' => "Not modified since", 'tran' => null], 232 'Test special "characters" escaping' => ['source' => 'Test special "characters" escaping', 'tran' => null], 233 ]; 234 $this->assertEquals($expectedResult, $this->obj->getFileUntranslated()); 235 236 // change file to check if the cache is ignored when the file changes 237 copy(__DIR__ . '/fixtures/language_untranslated.php', $this->langDir . '/language.php'); 238 $expectedResult = [ 239 "Kalture Video" => ['source' => "Kalture Video", 'tran' => null], 240 "Invalid response provided by the Kaltura server. Please retry" => ['source' => "Invalid response provided by the Kaltura server. Please retry", 'tran' => null], 241 "Delete comments" => ['source' => "Delete comments", 'tran' => null], 242 "Queued" => ['source' => "Queued", 'tran' => null], 243 "The file is already locked by %s" => ['source' => "The file is already locked by %s", 'tran' => null], 244 "Warning: The file is used in" => ['source' => "Warning: The file is used in", 'tran' => null], 245 "You do not have permission to edit this file" => ['source' => "You do not have permission to edit this file", 'tran' => null], 246 ]; 247 $this->assertEquals($expectedResult, $this->obj->getFileUntranslated()); 248 } 249 250 public function getAllTranslations_dataProvider() 251 { 252 $fileTranslations = [ 253 "categorize" => ["source" => "categorize", "tran" => "categorizar"], 254 "Set prefs" => ["source" => "Set prefs", "tran" => "Definir preferências"], 255 "creation date" => ["source" => "creation date", "tran" => "data de criação"], 256 "Delete comments" => ["source" => "Delete comments", "tran" => "Deletar comentários"], 257 ]; 258 259 $dbTranslations = [ 260 "Approved Status" => ["id" => "16131", "source" => "Approved Status", "lang" => "test_language", "tran" => "Aprovado", "changed" => "1"], 261 "creation date" => ["id" => "16132", "source" => "creation date", "lang" => "test_language", "tran" => "data de criação nova", "changed" => "1"], 262 "Post" => ["id" => "16133", "source" => "Post", "lang" => "test_language", "tran" => "Enviar", "changed" => "1"], 263 ]; 264 265 return [ 266 [$fileTranslations, $dbTranslations] 267 ]; 268 } 269 270 /** 271 * @dataProvider getAllTranslations_dataProvider 272 */ 273 public function testGetAllTranslations($fileTranslations, $dbTranslations) 274 { 275 $expectedResult = [ 276 'translations' => [ 277 "Approved Status" => ["id" => "16131", "source" => "Approved Status", "lang" => "test_language", "tran" => "Aprovado", "changed" => "1"], 278 "categorize" => ["source" => "categorize", "tran" => "categorizar"], 279 "creation date" => ["id" => "16132", "source" => "creation date", "lang" => "test_language", "tran" => "data de criação nova", "changed" => "1"], 280 "Delete comments" => ["source" => "Delete comments", "tran" => "Deletar comentários"], 281 "Post" => ["id" => "16133", "source" => "Post", "lang" => "test_language", "tran" => "Enviar", "changed" => "1"], 282 "Set prefs" => ["source" => "Set prefs", "tran" => "Definir preferências"], 283 ], 284 'total' => 6, 285 ]; 286 287 $obj = $this->getMockBuilder('LanguageTranslations') 288 ->setMethods(['getFileTranslations', '_getDbTranslations']) 289 ->getMock(); 290 291 $obj->expects($this->once())->method('getFileTranslations')->will($this->returnValue($fileTranslations)); 292 $obj->expects($this->once())->method('_getDbTranslations')->will($this->returnValue($dbTranslations)); 293 294 $this->assertEquals($expectedResult, $obj->getAllTranslations()); 295 } 296 297 /** 298 * @dataProvider getAllTranslations_dataProvider 299 */ 300 public function testGetAllTranslations_filterByMaxRecordsAndOffset($fileTranslations, $dbTranslations) 301 { 302 $expectedResult = [ 303 'translations' => [ 304 "Delete comments" => ["source" => "Delete comments", "tran" => "Deletar comentários"], 305 "Post" => ["id" => "16133", "source" => "Post", "lang" => "test_language", "tran" => "Enviar", "changed" => "1"], 306 ], 307 'total' => 6, 308 ]; 309 310 $obj = $this->getMockBuilder('LanguageTranslations') 311 ->setMethods(['getFileTranslations', '_getDbTranslations']) 312 ->getMock(); 313 314 $obj->expects($this->once())->method('getFileTranslations')->will($this->returnValue($fileTranslations)); 315 $obj->expects($this->once())->method('_getDbTranslations')->will($this->returnValue($dbTranslations)); 316 317 $this->assertEquals($expectedResult, $obj->getAllTranslations(2, 3)); 318 } 319 320 /** 321 * @dataProvider getAllTranslations_dataProvider 322 */ 323 public function testGetAllTranslations_filterByMaxRecordsOffsetAndSearch($fileTranslations, $dbTranslations) 324 { 325 $expectedResult = [ 326 'translations' => [ 327 "Set prefs" => ["source" => "Set prefs", "tran" => "Definir preferências"], 328 ], 329 'total' => 2, 330 ]; 331 332 $obj = $this->getMockBuilder('LanguageTranslations') 333 ->setMethods(['getFileTranslations', '_getDbTranslations']) 334 ->getMock(); 335 336 $obj->expects($this->once())->method('getFileTranslations')->will($this->returnValue($fileTranslations)); 337 $obj->expects($this->once())->method('_getDbTranslations')->will($this->returnValue($dbTranslations)); 338 339 $this->assertEquals($expectedResult, $obj->getAllTranslations(2, 1, 're')); 340 } 341 342 /** 343 * @dataProvider getAllTranslations_dataProvider 344 */ 345 public function testGetAllTranslations_searchByTranslation($fileTranslations, $dbTranslations) 346 { 347 $expectedResult = [ 348 'translations' => [ 349 "Set prefs" => ["source" => "Set prefs", "tran" => "Definir preferências"], 350 ], 351 'total' => 1, 352 ]; 353 354 $obj = $this->getMockBuilder('LanguageTranslations') 355 ->setMethods(['getFileTranslations', '_getDbTranslations']) 356 ->getMock(); 357 358 $obj->expects($this->once())->method('getFileTranslations')->will($this->returnValue($fileTranslations)); 359 $obj->expects($this->once())->method('_getDbTranslations')->will($this->returnValue($dbTranslations)); 360 361 $this->assertEquals($expectedResult, $obj->getAllTranslations(-1, 0, 'rê')); 362 } 363 364 public function testGetFileTranslations() 365 { 366 copy(__DIR__ . '/fixtures/custom.php', $this->langDir . '/custom.php'); 367 $this->assertEquals(27, count($this->obj->getFileTranslations())); 368 } 369 370 public function testGetFileTranslations_shouldEscapeSpecialCharacters() 371 { 372 $trans = $this->obj->getFileTranslations(); 373 $this->assertArrayHasKey('Second test special "characters" escaping', $trans); 374 } 375 376 public function testGetDbTranslations() 377 { 378 $obj = $this->getMockBuilder('LanguageTranslations') 379 ->setMethods(['_diff']) 380 ->setConstructorArgs(['test_language']) 381 ->getMock(); 382 383 $obj->expects($this->any())->method('_diff'); 384 385 $dbTranslations = $obj->getDbTranslations('source_asc', -1, 0); 386 $this->assertGreaterThan(0, $dbTranslations['total']); 387 $this->assertEquals('Aprovado', $dbTranslations['translations']['Approved Status']['tran']); 388 } 389 390 public function testGetDbTranslationsMaxrecordsAndOffset() 391 { 392 $obj = $this->getMockBuilder('LanguageTranslations') 393 ->setMethods(['_diff']) 394 ->setConstructorArgs(['test_language']) 395 ->getMock(); 396 397 $obj->expects($this->any())->method('_diff'); 398 399 $dbTranslations = $obj->getDbTranslations('source_asc', 2, 1); 400 $this->assertEquals(2, $dbTranslations['total']); 401 $this->assertEquals('Contribuições por autor', $dbTranslations['translations']['Contributions by author']['tran']); 402 } 403 404 public function testGetDbTranslationsSearch() 405 { 406 $obj = $this->getMockBuilder('LanguageTranslations') 407 ->setMethods(['_diff']) 408 ->setConstructorArgs(['test_language']) 409 ->getMock(); 410 411 $obj->expects($this->any())->method('_diff'); 412 413 $dbTranslations = $obj->getDbTranslations('source_asc', -1, 0, 'Approved'); 414 $this->assertEquals(1, $dbTranslations['total']); 415 $this->assertEquals('Aprovado', $dbTranslations['translations']['Approved Status']['tran']); 416 } 417 418 public function testGetDbUntranslated() 419 { 420 global $prefs; 421 $prefs['record_untranslated'] = 'y'; 422 423 $expectedResult = [ 424 'translations' => [ 425 'Untranslated string 1' => ['source' => 'Untranslated string 1', 'tran' => null], 426 'Untranslated string 2' => ['source' => 'Untranslated string 2', 'tran' => null], 427 'Untranslated string 3' => ['source' => 'Untranslated string 3', 'tran' => null], 428 ], 429 'total' => 3 430 ]; 431 432 $this->assertEquals($expectedResult, $this->obj->getDbUntranslated()); 433 } 434 435 public function testGetDbUntranslated_filterByMaxRecordsAndOffset() 436 { 437 global $prefs; 438 $prefs['record_untranslated'] = 'y'; 439 440 $expectedResult = [ 441 'translations' => [ 442 'Untranslated string 3' => ['source' => 'Untranslated string 3', 'tran' => null], 443 ], 444 'total' => 3, 445 ]; 446 447 $this->assertEquals($expectedResult, $this->obj->getDbUntranslated(1, 2)); 448 } 449 450 public function testGetDbUntranslated_filterBySearch() 451 { 452 global $prefs; 453 $prefs['record_untranslated'] = 'y'; 454 455 $expectedResult = [ 456 'translations' => [ 457 'Untranslated string 3' => ['source' => 'Untranslated string 3', 'tran' => null], 458 ], 459 'total' => 1, 460 ]; 461 462 $this->assertEquals($expectedResult, $this->obj->getDbUntranslated(-1, 0, 'string 3')); 463 } 464 465 public function getAllUntranslated_dataProvider() 466 { 467 $dbUntranslated = [ 468 'Untranslated string 1' => ['source' => 'Untranslated string 1', 'tran' => null], 469 'Untranslated string 2' => ['source' => 'Untranslated string 2', 'tran' => null], 470 "Communication error" => ['source' => "Communication error", 'tran' => null], 471 ]; 472 473 $fileUntranslated = [ 474 "Kalture Video" => ['source' => "Kalture Video", 'tran' => null], 475 "Communication error" => ['source' => "Communication error", 'tran' => null], 476 "Invalid response provided by the Kaltura server. Please retry" => ['source' => "Invalid response provided by the Kaltura server. Please retry", 'tran' => null], 477 "Delete comments" => ['source' => "Delete comments", 'tran' => null], 478 "Approved Status" => ['source' => "Approved Status", 'tran' => null], 479 ]; 480 481 $dbTranslations = [ 482 "Approved Status" => ['source' => "Approved Status", 'tran' => 'Aprovado'], 483 ]; 484 485 return [ 486 [$dbUntranslated, $fileUntranslated, $dbTranslations], 487 ]; 488 } 489 490 /** 491 * @dataProvider getAllUntranslated_dataProvider 492 */ 493 public function testGetAllUntranslated($dbUntranslated, $fileUntranslated, $dbTranslations) 494 { 495 $obj = $this->getMockBuilder('LanguageTranslations') 496 ->setMethods(['getFileUntranslated', '_getDbUntranslated', '_getDbTranslations']) 497 ->getMock(); 498 499 $obj->expects($this->once())->method('getFileUntranslated')->will($this->returnValue($fileUntranslated)); 500 $obj->expects($this->once())->method('_getDbUntranslated')->will($this->returnValue($dbUntranslated)); 501 $obj->expects($this->once())->method('_getDbTranslations')->will($this->returnValue($dbTranslations)); 502 503 $expectedResult = [ 504 'translations' => [ 505 "Communication error" => ['source' => "Communication error", 'tran' => null], 506 "Delete comments" => ['source' => "Delete comments", 'tran' => null], 507 "Invalid response provided by the Kaltura server. Please retry" => ['source' => "Invalid response provided by the Kaltura server. Please retry", 'tran' => null], 508 "Kalture Video" => ['source' => "Kalture Video", 'tran' => null], 509 'Untranslated string 1' => ['source' => 'Untranslated string 1', 'tran' => null], 510 'Untranslated string 2' => ['source' => 'Untranslated string 2', 'tran' => null], 511 ], 512 'total' => 6 513 ]; 514 515 $this->assertEquals($expectedResult, $obj->getAllUntranslated()); 516 } 517} 518