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