mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Last set of language tests
This commit is contained in:
parent
2c134c76dc
commit
4bc602957c
6 changed files with 80 additions and 6 deletions
|
@ -89,7 +89,7 @@ class TestConf extends \PHPUnit\Framework\TestCase {
|
||||||
/**
|
/**
|
||||||
* @depends testImportFile
|
* @depends testImportFile
|
||||||
*/
|
*/
|
||||||
function testImportFileNotPHP() {
|
function testImportFileNotPhp() {
|
||||||
$this->assertException("fileCorrupt", "Conf");
|
$this->assertException("fileCorrupt", "Conf");
|
||||||
// this should not print the output of the non-PHP file
|
// this should not print the output of the non-PHP file
|
||||||
$conf = new Conf(self::$path."confNotPHP");
|
$conf = new Conf(self::$path."confNotPHP");
|
||||||
|
|
50
tests/TestLangErrors.php
Normal file
50
tests/TestLangErrors.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
namespace JKingWeb\NewsSync;
|
||||||
|
use \org\bovigo\vfs\vfsStream;
|
||||||
|
|
||||||
|
|
||||||
|
class TestLangErrors extends \PHPUnit\Framework\TestCase {
|
||||||
|
use TestingHelpers, LanguageTestingHelpers;
|
||||||
|
|
||||||
|
static $vfs;
|
||||||
|
static $path;
|
||||||
|
static $files;
|
||||||
|
static $defaultPath;
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
Lang::set("", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadFileEmpty() {
|
||||||
|
$this->assertException("fileCorrupt", "Lang");
|
||||||
|
Lang::set("fr_ca", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadFileNotAnArray() {
|
||||||
|
$this->assertException("fileCorrupt", "Lang");
|
||||||
|
Lang::set("it", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadFileNotPhp() {
|
||||||
|
$this->assertException("fileCorrupt", "Lang");
|
||||||
|
Lang::set("ko", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadFileCorrupt() {
|
||||||
|
$this->assertException("fileCorrupt", "Lang");
|
||||||
|
Lang::set("zh", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadFileUnreadable() {
|
||||||
|
$this->assertException("fileUnreadable", "Lang");
|
||||||
|
Lang::set("ru", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLoadDefaultMissing() {
|
||||||
|
// this should be the last test of the series
|
||||||
|
unlink(self::$path.Lang::DEFAULT.".php");
|
||||||
|
$this->assertException("defaultFileMissing", "Lang");
|
||||||
|
Lang::set("fr", true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ trait LanguageTestingHelpers {
|
||||||
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
|
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
|
||||||
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
|
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
|
||||||
'de.php' => '<?php return ["Test.presentText" => "und der Stein der Weisen"];',
|
'de.php' => '<?php return ["Test.presentText" => "und der Stein der Weisen"];',
|
||||||
|
'vi.php' => '<?php return [];',
|
||||||
// corrupt files
|
// corrupt files
|
||||||
'it.php' => '<?php return 0;',
|
'it.php' => '<?php return 0;',
|
||||||
'zh.php' => '<?php return 0',
|
'zh.php' => '<?php return 0',
|
||||||
|
@ -40,12 +41,12 @@ trait LanguageTestingHelpers {
|
||||||
'ru.php' => '',
|
'ru.php' => '',
|
||||||
];
|
];
|
||||||
self::$vfs = vfsStream::setup("langtest", 0777, self::$files);
|
self::$vfs = vfsStream::setup("langtest", 0777, self::$files);
|
||||||
self::$path = self::$vfs->url();
|
self::$path = self::$vfs->url()."/";
|
||||||
// set up a file without read access
|
// set up a file without read access
|
||||||
chmod(self::$path."/ru.php", 0000);
|
chmod(self::$path."ru.php", 0000);
|
||||||
// make the Lang class use the vfs files
|
// make the Lang class use the vfs files
|
||||||
self::$defaultPath = Lang::$path;
|
self::$defaultPath = Lang::$path;
|
||||||
Lang::$path = self::$path."/";
|
Lang::$path = self::$path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function tearDownAfterClass() {
|
static function tearDownAfterClass() {
|
||||||
|
|
|
@ -7,12 +7,14 @@
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||||
beStrictAboutOutputDuringTests="true"
|
beStrictAboutOutputDuringTests="true"
|
||||||
beStrictAboutTestSize="true">
|
beStrictAboutTestSize="true"
|
||||||
|
stopOnError="true">
|
||||||
|
|
||||||
<testsuite name="Localization and exceptions">
|
<testsuite name="Localization and exceptions">
|
||||||
<file>TestLang.php</file>
|
<file>TestLang.php</file>
|
||||||
<file>TestLangComplex.php</file>
|
<file>TestLangComplex.php</file>
|
||||||
<file>TestException.php</file>
|
<file>TestException.php</file>
|
||||||
|
<file>TestLangErrors.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|
||||||
<testsuite name="Configuration loading and saving">
|
<testsuite name="Configuration loading and saving">
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TestLangComplex extends \PHPUnit\Framework\TestCase {
|
||||||
/**
|
/**
|
||||||
* @depends testMessage
|
* @depends testMessage
|
||||||
*/
|
*/
|
||||||
function testMessageNumMSingle() {
|
function testMessageNumSingle() {
|
||||||
Lang::set("en_ca", true);
|
Lang::set("en_ca", true);
|
||||||
$this->assertEquals('Default language file "en" missing', Lang::msg('Exception.JKingWeb/NewsSync/Lang/Exception.defaultFileMissing', Lang::DEFAULT));
|
$this->assertEquals('Default language file "en" missing', Lang::msg('Exception.JKingWeb/NewsSync/Lang/Exception.defaultFileMissing', Lang::DEFAULT));
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,24 @@ class TestLangComplex extends \PHPUnit\Framework\TestCase {
|
||||||
function testMessageNamed() {
|
function testMessageNamed() {
|
||||||
$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']));
|
$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']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testMessage
|
||||||
|
*/
|
||||||
|
function testReloadDefaults() {
|
||||||
|
Lang::set("de", true);
|
||||||
|
Lang::set("en", true);
|
||||||
|
$this->assertEquals('and the Philosopher\'s Stone', Lang::msg('Test.presentText'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testMessage
|
||||||
|
*/
|
||||||
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
1
vendor/JKingWeb/NewsSync/Lang.php
vendored
1
vendor/JKingWeb/NewsSync/Lang.php
vendored
|
@ -94,6 +94,7 @@ class Lang {
|
||||||
|
|
||||||
static protected function listFiles(): array {
|
static protected function listFiles(): array {
|
||||||
$out = glob(self::$path."*.php");
|
$out = glob(self::$path."*.php");
|
||||||
|
// built-in glob doesn't work with vfsStream (and this other glob doesn't seem to work with Windows paths), so we try both
|
||||||
if(empty($out)) $out = Glob::glob(self::$path."*.php");
|
if(empty($out)) $out = Glob::glob(self::$path."*.php");
|
||||||
$out = array_map(function($file) {
|
$out = array_map(function($file) {
|
||||||
$file = str_replace(DIRECTORY_SEPARATOR, "/", $file);
|
$file = str_replace(DIRECTORY_SEPARATOR, "/", $file);
|
||||||
|
|
Loading…
Reference in a new issue