Add script 'get-openssl-version.sh'.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test;
|
||||
|
||||
use dokuwiki\plugin\config\core\ConfigParser;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class ConfigParserTest extends \DokuWikiTest {
|
||||
|
||||
function test_readconfig() {
|
||||
$parser = new ConfigParser();
|
||||
$conf = $parser->parse(__DIR__ . '/data/config.php');
|
||||
|
||||
// var_dump($conf);
|
||||
|
||||
$this->assertEquals('42', $conf['int1']);
|
||||
$this->assertEquals('6*7', $conf['int2']);
|
||||
|
||||
$this->assertEquals('Hello World', $conf['str1']);
|
||||
$this->assertEquals('G\'day World', $conf['str2']);
|
||||
$this->assertEquals('Hello World', $conf['str3']);
|
||||
$this->assertEquals("Hello 'World'", $conf['str4']);
|
||||
$this->assertEquals('Hello "World"', $conf['str5']);
|
||||
|
||||
$this->assertEquals(array('foo', 'bar', 'baz'), $conf['arr1']);
|
||||
}
|
||||
|
||||
function test_readconfig_onoff() {
|
||||
$parser = new ConfigParser();
|
||||
$conf = $parser->parse(__DIR__ . '/data/config.php');
|
||||
|
||||
// var_dump($conf);
|
||||
|
||||
$this->assertEquals(0, $conf['onoff1']);
|
||||
$this->assertEquals(1, $conf['onoff2']);
|
||||
$this->assertEquals(2, $conf['onoff3']);
|
||||
$this->assertEquals(0, $conf['onoff4']);
|
||||
$this->assertEquals(1, $conf['onoff5']);
|
||||
$this->assertEquals(false, $conf['onoff6']);
|
||||
$this->assertEquals(true, $conf['onoff7']);
|
||||
$this->assertEquals('false', $conf['onoff8']);
|
||||
$this->assertEquals('true', $conf['onoff9']);
|
||||
|
||||
$this->assertEquals('false senctence', $conf['str11']);
|
||||
$this->assertEquals('true sentence', $conf['str12']);
|
||||
$this->assertEquals('truesfdf', $conf['str13']);
|
||||
$this->assertEquals("true", $conf['str14']);
|
||||
$this->assertEquals("truesfdsf", $conf['str15']);
|
||||
|
||||
$this->assertTrue($conf['onoff1'] == false);
|
||||
$this->assertTrue($conf['onoff2'] == true);
|
||||
$this->assertTrue($conf['onoff3'] == true);
|
||||
$this->assertTrue($conf['onoff4'] == false);
|
||||
$this->assertTrue($conf['onoff5'] == true);
|
||||
$this->assertTrue($conf['onoff6'] == false);
|
||||
$this->assertTrue($conf['onoff7'] == true);
|
||||
$this->assertTrue($conf['onoff8'] == true); //string
|
||||
$this->assertTrue($conf['onoff9'] == true); //string
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test;
|
||||
|
||||
use dokuwiki\HTTP\DokuHTTPClient;
|
||||
use dokuwiki\plugin\config\core\Configuration;
|
||||
use dokuwiki\plugin\config\core\Setting\SettingFieldset;
|
||||
use dokuwiki\plugin\config\core\Setting\SettingHidden;
|
||||
|
||||
/**
|
||||
* Ensure config options have documentation at dokuwiki.org
|
||||
*
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
* @group internet
|
||||
*/
|
||||
class DocumentationTest extends \DokuWikiTest
|
||||
{
|
||||
/**
|
||||
* @return \Generator|array[]
|
||||
*/
|
||||
public function provideSettings()
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
|
||||
foreach ($configuration->getSettings() as $setting) {
|
||||
if (is_a($setting, SettingHidden::class)) continue;
|
||||
if (is_a($setting, SettingFieldset::class)) continue;
|
||||
|
||||
$key = $setting->getKey();
|
||||
$pretty = $setting->getPrettyKey();
|
||||
if (!preg_match('/ href="(.*?)"/', $pretty, $m)) continue;
|
||||
$url = $m[1];
|
||||
|
||||
yield [$key, $url];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSettings
|
||||
* @param string $key Settingskey
|
||||
* @param string $url Documentation URL
|
||||
*/
|
||||
public function testDocs($key, $url)
|
||||
{
|
||||
$http = new DokuHTTPClient();
|
||||
$check = $http->get($url);
|
||||
$fail = (bool)strpos($check, 'topic does not exist');
|
||||
$msg = "Setting '$key' should have documentation at $url.";
|
||||
$this->assertFalse($fail, $msg . ' ' . $http->status . ' ' . $http->error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test;
|
||||
|
||||
use dokuwiki\plugin\config\core\ConfigParser;
|
||||
use dokuwiki\plugin\config\core\Loader;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class LoaderExtraDefaultsTest extends \DokuWikiTest
|
||||
{
|
||||
|
||||
protected $pluginsEnabled = ['testing'];
|
||||
|
||||
protected $oldSetting = [];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $config_cascade;
|
||||
|
||||
$out = "<?php\n/*\n * protected settings, cannot modified in the Config manager\n" .
|
||||
" * Some test data */\n";
|
||||
$out .= "\$conf['title'] = 'New default Title';\n";
|
||||
$out .= "\$conf['tagline'] = 'New default Tagline';\n";
|
||||
$out .= "\$conf['plugin']['testing']['schnibble'] = 1;\n";
|
||||
$out .= "\$conf['plugin']['testing']['second'] = 'New default setting';\n";
|
||||
|
||||
$file = DOKU_CONF . 'otherdefaults.php';
|
||||
file_put_contents($file, $out);
|
||||
|
||||
//store original settings
|
||||
$this->oldSetting = $config_cascade['main']['default'];
|
||||
//add second file with defaults, which override the defaults of DokuWiki
|
||||
$config_cascade['main']['default'][] = $file;
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure loading the defaults work, and that the extra default for plugins provided via an extra main default file
|
||||
* override the plugin defaults as well
|
||||
*/
|
||||
public function testDefaultsOverwriting()
|
||||
{
|
||||
$loader = new Loader(new ConfigParser());
|
||||
|
||||
$conf = $loader->loadDefaults();
|
||||
$this->assertTrue(is_array($conf));
|
||||
|
||||
// basic defaults
|
||||
$this->assertArrayHasKey('title', $conf);
|
||||
$this->assertEquals('New default Title', $conf['title']);
|
||||
$this->assertEquals('New default Tagline', $conf['tagline']);
|
||||
|
||||
// plugin defaults
|
||||
$this->assertArrayHasKey('plugin____testing____schnibble', $conf);
|
||||
$this->assertEquals(1, $conf['plugin____testing____schnibble']);
|
||||
$this->assertEquals('New default setting', $conf['plugin____testing____second']);
|
||||
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
global $config_cascade;
|
||||
|
||||
$config_cascade['main']['default'] = $this->oldSetting;
|
||||
unlink(DOKU_CONF . 'otherdefaults.php');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test;
|
||||
|
||||
use dokuwiki\plugin\config\core\ConfigParser;
|
||||
use dokuwiki\plugin\config\core\Loader;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class LoaderTest extends \DokuWikiTest {
|
||||
|
||||
protected $pluginsEnabled = ['testing'];
|
||||
|
||||
/**
|
||||
* Ensure loading the config meta data works
|
||||
*/
|
||||
public function testMetaData() {
|
||||
$loader = new Loader(new ConfigParser());
|
||||
|
||||
$meta = $loader->loadMeta();
|
||||
$this->assertTrue(is_array($meta));
|
||||
|
||||
// there should be some defaults
|
||||
$this->assertArrayHasKey('savedir', $meta);
|
||||
$this->assertEquals(['savedir', '_caution' => 'danger'], $meta['savedir']);
|
||||
$this->assertArrayHasKey('proxy____port', $meta);
|
||||
$this->assertEquals(['numericopt'], $meta['proxy____port']);
|
||||
|
||||
// there should be plugin info
|
||||
$this->assertArrayHasKey('plugin____testing____plugin_settings_name', $meta);
|
||||
$this->assertEquals(['fieldset'], $meta['plugin____testing____plugin_settings_name']);
|
||||
$this->assertArrayHasKey('plugin____testing____schnibble', $meta);
|
||||
$this->assertEquals(['onoff'], $meta['plugin____testing____schnibble']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure loading the defaults work
|
||||
*/
|
||||
public function testDefaults() {
|
||||
$loader = new Loader(new ConfigParser());
|
||||
|
||||
$conf = $loader->loadDefaults();
|
||||
$this->assertTrue(is_array($conf));
|
||||
|
||||
// basic defaults
|
||||
$this->assertArrayHasKey('title', $conf);
|
||||
$this->assertEquals('DokuWiki', $conf['title']);
|
||||
|
||||
// plugin defaults
|
||||
$this->assertArrayHasKey('plugin____testing____schnibble', $conf);
|
||||
$this->assertEquals(0, $conf['plugin____testing____schnibble']);
|
||||
$this->assertEquals('Default value', $conf['plugin____testing____second']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure language loading works
|
||||
*/
|
||||
public function testLangs() {
|
||||
$loader = new Loader(new ConfigParser());
|
||||
|
||||
$lang = $loader->loadLangs();
|
||||
$this->assertTrue(is_array($lang));
|
||||
|
||||
// basics are not included in the returned array!
|
||||
$this->assertArrayNotHasKey('title', $lang);
|
||||
|
||||
// plugin strings
|
||||
$this->assertArrayHasKey('plugin____testing____plugin_settings_name', $lang);
|
||||
$this->assertEquals('Testing', $lang['plugin____testing____plugin_settings_name']);
|
||||
$this->assertArrayHasKey('plugin____testing____schnibble', $lang);
|
||||
$this->assertEquals(
|
||||
'Turns on the schnibble before the frobble is used',
|
||||
$lang['plugin____testing____schnibble']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
use dokuwiki\plugin\config\core\Setting\Setting;
|
||||
|
||||
abstract class AbstractSettingTest extends \DokuWikiTest {
|
||||
|
||||
/** @var string the class to test */
|
||||
protected $class;
|
||||
|
||||
/**
|
||||
* Sets up the proper class to test based on the test's class name
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setUp() : void {
|
||||
parent::setUp();
|
||||
$class = get_class($this);
|
||||
$class = substr($class, strrpos($class, '\\') + 1, -4);
|
||||
$class = 'dokuwiki\\plugin\\config\\core\\Setting\\' . $class;
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public function testInitialBasics() {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$this->assertEquals('test', $setting->getKey());
|
||||
$this->assertSame(false, $setting->isProtected());
|
||||
$this->assertSame(true, $setting->isDefault());
|
||||
$this->assertSame(false, $setting->hasError());
|
||||
$this->assertSame(false, $setting->shouldBeSaved());
|
||||
}
|
||||
|
||||
public function testShouldHaveDefault() {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$this->assertSame(true, $setting->shouldHaveDefault());
|
||||
}
|
||||
|
||||
public function testPrettyKey() {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$this->assertEquals('test', $setting->getPrettyKey(false));
|
||||
|
||||
$setting = new $this->class('test____foo');
|
||||
$this->assertEquals('test»foo', $setting->getPrettyKey(false));
|
||||
|
||||
$setting = new $this->class('test');
|
||||
$this->assertEquals(
|
||||
'<a href="https://www.dokuwiki.org/config:test">test</a>',
|
||||
$setting->getPrettyKey(true)
|
||||
);
|
||||
|
||||
$setting = new $this->class('test____foo');
|
||||
$this->assertEquals('test»foo', $setting->getPrettyKey(true));
|
||||
|
||||
$setting = new $this->class('start');
|
||||
$this->assertEquals(
|
||||
'<a href="https://www.dokuwiki.org/config:startpage">start</a>',
|
||||
$setting->getPrettyKey(true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testType() {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$this->assertEquals('dokuwiki', $setting->getType());
|
||||
|
||||
$setting = new $this->class('test_foo');
|
||||
$this->assertEquals('dokuwiki', $setting->getType());
|
||||
|
||||
$setting = new $this->class('plugin____test');
|
||||
$this->assertEquals('plugin', $setting->getType());
|
||||
|
||||
$setting = new $this->class('tpl____test');
|
||||
$this->assertEquals('template', $setting->getType());
|
||||
}
|
||||
|
||||
public function testCaution() {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$this->assertEquals(false, $setting->caution());
|
||||
|
||||
$setting = new $this->class('test', ['_caution' => 'warning']);
|
||||
$this->assertEquals('warning', $setting->caution());
|
||||
|
||||
$setting = new $this->class('test', ['_caution' => 'danger']);
|
||||
$this->assertEquals('danger', $setting->caution());
|
||||
|
||||
$setting = new $this->class('test', ['_caution' => 'security']);
|
||||
$this->assertEquals('security', $setting->caution());
|
||||
|
||||
$setting = new $this->class('test', ['_caution' => 'flargh']);
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$setting->caution();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingArrayTest extends SettingTest {
|
||||
|
||||
/** @inheritdoc */
|
||||
public function dataOut() {
|
||||
return [
|
||||
[ ['foo','bar'], "\$conf['test'] = array('foo', 'bar');\n"]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingNumericTest extends SettingTest {
|
||||
|
||||
/** @inheritdoc */
|
||||
public function dataOut() {
|
||||
return [
|
||||
[42, "\$conf['test'] = 42;\n"],
|
||||
[0, "\$conf['test'] = 0;\n"],
|
||||
[-42, "\$conf['test'] = -42;\n"],
|
||||
[-42.13, "\$conf['test'] = -42.13;\n"],
|
||||
['12*13', "\$conf['test'] = 12*13;\n"],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingNumericoptTest extends SettingNumericTest {
|
||||
|
||||
/** @inheritdoc */
|
||||
public function dataOut() {
|
||||
return array_merge(
|
||||
parent::dataOut(),
|
||||
[
|
||||
['', "\$conf['test'] = '';\n"],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingOnoffTest extends SettingTest {
|
||||
|
||||
/** @inheritdoc */
|
||||
public function dataOut() {
|
||||
return [
|
||||
[1, "\$conf['test'] = 1;\n"],
|
||||
[0, "\$conf['test'] = 0;\n"],
|
||||
|
||||
['1', "\$conf['test'] = 1;\n"],
|
||||
['0', "\$conf['test'] = 0;\n"],
|
||||
|
||||
['on', "\$conf['test'] = 1;\n"],
|
||||
['off', "\$conf['test'] = 0;\n"],
|
||||
|
||||
['true', "\$conf['test'] = 1;\n"],
|
||||
['false', "\$conf['test'] = 0;\n"],
|
||||
|
||||
['On', "\$conf['test'] = 1;\n"],
|
||||
['Off', "\$conf['test'] = 0;\n"],
|
||||
|
||||
['True', "\$conf['test'] = 1;\n"],
|
||||
['False', "\$conf['test'] = 0;\n"],
|
||||
|
||||
[true, "\$conf['test'] = 1;\n"],
|
||||
[false, "\$conf['test'] = 0;\n"],
|
||||
|
||||
[3, "\$conf['test'] = 1;\n"],
|
||||
['3', "\$conf['test'] = 1;\n"],
|
||||
|
||||
['', "\$conf['test'] = 0;\n"],
|
||||
[' ', "\$conf['test'] = 0;\n"],
|
||||
];
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function dataShouldBeSaved() {
|
||||
return [
|
||||
[0, null, false],
|
||||
[1, null, false],
|
||||
[0, 0, false],
|
||||
[1, 1, false],
|
||||
[0, 1, true],
|
||||
[1, 0, true],
|
||||
|
||||
['0', '0', false],
|
||||
['1', '1', false],
|
||||
['0', '1', true],
|
||||
['1', '0', true],
|
||||
|
||||
['0', 0, false],
|
||||
['1', 1, false],
|
||||
['0', 1, true],
|
||||
['1', 0, true],
|
||||
|
||||
[0, '0', false],
|
||||
[1, '1', false],
|
||||
[0, '1', true],
|
||||
[1, '0', true],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingStringTest extends SettingTest {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test\Setting;
|
||||
|
||||
use dokuwiki\plugin\config\core\Setting\Setting;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class SettingTest extends AbstractSettingTest {
|
||||
|
||||
/**
|
||||
* Dataprovider for testOut()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataOut() {
|
||||
return [
|
||||
['bar', "\$conf['test'] = 'bar';\n"],
|
||||
["foo'bar", "\$conf['test'] = 'foo\\'bar';\n"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the output
|
||||
*
|
||||
* @param mixed $in The value to initialize the setting with
|
||||
* @param string $out The expected output (for conf[test])
|
||||
* @dataProvider dataOut
|
||||
*/
|
||||
public function testOut($in, $out) {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$setting->initialize('ignore', $in);
|
||||
|
||||
$this->assertEquals($out, $setting->out('conf'));
|
||||
}
|
||||
|
||||
/**
|
||||
* DataProvider for testShouldBeSaved()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataShouldBeSaved() {
|
||||
return [
|
||||
['default', null, false],
|
||||
['default', 'default', false],
|
||||
['default', 'new', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if shouldBeSaved works as expected
|
||||
*
|
||||
* @dataProvider dataShouldBeSaved
|
||||
* @param mixed $default The default value
|
||||
* @param mixed $local The current local value
|
||||
* @param bool $expect The expected outcome
|
||||
*/
|
||||
public function testShouldBeSaved($default, $local, $expect) {
|
||||
/** @var Setting $setting */
|
||||
$setting = new $this->class('test');
|
||||
$setting->initialize($default, $local, null);
|
||||
$this->assertSame($expect, $setting->shouldBeSaved());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\config\test;
|
||||
use dokuwiki\plugin\config\core\Setting\SettingString;
|
||||
use dokuwiki\plugin\config\core\Writer;
|
||||
|
||||
/**
|
||||
* @group plugin_config
|
||||
* @group admin_plugins
|
||||
* @group plugins
|
||||
* @group bundled_plugins
|
||||
*/
|
||||
class WriterTest extends \DokuWikiTest {
|
||||
|
||||
public function testSave() {
|
||||
global $config_cascade;
|
||||
$config = end($config_cascade['main']['local']);
|
||||
|
||||
$set1 = new SettingString('test1');
|
||||
$set1->initialize('foo','bar', null);
|
||||
$set2 = new SettingString('test2');
|
||||
$set2->initialize('foo','foo', null);
|
||||
$settings = [$set1, $set2];
|
||||
$writer = new Writer();
|
||||
|
||||
// before running, no backup should exist
|
||||
$this->assertFileExists($config);
|
||||
$this->assertFileNotExists("$config.bak.php");
|
||||
$old = filesize($config);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$writer->save($settings);
|
||||
|
||||
// after running, both should exist
|
||||
$this->assertFileExists($config);
|
||||
$this->assertFileExists("$config.bak.php");
|
||||
$this->assertEquals($old, filesize("$config.bak.php"), 'backup should have size of old file');
|
||||
|
||||
// check contents
|
||||
$conf = [];
|
||||
include $config;
|
||||
$this->assertArrayHasKey('test1', $conf);
|
||||
$this->assertEquals('bar', $conf['test1']);
|
||||
$this->assertArrayNotHasKey('test2', $conf);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$writer->save($settings);
|
||||
$this->assertEquals(filesize($config), filesize("$config.bak.php"));
|
||||
}
|
||||
|
||||
public function testTouch() {
|
||||
global $config_cascade;
|
||||
$config = end($config_cascade['main']['local']);
|
||||
$writer = new Writer();
|
||||
|
||||
$old = filemtime($config);
|
||||
$this->waitForTick(true);
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$writer->touch();
|
||||
clearstatcache($config);
|
||||
$this->assertGreaterThan($old, filemtime($config));
|
||||
}
|
||||
|
||||
public function testEmpty() {
|
||||
$writer = new Writer();
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectErrorMessage('empty config');
|
||||
$writer->save([]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
|
||||
$conf['int1'] = 42;
|
||||
$conf['int2'] = 6*7;
|
||||
|
||||
$conf['str1'] = 'Hello World';
|
||||
$conf['str2'] = 'G\'day World';
|
||||
$conf['str3'] = "Hello World";
|
||||
$conf['str4'] = "Hello 'World'";
|
||||
$conf['str5'] = "Hello \"World\"";
|
||||
|
||||
$conf['arr1'] = array('foo','bar', 'baz');
|
||||
|
||||
$conf['foo']['bar'] = 'x1';
|
||||
$conf['foo']['baz'] = 'x2';
|
||||
|
||||
$conf['onoff1'] = 0;
|
||||
$conf['onoff2'] = 1;
|
||||
$conf['onoff3'] = 2;
|
||||
$conf['onoff4'] = '0';
|
||||
$conf['onoff5'] = '1';
|
||||
$conf['onoff6'] = false;
|
||||
$conf['onoff7'] = true;
|
||||
$conf['onoff8'] = 'false';
|
||||
$conf['onoff9'] = 'true';
|
||||
|
||||
$conf['str11'] = 'false senctence';
|
||||
$conf['str12'] = 'true sentence';
|
||||
$conf['str13'] = 'truesfdf';
|
||||
$conf['str14'] = "true";
|
||||
$conf['str15'] = "truesfdsf";
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
$meta['int1'] = array('numeric');
|
||||
$meta['int2'] = array('numeric');
|
||||
|
||||
$meta['str1'] = array('string');
|
||||
$meta['str2'] = array('string');
|
||||
$meta['str3'] = array('string');
|
||||
$meta['str4'] = array('string');
|
||||
$meta['str5'] = array('string');
|
||||
|
||||
$meta['arr1'] = array('array');
|
||||
|
||||
$meta['onoff1'] = array('onoff');
|
||||
$meta['onoff2'] = array('onoff');
|
||||
$meta['onoff3'] = array('onoff');
|
||||
$meta['onoff4'] = array('onoff');
|
||||
$meta['onoff5'] = array('onoff');
|
||||
$meta['onoff6'] = array('onoff');
|
||||
$meta['onoff7'] = array('onoff');
|
||||
$meta['onoff8'] = array('onoff');
|
||||
$meta['onoff9'] = array('onoff');
|
||||
|
||||
$meta['str11'] = array('string');
|
||||
$meta['str12'] = array('string');
|
||||
$meta['str13'] = array('string');
|
||||
$meta['str14'] = array('string');
|
||||
$meta['str15'] = array('string');
|
||||
Reference in New Issue
Block a user