1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-08 17:02:41 +00:00
Arsse/tests/TestLangErrors.php
J. King 8db31cf3e4 Tweaked Lang; added comments and tests
Tweaks:
- get() method can now report loaded and well as wanted locale
- msg() passed without vars still gets formatted to catch malformed strings
- set('en', false) followed by set('en', true) will now immediately load
- Lang::$synched was not getting set to true properly

Tests:
- Added test for get()
- Added test for malformed strings (exception code was missing)
- Added test for missing strings
- Added test for strings taking variables not being passed any variables
2017-02-16 17:50:34 -05:00

66 lines
No EOL
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync;
use \org\bovigo\vfs\vfsStream;
class TestLangErrors extends \PHPUnit\Framework\TestCase {
use Test\Tools, Test\Lang\Setup;
static $vfs;
static $path;
static $files;
static $defaultPath;
function setUp() {
Lang::set("", true);
}
function testLoadEmptyFile() {
$this->assertException("fileCorrupt", "Lang");
Lang::set("fr_ca", true);
}
function testLoadFileWhichDoesNotReturnAnArray() {
$this->assertException("fileCorrupt", "Lang");
Lang::set("it", true);
}
function testLoadFileWhichIsNotPhp() {
$this->assertException("fileCorrupt", "Lang");
Lang::set("ko", true);
}
function testLoadFileWhichIsCorrupt() {
$this->assertException("fileCorrupt", "Lang");
Lang::set("zh", true);
}
function testLoadFileWithooutReadPermission() {
$this->assertException("fileUnreadable", "Lang");
Lang::set("ru", true);
}
function testLoadSubtagOfMissingLanguage() {
$this->assertException("fileMissing", "Lang");
Lang::set("pt_br", true);
}
function testFetchInvalidMessage() {
$this->assertException("stringInvalid", "Lang");
Lang::set("vi", true);
$txt = Lang::msg('Test.presentText');
}
function testFetchMissingMessage() {
$this->assertException("stringMissing", "Lang");
$txt = Lang::msg('Test.absentText');
}
function testLoadMissingDefaultLanguage() {
// this should be the last test of the series
unlink(self::$path.Lang::DEFAULT.".php");
$this->assertException("defaultFileMissing", "Lang");
Lang::set("fr", true);
}
}