1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-24 17:42:40 +00:00
Arsse/tests/cases/Lang/testComplex.php

109 lines
3.4 KiB
PHP
Raw Normal View History

2017-02-09 21:39:13 +00:00
<?php
/** @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
public $files;
public $path;
public $l;
2017-02-09 21:39:13 +00:00
2017-08-29 14:50:31 +00:00
public function setUpSeries() {
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
2017-08-29 14:50:31 +00:00
public function testLazyLoad() {
$this->l->set("ja");
$this->assertArrayNotHasKey('Test.absentText', $this->l->dump());
2017-02-16 20:29:42 +00:00
}
/**
* @depends testLazyLoad
*/
2017-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public function testLoadSubtag() {
$this->assertEquals("en_ca", $this->l->set("en_ca", true));
2017-02-16 20:29:42 +00:00
}
2017-08-29 14:50:31 +00:00
public function testFetchAMessage() {
$this->l->set("de");
$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
*/
2017-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public function testFetchAMessageWithSingleNumericParameter() {
$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
/**
* @depends testFetchAMessage
2017-02-09 21:39:13 +00:00
*/
2017-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
public 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-08-29 14:50:31 +00:00
}