2017-02-06 00:00:57 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse;
|
2017-03-28 22:50:00 +00:00
|
|
|
use org\bovigo\vfs\vfsStream;
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\Conf */
|
2017-07-08 01:06:38 +00:00
|
|
|
class TestConf extends Test\AbstractTest {
|
2017-02-16 20:29:42 +00:00
|
|
|
static $vfs;
|
|
|
|
static $path;
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-03-28 22:50:00 +00:00
|
|
|
function setUp() {
|
|
|
|
$this->clearData();
|
2017-02-16 20:29:42 +00:00
|
|
|
self::$vfs = vfsStream::setup("root", null, [
|
|
|
|
'confGood' => '<?php return Array("lang" => "xx");',
|
|
|
|
'confNotArray' => '<?php return 0;',
|
|
|
|
'confCorrupt' => '<?php return 0',
|
|
|
|
'confNotPHP' => 'DEAD BEEF',
|
|
|
|
'confEmpty' => '',
|
|
|
|
'confUnreadable' => '',
|
|
|
|
]);
|
|
|
|
self::$path = self::$vfs->url()."/";
|
|
|
|
// set up a file without read access
|
|
|
|
chmod(self::$path."confUnreadable", 0000);
|
|
|
|
}
|
2017-02-08 15:00:38 +00:00
|
|
|
|
2017-03-28 22:50:00 +00:00
|
|
|
function tearDown() {
|
2017-02-16 20:29:42 +00:00
|
|
|
self::$path = null;
|
|
|
|
self::$vfs = null;
|
2017-03-28 22:50:00 +00:00
|
|
|
$this->clearData();
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-02-16 20:29:42 +00:00
|
|
|
function testLoadDefaultValues() {
|
|
|
|
$this->assertInstanceOf(Conf::class, new Conf());
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testLoadDefaultValues */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromArray() {
|
|
|
|
$arr = ['lang' => "xx"];
|
|
|
|
$conf = new Conf();
|
|
|
|
$conf->import($arr);
|
|
|
|
$this->assertEquals("xx", $conf->lang);
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromArray */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromFile() {
|
|
|
|
$conf = new Conf();
|
|
|
|
$conf->importFile(self::$path."confGood");
|
|
|
|
$this->assertEquals("xx", $conf->lang);
|
|
|
|
$conf = new Conf(self::$path."confGood");
|
|
|
|
$this->assertEquals("xx", $conf->lang);
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromMissingFile() {
|
|
|
|
$this->assertException("fileMissing", "Conf");
|
|
|
|
$conf = new Conf(self::$path."confMissing");
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromEmptyFile() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
$conf = new Conf(self::$path."confEmpty");
|
|
|
|
}
|
2017-02-08 21:59:16 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromFileWithoutReadPermission() {
|
|
|
|
$this->assertException("fileUnreadable", "Conf");
|
|
|
|
$conf = new Conf(self::$path."confUnreadable");
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromFileWhichIsNotAnArray() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
$conf = new Conf(self::$path."confNotArray");
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromFileWhichIsNotPhp() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
// this should not print the output of the non-PHP file
|
|
|
|
$conf = new Conf(self::$path."confNotPHP");
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @depends testImportFromFile */
|
2017-02-16 20:29:42 +00:00
|
|
|
function testImportFromCorruptFile() {
|
|
|
|
$this->assertException("fileCorrupt", "Conf");
|
|
|
|
$conf = new Conf(self::$path."confCorrupt");
|
|
|
|
}
|
2017-02-06 00:00:57 +00:00
|
|
|
}
|