1<?php 2 3use dokuwiki\plugin\config\core\ConfigParser; 4use dokuwiki\plugin\config\core\Loader; 5 6 7/** 8 * Test the settings.php file 9 * 10 * @group plugin_stale 11 * @group plugins 12 */ 13class baseTest extends DokuWikiTest 14{ 15 16 17 public function setUp(): void 18 { 19 $this->pluginsEnabled[] = helper_plugin_stale::PLUGIN_NAME; 20 parent::setUp(); 21 } 22 23 24 /** 25 * 26 * Test if we don't have any problem 27 * in the file settings.php 28 * 29 * If there is, we got an error in the admin config page 30 */ 31 public function test_base() 32 { 33 34 $request = new TestRequest(); 35 36 // run as admin 37 global $conf; 38 $conf['useacl'] = 1; 39 $user = "admin"; 40 $conf['superuser'] = $user; 41 $conf['remoteuser'] = $user; 42 $request->setServer('REMOTE_USER', $user); 43 44 45 $response = $request->get(array('do' => 'admin', 'page' => "config"), '/doku.php'); 46 47 // Simple 48 $countListContainer = $response->queryHTML("#plugin____" . helper_plugin_stale::PLUGIN_NAME . "____plugin_settings_name")->count(); 49 $this->assertEquals(1, $countListContainer, "There should an element"); 50 51 } 52 53 public function test_delete_sitemap() 54 { 55 56 global $conf; 57 $cacheDirectory = $conf['cachedir']; 58 $file = $cacheDirectory . "/sitemap.xml.gz"; 59 touch($file); 60 61 /** @var helper_plugin_stale $stale */ 62 $stale = plugin_load('helper', 'stale'); 63 64 $result = $stale->deleteSitemap(); 65 $this->assertEquals(true, $result); 66 67 } 68 69 /** 70 * Test to ensure that every conf['...'] entry 71 * in conf/default.php has a corresponding meta['...'] entry in conf/metadata.php. 72 */ 73 public function test_plugin_default() 74 { 75 $conf = array(); 76 $conf_file = __DIR__ . '/../conf/default.php'; 77 if (file_exists($conf_file)) { 78 include($conf_file); 79 } 80 81 $meta = array(); 82 $meta_file = __DIR__ . '/../conf/metadata.php'; 83 if (file_exists($meta_file)) { 84 include($meta_file); 85 } 86 87 88 $this->assertEquals( 89 gettype($conf), 90 gettype($meta), 91 'Both ' . DOKU_PLUGIN . 'syntax/conf/default.php and ' . DOKU_PLUGIN . 'syntax/conf/metadata.php have to exist and contain the same keys.' 92 ); 93 94 if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { 95 foreach ($conf as $key => $value) { 96 $this->assertArrayHasKey( 97 $key, 98 $meta, 99 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 100 ); 101 } 102 103 foreach ($meta as $key => $value) { 104 $this->assertArrayHasKey( 105 $key, 106 $conf, 107 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/default.php' 108 ); 109 } 110 } 111 112 /** 113 * English language 114 */ 115 $lang = array(); 116 $settings_file = __DIR__ . '/../lang/en/settings.php'; 117 if (file_exists($settings_file)) { 118 include($settings_file); 119 } 120 121 122 $this->assertEquals( 123 gettype($conf), 124 gettype($lang), 125 'Both ' . DOKU_PLUGIN . 'syntax/conf/metadata.php and ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php have to exist and contain the same keys.' 126 ); 127 128 if (gettype($conf) != 'NULL' && gettype($lang) != 'NULL') { 129 foreach ($lang as $key => $value) { 130 $this->assertArrayHasKey( 131 $key, 132 $conf, 133 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 134 ); 135 } 136 137 foreach ($conf as $key => $value) { 138 $this->assertArrayHasKey( 139 $key, 140 $lang, 141 'Key $lang[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php' 142 ); 143 } 144 } 145 146 /** 147 * The default are read through parsing 148 * by the config plugin 149 * Yes that's fuck up but yeah 150 * This test check that we can read them 151 */ 152 $parser = new ConfigParser(); 153 $loader = new Loader($parser); 154 $defaultConf = $loader->loadDefaults(); 155 $keyPrefix = "plugin____" . helper_plugin_stale::PLUGIN_NAME . "____"; 156 $this->assertTrue(is_array($defaultConf)); 157 158 // plugin defaults 159 foreach ($meta as $key => $value) { 160 $this->assertArrayHasKey( 161 $keyPrefix . $key, 162 $defaultConf, 163 'Key $conf[\'' . $key . '\'] could not be parsed in ' . DOKU_PLUGIN . 'syntax/conf/default.php. Be sure to give only values and not variable.' 164 ); 165 } 166 167 168 } 169 170 171} 172