1<?php 2 3use ComboStrap\TplUtility; 4use dokuwiki\plugin\config\core\ConfigParser; 5use dokuwiki\plugin\config\core\Loader; 6 7require_once(__DIR__ . '/../class/TplUtility.php'); 8 9 10/** 11 * Test the settings.php file 12 * 13 * @group template_strap 14 * @group templates 15 */ 16class configTest extends DokuWikiTest 17{ 18 19 const CONF_WITHOUT_DEFAULT = [TplUtility::CONF_FOOTER_SLOT_PAGE_NAME, 20 TplUtility::CONF_HEADER_SLOT_PAGE_NAME, 21 TplUtility::CONF_SIDEKICK_SLOT_PAGE_NAME, 22 TplUtility::CONF_REM_SIZE 23 ]; 24 25 public function setUp(): void 26 { 27 28 global $conf; 29 parent::setUp(); 30 $conf['template'] = 'strap'; 31 /** 32 * static variable bug in the {@link tpl_getConf()} 33 * that does not load the configuration twice 34 */ 35 TplUtility::reloadConf(); 36 37 38 } 39 40 41 /** 42 * 43 * Test if we don't have any problem 44 * in the file settings.php 45 * 46 * If there is, we got an error in the admin config page 47 */ 48 public function test_base() 49 { 50 51 $request = new TestRequest(); 52 global $conf; 53 $conf['useacl'] = 1; 54 $user = 'admin'; 55 $conf['superuser'] = $user; 56 57 // $_SERVER[] = $user; 58 $request->setServer('REMOTE_USER', $user); 59 60 $response = $request->get(array('do' => 'admin', 'page' => "config"), '/doku.php'); 61 62 // Simple 63 /** 64 * The conf identifier used as id in the pae configuration 65 * and in array 66 */ 67 $htmlId = "tpl____" . TplUtility::TEMPLATE_NAME . "____tpl_settings_name"; 68 $countListContainer = $response->queryHTML("#" . $htmlId)->count(); 69 $this->assertEquals(1, $countListContainer, "There should an element"); 70 71 } 72 73 /** 74 * Test to ensure that every conf['...'] entry 75 * in conf/default.php has a corresponding meta['...'] entry in conf/metadata.php. 76 */ 77 public function test_plugin_default() 78 { 79 $conf = array(); 80 $conf_file = __DIR__ . '/../conf/default.php'; 81 if (file_exists($conf_file)) { 82 include($conf_file); 83 } 84 85 $meta = array(); 86 $meta_file = __DIR__ . '/../conf/metadata.php'; 87 if (file_exists($meta_file)) { 88 include($meta_file); 89 } 90 91 92 $this->assertEquals( 93 gettype($conf), 94 gettype($meta), 95 'Both ' . DOKU_PLUGIN . 'syntax/conf/default.php and ' . DOKU_PLUGIN . 'syntax/conf/metadata.php have to exist and contain the same keys.' 96 ); 97 98 if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') { 99 foreach ($conf as $key => $value) { 100 $this->assertArrayHasKey( 101 $key, 102 $meta, 103 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 104 ); 105 } 106 107 foreach ($meta as $key => $value) { 108 109 /** 110 * Known configuration without default 111 */ 112 if (in_array($key, 113 self::CONF_WITHOUT_DEFAULT 114 )) { 115 continue; 116 } 117 $this->assertArrayHasKey( 118 $key, 119 $conf, 120 'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/default.php' 121 ); 122 } 123 } 124 125 /** 126 * English language 127 */ 128 $lang = array(); 129 $settings_file = __DIR__ . '/../lang/en/settings.php'; 130 if (file_exists($settings_file)) { 131 include($settings_file); 132 } 133 134 135 $this->assertEquals( 136 gettype($conf), 137 gettype($lang), 138 'Both ' . DOKU_PLUGIN . 'syntax/conf/metadata.php and ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php have to exist and contain the same keys.' 139 ); 140 141 if (gettype($conf) != 'NULL' && gettype($lang) != 'NULL') { 142 foreach ($conf as $key => $value) { 143 $this->assertArrayHasKey( 144 $key, 145 $conf, 146 'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/conf/metadata.php' 147 ); 148 } 149 150 foreach ($lang as $key => $value) { 151 $this->assertArrayHasKey( 152 $key, 153 $lang, 154 'Key $lang[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'syntax/lang/en/settings.php' 155 ); 156 } 157 } 158 159 160 /** 161 * The default value are read through parsing 162 * by the config plugin. 163 * You can't use variable in them. 164 * 165 * Yes that's fuck up but yeah 166 * This test check that we can read them 167 */ 168 $parser = new ConfigParser(); 169 $loader = new Loader($parser); 170 $defaultConf = $loader->loadDefaults(); 171 $keyPrefix = 'tpl____strap____'; 172 $this->assertTrue(is_array($defaultConf)); 173 174 // plugin defaults 175 foreach ($meta as $key => $value) { 176 /** 177 * Known configuration without default 178 */ 179 if (in_array($key, 180 self::CONF_WITHOUT_DEFAULT 181 )) { 182 continue; 183 } 184 $this->assertArrayHasKey( 185 $keyPrefix . $key, 186 $defaultConf, 187 'Key $conf[\'' . $key . '\'] could not be parsed in ' . DOKU_PLUGIN . 'syntax/conf/default.php. Be sure to give only values and not variable.' 188 ); 189 } 190 191 192 } 193 194 195} 196