1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-21 18:40:33 +00:00
Arsse/tests/cases/Lang/testComplex.php

110 lines
3.5 KiB
PHP
Raw Normal View History

2017-02-09 16:39:13 -05:00
<?php
/** @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;
use org\bovigo\vfs\vfsStream;
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
public $files;
public $path;
public $l;
2017-02-09 16:39:13 -05:00
2017-08-29 10:50:31 -04:00
public function setUpSeries() {
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
2017-08-29 10:50:31 -04:00
public function testLazyLoad() {
$this->l->set("ja");
$this->assertArrayNotHasKey('Test.absentText', $this->l->dump());
2017-02-16 14:29:42 -06:00
}
/**
* @depends testLazyLoad
*/
2017-08-29 10:50:31 -04: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 10:50:31 -04:00
public function testLoadCascadeOfFiles() {
$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
/**
* @depends testLoadCascadeOfFiles
2017-02-09 16:39:13 -05:00
*/
2017-08-29 10:50:31 -04:00
public function testLoadSubtag() {
$this->assertEquals("en_ca", $this->l->set("en_ca", true));
2017-02-16 14:29:42 -06:00
}
2017-08-29 10:50:31 -04:00
public function testFetchAMessage() {
$this->l->set("de");
$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
/**
* @depends testFetchAMessage
*/
2017-08-29 10:50:31 -04:00
public function testFetchAMessageWithMissingParameters() {
$this->l->set("en_ca", true);
$this->assertEquals('{0} and {1}', $this->l->msg('Test.presentText'));
}
2017-02-16 14:29:42 -06:00
/**
* @depends testFetchAMessage
2017-02-09 16:39:13 -05:00
*/
2017-08-29 10:50:31 -04:00
public function testFetchAMessageWithSingleNumericParameter() {
$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
/**
* @depends testFetchAMessage
2017-02-09 16:39:13 -05:00
*/
2017-08-29 10:50:31 -04: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 14:29:42 -06:00
}
2017-02-09 16:39:13 -05:00
2017-02-16 14:29:42 -06:00
/**
* @depends testFetchAMessage
2017-02-09 16:39:13 -05:00
*/
2017-08-29 10:50:31 -04: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 14:29:42 -06:00
}
2017-02-11 12:11:14 -05:00
2017-02-16 14:29:42 -06:00
/**
* @depends testFetchAMessage
2017-02-11 12:11:14 -05:00
*/
2017-08-29 10:50:31 -04: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 14:29:42 -06:00
}
2017-02-11 12:11:14 -05:00
2017-02-16 14:29:42 -06:00
/**
* @depends testFetchAMessage
2017-02-11 12:11:14 -05:00
*/
2017-08-29 10:50:31 -04: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 14:29:42 -06:00
}
2017-08-29 10:50:31 -04:00
}