3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests\Config
;
7 use PhpMyAdmin\Config\ConfigFile
;
8 use PhpMyAdmin\Config\Form
;
9 use PhpMyAdmin\Tests\AbstractTestCase
;
11 use ReflectionProperty
;
12 use function array_keys
;
13 use function preg_match
;
15 class FormTest
extends AbstractTestCase
21 * Configures global environment.
23 protected function setUp(): void
26 parent
::defineVersionConstants();
28 parent
::loadDefaultConfig();
29 parent
::setGlobalConfig();
30 $GLOBALS['server'] = 0;
31 $this->object = new Form(
43 * tearDown for test cases
45 protected function tearDown(): void
52 * Test for Form::__constructor
56 public function testContructor(): void
66 $this->assertArrayHasKey(
73 * Test for Form::getOptionType
75 public function testGetOptionType(): void
77 $attrFieldsTypes = new ReflectionProperty(Form
::class, 'fieldsTypes');
78 $attrFieldsTypes->setAccessible(true);
79 $attrFieldsTypes->setValue(
85 $this->object->getOptionType('123/4/5/6')
90 $this->object->getOptionType('123/4/5/7')
95 * Test for Form::getOptionValueList
97 public function testGetOptionValueList(): void
104 $this->object->getOptionValueList('Export/codegen_format')
113 $this->object->getOptionValueList('OBGzip')
123 $this->object->getOptionValueList('RowActionLinks')
128 * Test for Form::readFormPathsCallback
130 public function testReadFormPathsCallBack(): void
132 $reflection = new ReflectionClass(Form
::class);
133 $method = $reflection->getMethod('readFormPathsCallback');
134 $method->setAccessible(true);
145 $method->invoke($this->object, $array, 'foo', 'pref');
147 $result = $this->object->fields
;
165 'preffoo/foo/bar/test',
169 // needs regexp because the counter is static
171 // assertMatchesRegularExpression added in 9.1
173 '/^preffoo\/foo\/bar\/\:group\:end\:\d+$/',
179 * Test for Form::readFormPaths
181 public function testReadFormPaths(): void
183 $reflection = new ReflectionClass(Form
::class);
184 $method = $reflection->getMethod('readFormPaths');
185 $method->setAccessible(true);
196 $method->invoke($this->object, $array);
198 $result = $this->object->fields
;
210 unset($result['test']);
212 // needs regexp because the counter is static
214 $keys = array_keys($result);
217 // assertMatchesRegularExpression added in 9.1
219 '/^\:group\:end\:(\d+)$/',
223 preg_match('/^\:group\:end\:(\d+)$/', $key, $matches);
224 $digit = $matches[1];
227 'foo/bar/:group:end:' . $digit,
228 $result[':group:end:' . $digit]
233 * Test for Form::readTypes
235 public function testReadTypes(): void
237 $reflection = new ReflectionClass(Form
::class);
238 $method = $reflection->getMethod('readTypes');
239 $method->setAccessible(true);
241 $this->object->fields
= [
242 'pma_form1' => 'Servers/1/port',
243 'pma_form2' => 'Servers/1/auth_type',
244 ':group:end:0' => 'preffoo/foo/bar/test',
245 '1' => 'preffoo/foo/bar/:group:end:0',
248 $attrFieldsTypes = $reflection->getProperty('fieldsTypes');
249 $attrFieldsTypes->setAccessible(true);
251 $method->invoke($this->object, null);
255 'pma_form1' => 'integer',
256 'pma_form2' => 'select',
257 ':group:end:0' => 'group',
260 $attrFieldsTypes->getValue($this->object)
265 * Test for Form::loadForm
267 public function testLoadForm(): void
269 $this->object = $this->getMockBuilder(Form
::class)
270 ->disableOriginalConstructor()
271 ->setMethods(['readFormPaths', 'readTypes'])
274 $this->object->expects($this->exactly(1))
275 ->method('readFormPaths')
276 ->with(['testForm']);
278 $this->object->expects($this->exactly(1))
279 ->method('readTypes');
281 $this->object->loadForm('pmaform', ['testForm']);
290 * Test for Form::cleanGroupPaths
292 public function testCleanGroupPaths(): void
294 $this->object = $this->getMockBuilder(Form
::class)
295 ->disableOriginalConstructor()
296 ->setMethods(['readFormPaths', 'readTypes'])
299 $this->object->expects($this->exactly(1))->method('readFormPaths')->with([
300 ':group:OpenDocument-OpenOffice 試算表',
302 'Export/ods_columns',
307 $this->object->loadForm('pmaform', [
308 ':group:OpenDocument/OpenOffice 試算表',
310 'Export/ods_columns',