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() 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 self::runAsAdmin($request); 36 37 $response = $request->get(array('do' => 'admin', 'page' => "config"), '/doku.php'); 38 39 // Simple 40 $countListContainer = $response->queryHTML("#plugin____" . helper_plugin_stale::PLUGIN_NAME . "____plugin_settings_name")->count(); 41 $this->assertEquals(1, $countListContainer, "There should an element"); 42 43 } 44 45 public function test_delete_sitemap() 46 { 47 48 global $conf; 49 $cacheDirectory = $conf['cachedir']; 50 $file = $cacheDirectory . "/sitemap.xml.gz"; 51 touch($file); 52 53 /** @var helper_plugin_stale $stale */ 54 $stale = plugin_load('helper', 'stale'); 55 56 $result = $stale->deleteSitemap(); 57 $this->assertEquals(true, $result); 58 59 } 60 61 /** 62 * Test to ensure that every conf['...'] entry 63 * in conf/default.php has a corresponding meta['...'] entry in conf/metadata.php. 64 */ 65 public function test_plugin_default() 66 { 67 $conf = array(); 68 $conf_file = __DIR__ . '/../conf/default.php'; 69 if (file_exists($conf_file)) { 70 include($conf_file); 71 } 72 73 $meta = array(); 74 $meta_file = __DIR__ . '/../conf/metadata.php'; 75 if (file_exists($meta_file)) { 76 include($meta_file); 77 } 78 79 80 $this->assertEquals( 81 gettype($conf), 82 gettype($meta), 83 'Both ' . DOKU_PLUGIN . 'syntax/conf/default.php and ' . DOKU_PLUGIN . 'syntax/conf/metadata.php have to exist and contain the same keys.' 84 ); 85 86 if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { 87 foreach ($conf as $key => $value) { 88 $this->assertArrayHasKey( 89 $key, 90 $meta, 91 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 92 ); 93 } 94 95 foreach ($meta as $key => $value) { 96 $this->assertArrayHasKey( 97 $key, 98 $conf, 99 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/default.php' 100 ); 101 } 102 } 103 104 /** 105 * English language 106 */ 107 $lang = array(); 108 $settings_file = __DIR__ . '/../lang/en/settings.php'; 109 if (file_exists($settings_file)) { 110 include($settings_file); 111 } 112 113 114 $this->assertEquals( 115 gettype($conf), 116 gettype($lang), 117 'Both ' . DOKU_PLUGIN . 'syntax/conf/metadata.php and ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php have to exist and contain the same keys.' 118 ); 119 120 if (gettype($conf) != 'NULL' && gettype($lang) != 'NULL') { 121 foreach ($lang as $key => $value) { 122 $this->assertArrayHasKey( 123 $key, 124 $conf, 125 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 126 ); 127 } 128 129 foreach ($conf as $key => $value) { 130 $this->assertArrayHasKey( 131 $key, 132 $lang, 133 'Key $lang[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php' 134 ); 135 } 136 } 137 138 /** 139 * The default are read through parsing 140 * by the config plugin 141 * Yes that's fuck up but yeah 142 * This test check that we can read them 143 */ 144 $parser = new ConfigParser(); 145 $loader = new Loader($parser); 146 $defaultConf = $loader->loadDefaults(); 147 $keyPrefix = "plugin____" . helper_plugin_stale::PLUGIN_NAME . "____"; 148 $this->assertTrue(is_array($defaultConf)); 149 150 // plugin defaults 151 foreach ($meta as $key => $value) { 152 $this->assertArrayHasKey( 153 $keyPrefix . $key, 154 $defaultConf, 155 'Key $conf[\'' . $key . '\'] could not be parsed in ' . DOKU_PLUGIN . 'syntax/conf/default.php. Be sure to give only values and not variable.' 156 ); 157 } 158 159 160 } 161 162 163 164 private static function runAsAdmin(TestRequest $request = null, $user = 'admin') 165 { 166 global $conf; 167 $conf['useacl'] = 1; 168 $conf['superuser'] = $user; 169 $conf['remoteuser'] = $user; 170 171 if ($request != null) { 172 $request->setServer('REMOTE_USER', $user); 173 } else { 174 global $INPUT; 175 $INPUT->server->set('REMOTE_USER', $user); 176 } 177 } 178 179 180} 181