1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/tests/Lang/testLangComplex.php

103 lines
3.2 KiB
PHP
Raw Normal View History

2017-02-09 21:39:13 +00:00
<?php
declare(strict_types=1);
2017-03-28 04:12:12 +00:00
namespace JKingWeb\Arsse;
use org\bovigo\vfs\vfsStream;
2017-02-09 21:39:13 +00:00
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
public $files;
public $path;
public $l;
2017-02-09 21:39:13 +00:00
function setUpSeries() {
$this->l->set(Lang::DEFAULT, true);
2017-02-16 20:29:42 +00:00
}
2017-02-09 21:39:13 +00:00
2017-02-16 20:29:42 +00:00
function testLazyLoad() {
$this->l->set("ja");
$this->assertArrayNotHasKey('Test.absentText', $this->l->dump());
2017-02-16 20:29:42 +00:00
}
/**
* @depends testLazyLoad
*/
function testGetWantedAndLoadedLocale() {
$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 20:29:42 +00:00
function testLoadCascadeOfFiles() {
$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
/**
* @depends testLoadCascadeOfFiles
2017-02-09 21:39:13 +00:00
*/
2017-02-16 20:29:42 +00:00
function testLoadSubtag() {
$this->assertEquals("en_ca", $this->l->set("en_ca", true));
2017-02-16 20:29:42 +00:00
}
function testFetchAMessage() {
$this->l->set("de", true);
$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
/**
* @depends testFetchAMessage
*/
function testFetchAMessageWithMissingParameters() {
$this->l->set("en_ca", true);
$this->assertEquals('{0} and {1}', $this->l->msg('Test.presentText'));
}
2017-02-16 20:29:42 +00:00
/**
* @depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2017-02-16 20:29:42 +00:00
function testFetchAMessageWithSingleNumericParameter() {
$this->l->set("en_ca", true);
$this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', Lang::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
/**
* @depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2017-02-16 20:29:42 +00:00
function testFetchAMessageWithMultipleNumericParameters() {
$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
/**
* @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)', $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
/**
* @depends testFetchAMessage
2017-02-11 17:11:14 +00:00
*/
2017-02-16 20:29:42 +00:00
function testReloadDefaultStrings() {
$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
/**
* @depends testFetchAMessage
2017-02-11 17:11:14 +00:00
*/
2017-02-16 20:29:42 +00:00
function testReloadGeneralTagAfterSubtag() {
$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-02-09 21:39:13 +00:00
}