2017-02-09 21:39:13 +00:00
< ? php
2017-11-17 01:23:18 +00:00
/** @ license MIT
* Copyright 2017 J . King , Dustin Wilson et al .
* See LICENSE and AUTHORS files for details */
2017-02-09 21:39:13 +00:00
declare ( strict_types = 1 );
2017-12-22 03:47:19 +00:00
namespace JKingWeb\Arsse\TestCase\Lang ;
2017-08-29 14:50:31 +00:00
2017-12-22 03:47:19 +00:00
use JKingWeb\Arsse\Lang as TestClass ;
2017-02-09 21:39:13 +00:00
2017-07-20 22:36:03 +00:00
/** @covers \JKingWeb\Arsse\Lang */
2017-12-22 03:47:19 +00:00
class TestComplex extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Lang\Setup ;
2017-02-09 21:39:13 +00:00
2017-03-28 22:50:00 +00:00
public $files ;
public $path ;
public $l ;
2017-02-09 21:39:13 +00:00
2020-01-20 18:52:48 +00:00
public function setUpSeries () : void {
2017-12-22 03:47:19 +00:00
$this -> l -> set ( TestClass :: DEFAULT , true );
2017-02-16 20:29:42 +00:00
}
2017-02-09 21:39:13 +00:00
2020-01-20 18:52:48 +00:00
public function testLazyLoad () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " ja " );
$this -> assertArrayNotHasKey ( 'Test.absentText' , $this -> l -> dump ());
2017-02-16 20:29:42 +00:00
}
2017-04-07 01:41:21 +00:00
2017-02-16 22:50:34 +00:00
/**
* @ depends testLazyLoad
*/
2020-01-20 18:52:48 +00:00
public function testGetWantedAndLoadedLocale () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " en " , true );
$this -> l -> set ( " ja " );
$this -> assertEquals ( " ja " , $this -> l -> get ());
$this -> assertEquals ( " en " , $this -> l -> get ( true ));
2017-02-16 22:50:34 +00:00
}
2017-04-07 01:41:21 +00:00
2020-01-20 18:52:48 +00:00
public function testLoadCascadeOfFiles () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " ja " , true );
$this -> assertEquals ( " de " , $this -> l -> set ( " de " , true ));
$str = $this -> l -> dump ();
2017-02-16 20:29:42 +00:00
$this -> assertArrayNotHasKey ( 'Test.absentText' , $str );
$this -> assertEquals ( 'und der Stein der Weisen' , $str [ 'Test.presentText' ]);
}
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testLoadCascadeOfFiles
2017-02-09 21:39:13 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testLoadSubtag () : void {
2017-03-28 22:50:00 +00:00
$this -> assertEquals ( " en_ca " , $this -> l -> set ( " en_ca " , true ));
2017-02-16 20:29:42 +00:00
}
2017-04-07 01:41:21 +00:00
2020-01-20 18:52:48 +00:00
public function testFetchAMessage () : void {
2017-09-05 23:35:14 +00:00
$this -> l -> set ( " de " );
2017-03-28 22:50:00 +00:00
$this -> assertEquals ( 'und der Stein der Weisen' , $this -> l -> msg ( 'Test.presentText' ));
2017-02-16 20:29:42 +00:00
}
2017-02-09 21:39:13 +00:00
2017-02-16 22:50:34 +00:00
/**
* @ depends testFetchAMessage
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithMissingParameters () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " en_ca " , true );
$this -> assertEquals ( '{0} and {1}' , $this -> l -> msg ( 'Test.presentText' ));
2017-02-16 22:50:34 +00:00
}
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithSingleNumericParameter () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " en_ca " , true );
2017-12-22 03:47:19 +00:00
$this -> assertEquals ( 'Default language file "en" missing' , $this -> l -> msg ( 'Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing' , TestClass :: DEFAULT ));
2017-02-16 20:29:42 +00:00
}
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithMultipleNumericParameters () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " en_ca " , true );
$this -> assertEquals ( 'Happy Rotter and the Philosopher\'s Stone' , $this -> l -> msg ( 'Test.presentText' , [ 'Happy Rotter' , 'the Philosopher\'s Stone' ]));
2017-02-16 20:29:42 +00:00
}
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithNamedParameters () : void {
2017-03-28 22:50:00 +00:00
$this -> assertEquals ( 'Message string "Test.absentText" missing from all loaded language files (en)' , $this -> l -> msg ( 'Exception.JKingWeb/Arsse/Lang/Exception.stringMissing' , [ 'msgID' => 'Test.absentText' , 'fileList' => 'en' ]));
2017-02-16 20:29:42 +00:00
}
2017-02-11 17:11:14 +00:00
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testFetchAMessage
2017-02-11 17:11:14 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testReloadDefaultStrings () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " de " , true );
$this -> l -> set ( " en " , true );
$this -> assertEquals ( 'and the Philosopher\'s Stone' , $this -> l -> msg ( 'Test.presentText' ));
2017-02-16 20:29:42 +00:00
}
2017-02-11 17:11:14 +00:00
2017-02-16 20:29:42 +00:00
/**
2017-02-11 18:50:34 +00:00
* @ depends testFetchAMessage
2017-02-11 17:11:14 +00:00
*/
2020-01-20 18:52:48 +00:00
public function testReloadGeneralTagAfterSubtag () : void {
2017-03-28 22:50:00 +00:00
$this -> l -> set ( " en " , true );
$this -> l -> set ( " en_us " , true );
$this -> assertEquals ( 'and the Sorcerer\'s Stone' , $this -> l -> msg ( 'Test.presentText' ));
$this -> l -> set ( " en " , true );
$this -> assertEquals ( 'and the Philosopher\'s Stone' , $this -> l -> msg ( 'Test.presentText' ));
2017-02-16 20:29:42 +00:00
}
2017-08-29 14:50:31 +00:00
}