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

109 lines
3.5 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
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 {
$this->l->set("ja");
$this->assertArrayNotHasKey('Test.absentText', $this->l->dump());
2017-02-16 20:29:42 +00:00
}
/**
* @depends testLazyLoad
*/
2020-01-20 18:52:48 +00:00
public function testGetWantedAndLoadedLocale(): void {
$this->l->set("en", true);
$this->l->set("ja");
$this->assertEquals("ja", $this->l->get());
$this->assertEquals("en", $this->l->get(true));
}
2020-01-20 18:52:48 +00:00
public function testLoadCascadeOfFiles(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testLoadSubtag(): void {
$this->assertEquals("en_ca", $this->l->set("en_ca", true));
2017-02-16 20:29:42 +00:00
}
2020-01-20 18:52:48 +00:00
public function testFetchAMessage(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithMissingParameters(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithSingleNumericParameter(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithMultipleNumericParameters(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testFetchAMessageWithNamedParameters(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testReloadDefaultStrings(): void {
$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
*/
2020-01-20 18:52:48 +00:00
public function testReloadGeneralTagAfterSubtag(): void {
$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
}