1*98a151baSAndreas Gohr<?php 2*98a151baSAndreas Gohr 3*98a151baSAndreas Gohrnamespace dokuwiki\plugin\config\test; 4*98a151baSAndreas Gohruse dokuwiki\plugin\config\core\Setting\SettingString; 5*98a151baSAndreas Gohruse dokuwiki\plugin\config\core\Writer; 6*98a151baSAndreas Gohr 7*98a151baSAndreas Gohr/** 8*98a151baSAndreas Gohr * @group plugin_config 9*98a151baSAndreas Gohr * @group admin_plugins 10*98a151baSAndreas Gohr * @group plugins 11*98a151baSAndreas Gohr * @group bundled_plugins 12*98a151baSAndreas Gohr */ 13*98a151baSAndreas Gohrclass WriterTest extends \DokuWikiTest { 14*98a151baSAndreas Gohr 15*98a151baSAndreas Gohr public function testSave() { 16*98a151baSAndreas Gohr global $config_cascade; 17*98a151baSAndreas Gohr $config = end($config_cascade['main']['local']); 18*98a151baSAndreas Gohr 19*98a151baSAndreas Gohr $set1 = new SettingString('test1'); 20*98a151baSAndreas Gohr $set1->initialize('foo','bar', null); 21*98a151baSAndreas Gohr $set2 = new SettingString('test2'); 22*98a151baSAndreas Gohr $set2->initialize('foo','foo', null); 23*98a151baSAndreas Gohr $settings = [$set1, $set2]; 24*98a151baSAndreas Gohr $writer = new Writer(); 25*98a151baSAndreas Gohr 26*98a151baSAndreas Gohr // before running, no backup should exist 27*98a151baSAndreas Gohr $this->assertFileExists($config); 28*98a151baSAndreas Gohr $this->assertFileNotExists("$config.bak"); 29*98a151baSAndreas Gohr $old = filesize($config); 30*98a151baSAndreas Gohr 31*98a151baSAndreas Gohr /** @noinspection PhpUnhandledExceptionInspection */ 32*98a151baSAndreas Gohr $writer->save($settings); 33*98a151baSAndreas Gohr 34*98a151baSAndreas Gohr // after running, both should exist 35*98a151baSAndreas Gohr $this->assertFileExists($config); 36*98a151baSAndreas Gohr $this->assertFileExists("$config.bak"); 37*98a151baSAndreas Gohr $this->assertEquals($old, filesize("$config.bak"), 'backup should have size of old file'); 38*98a151baSAndreas Gohr 39*98a151baSAndreas Gohr // check contents 40*98a151baSAndreas Gohr $conf = []; 41*98a151baSAndreas Gohr include $config; 42*98a151baSAndreas Gohr $this->assertArrayHasKey('test1', $conf); 43*98a151baSAndreas Gohr $this->assertEquals('bar', $conf['test1']); 44*98a151baSAndreas Gohr $this->assertArrayNotHasKey('test2', $conf); 45*98a151baSAndreas Gohr 46*98a151baSAndreas Gohr /** @noinspection PhpUnhandledExceptionInspection */ 47*98a151baSAndreas Gohr $writer->save($settings); 48*98a151baSAndreas Gohr $this->assertEquals(filesize($config), filesize("$config.bak")); 49*98a151baSAndreas Gohr } 50*98a151baSAndreas Gohr 51*98a151baSAndreas Gohr public function testTouch() { 52*98a151baSAndreas Gohr global $config_cascade; 53*98a151baSAndreas Gohr $config = end($config_cascade['main']['local']); 54*98a151baSAndreas Gohr $writer = new Writer(); 55*98a151baSAndreas Gohr 56*98a151baSAndreas Gohr $old = filemtime($config); 57*98a151baSAndreas Gohr $this->waitForTick(true); 58*98a151baSAndreas Gohr /** @noinspection PhpUnhandledExceptionInspection */ 59*98a151baSAndreas Gohr $writer->touch(); 60*98a151baSAndreas Gohr clearstatcache($config); 61*98a151baSAndreas Gohr $this->assertGreaterThan($old, filemtime($config)); 62*98a151baSAndreas Gohr } 63*98a151baSAndreas Gohr} 64