2017-02-09 21:39:13 +00:00
< ? php
declare ( strict_types = 1 );
namespace JKingWeb\NewsSync ;
use \org\bovigo\vfs\vfsStream ;
class TestLangComplex extends \PHPUnit\Framework\TestCase {
2017-02-16 20:29:42 +00:00
use Test\Tools , Test\Lang\Setup ;
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
static $vfs ;
static $path ;
static $files ;
static $defaultPath ;
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
function setUp () {
Lang :: set ( Lang :: DEFAULT , true );
}
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
function testLazyLoad () {
Lang :: set ( " ja " );
$this -> assertArrayNotHasKey ( 'Test.absentText' , Lang :: dump ());
}
2017-02-16 22:50:34 +00:00
/**
* @ depends testLazyLoad
*/
function testGetWantedAndLoadedLocale () {
2017-03-01 17:13:38 +00:00
Lang :: set ( " en " , true );
2017-02-16 22:50:34 +00:00
Lang :: set ( " ja " );
$this -> assertEquals ( " ja " , Lang :: get ());
$this -> assertEquals ( " en " , Lang :: get ( true ));
}
2017-02-16 20:29:42 +00:00
function testLoadCascadeOfFiles () {
Lang :: set ( " ja " , true );
$this -> assertEquals ( " de " , Lang :: set ( " de " , true ));
$str = Lang :: dump ();
$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
*/
2017-02-16 20:29:42 +00:00
function testLoadSubtag () {
$this -> assertEquals ( " en_ca " , Lang :: set ( " en_ca " , true ));
}
function testFetchAMessage () {
Lang :: set ( " de " , true );
$this -> assertEquals ( 'und der Stein der Weisen' , Lang :: msg ( 'Test.presentText' ));
}
2017-02-09 21:39:13 +00:00
2017-02-16 22:50:34 +00:00
/**
* @ depends testFetchAMessage
*/
function testFetchAMessageWithMissingParameters () {
Lang :: set ( " en_ca " , true );
$this -> assertEquals ( '{0} and {1}' , Lang :: msg ( 'Test.presentText' ));
}
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
*/
2017-02-16 20:29:42 +00:00
function testFetchAMessageWithSingleNumericParameter () {
Lang :: set ( " en_ca " , true );
$this -> assertEquals ( 'Default language file "en" missing' , Lang :: msg ( 'Exception.JKingWeb/NewsSync/Lang/Exception.defaultFileMissing' , Lang :: DEFAULT ));
}
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
*/
2017-02-16 20:29:42 +00:00
function testFetchAMessageWithMultipleNumericParameters () {
Lang :: set ( " en_ca " , true );
$this -> assertEquals ( 'Happy Rotter and the Philosopher\'s Stone' , Lang :: msg ( 'Test.presentText' , [ 'Happy Rotter' , 'the Philosopher\'s Stone' ]));
}
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
*/
2017-02-16 20:29:42 +00:00
function testFetchAMessageWithNamedParameters () {
$this -> assertEquals ( 'Message string "Test.absentText" missing from all loaded language files (en)' , Lang :: msg ( 'Exception.JKingWeb/NewsSync/Lang/Exception.stringMissing' , [ 'msgID' => 'Test.absentText' , 'fileList' => 'en' ]));
}
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
*/
2017-02-16 20:29:42 +00:00
function testReloadDefaultStrings () {
Lang :: set ( " de " , true );
Lang :: set ( " en " , true );
$this -> assertEquals ( 'and the Philosopher\'s Stone' , Lang :: msg ( 'Test.presentText' ));
}
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
*/
2017-02-16 20:29:42 +00:00
function testReloadGeneralTagAfterSubtag () {
Lang :: set ( " en " , true );
Lang :: set ( " en_us " , true );
$this -> assertEquals ( 'and the Sorcerer\'s Stone' , Lang :: msg ( 'Test.presentText' ));
Lang :: set ( " en " , true );
$this -> assertEquals ( 'and the Philosopher\'s Stone' , Lang :: msg ( 'Test.presentText' ));
}
2017-02-09 21:39:13 +00:00
}