diff --git a/tests/TestConf.php b/tests/TestConf.php index 4e839a5..da2dbfa 100644 --- a/tests/TestConf.php +++ b/tests/TestConf.php @@ -89,7 +89,7 @@ class TestConf extends \PHPUnit\Framework\TestCase { /** * @depends testImportFile */ - function testImportFileNotPHP() { + function testImportFileNotPhp() { $this->assertException("fileCorrupt", "Conf"); // this should not print the output of the non-PHP file $conf = new Conf(self::$path."confNotPHP"); diff --git a/tests/TestLangErrors.php b/tests/TestLangErrors.php new file mode 100644 index 0000000..99971f3 --- /dev/null +++ b/tests/TestLangErrors.php @@ -0,0 +1,50 @@ +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); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c4c2368..3df862e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,6 +31,7 @@ trait LanguageTestingHelpers { 'fr.php' => ' "à l\'école des sorciers"];', 'ja.php' => ' "賢者の石"];', 'de.php' => ' "und der Stein der Weisen"];', + 'vi.php' => ' ' ' '', ]; 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 - chmod(self::$path."/ru.php", 0000); + chmod(self::$path."ru.php", 0000); // make the Lang class use the vfs files self::$defaultPath = Lang::$path; - Lang::$path = self::$path."/"; + Lang::$path = self::$path; } static function tearDownAfterClass() { diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 8b1dbd8..3278285 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,12 +7,14 @@ convertWarningsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" - beStrictAboutTestSize="true"> + beStrictAboutTestSize="true" + stopOnError="true"> TestLang.php TestLangComplex.php TestException.php + TestLangErrors.php diff --git a/tests/testLangComplex.php b/tests/testLangComplex.php index d02ecdb..8340d4d 100644 --- a/tests/testLangComplex.php +++ b/tests/testLangComplex.php @@ -47,7 +47,7 @@ class TestLangComplex extends \PHPUnit\Framework\TestCase { /** * @depends testMessage */ - function testMessageNumMSingle() { + function testMessageNumSingle() { Lang::set("en_ca", true); $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() { $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')); + } } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Lang.php b/vendor/JKingWeb/NewsSync/Lang.php index 9ae9e68..d557866 100644 --- a/vendor/JKingWeb/NewsSync/Lang.php +++ b/vendor/JKingWeb/NewsSync/Lang.php @@ -94,6 +94,7 @@ class Lang { static protected function listFiles(): array { $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"); $out = array_map(function($file) { $file = str_replace(DIRECTORY_SEPARATOR, "/", $file);