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
;
13 use function array_keys
;
14 use function preg_match
;
17 * @covers \PhpMyAdmin\Config\Form
19 class FormTest
extends AbstractTestCase
25 * Configures global environment.
27 protected function setUp(): void
31 parent
::setGlobalConfig();
32 $GLOBALS['server'] = 0;
33 $this->object = new Form(
45 * tearDown for test cases
47 protected function tearDown(): void
54 * Test for Form::__constructor
58 public function testContructor(): void
60 $this->assertEquals(1, $this->object->index
);
61 $this->assertEquals('pma_form_name', $this->object->name
);
62 $this->assertArrayHasKey('pma_form1', $this->object->fields
);
66 * Test for Form::getOptionType
68 public function testGetOptionType(): void
70 $attrFieldsTypes = new ReflectionProperty(Form
::class, 'fieldsTypes');
71 $attrFieldsTypes->setAccessible(true);
72 $attrFieldsTypes->setValue(
78 $this->object->getOptionType('123/4/5/6')
83 $this->object->getOptionType('123/4/5/7')
88 * Test for Form::getOptionValueList
90 public function testGetOptionValueList(): void
97 $this->object->getOptionValueList('Export/codegen_format')
106 $this->object->getOptionValueList('OBGzip')
116 $this->object->getOptionValueList('RowActionLinks')
121 * Test for Form::readFormPathsCallback
123 public function testReadFormPathsCallBack(): void
125 $reflection = new ReflectionClass(Form
::class);
126 $method = $reflection->getMethod('readFormPathsCallback');
127 $method->setAccessible(true);
138 $method->invoke($this->object, $array, 'foo', 'pref');
140 $result = $this->object->fields
;
142 $this->assertCount(4, $result);
144 $this->assertEquals('pma_form1', $result['pma_form1']);
146 $this->assertEquals('pma_form2', $result['pma_form2']);
148 $this->assertEquals('preffoo/foo/bar/test', $result[0]);
150 $this->assertIsString($result[1]);
152 // needs regexp because the counter is static
153 $this->assertMatchesRegularExpression('/^preffoo\/foo\/bar\/\:group\:end\:\d+$/', $result[1]);
157 * Test for Form::readFormPaths
159 public function testReadFormPaths(): void
161 $reflection = new ReflectionClass(Form
::class);
162 $method = $reflection->getMethod('readFormPaths');
163 $method->setAccessible(true);
174 $method->invoke($this->object, $array);
176 $result = $this->object->fields
;
178 $this->assertCount(2, $result);
180 $this->assertEquals('foo/bar/test', $result['test']);
182 unset($result['test']);
184 // needs regexp because the counter is static
186 $keys = array_keys($result);
188 $this->assertIsString($key);
189 $this->assertMatchesRegularExpression('/^\:group\:end\:(\d+)$/', $key);
191 preg_match('/^\:group\:end\:(\d+)$/', $key, $matches);
192 $digit = $matches[1];
194 $this->assertEquals('foo/bar/:group:end:' . $digit, $result[':group:end:' . $digit]);
198 * Test for Form::readTypes
200 public function testReadTypes(): void
202 $reflection = new ReflectionClass(Form
::class);
203 $method = $reflection->getMethod('readTypes');
204 $method->setAccessible(true);
206 $this->object->fields
= [
207 'pma_form1' => 'Servers/1/port',
208 'pma_form2' => 'Servers/1/auth_type',
209 ':group:end:0' => 'preffoo/foo/bar/test',
210 '1' => 'preffoo/foo/bar/:group:end:0',
213 $attrFieldsTypes = $reflection->getProperty('fieldsTypes');
214 $attrFieldsTypes->setAccessible(true);
216 $method->invoke($this->object, null);
220 'pma_form1' => 'integer',
221 'pma_form2' => 'select',
222 ':group:end:0' => 'group',
225 $attrFieldsTypes->getValue($this->object)
230 * Test for Form::loadForm
232 public function testLoadForm(): void
234 $this->object = $this->getMockBuilder(Form
::class)
235 ->disableOriginalConstructor()
236 ->onlyMethods(['readFormPaths', 'readTypes'])
239 $this->object->expects($this->exactly(1))
240 ->method('readFormPaths')
241 ->with(['testForm']);
243 $this->object->expects($this->exactly(1))
244 ->method('readTypes');
246 $this->object->loadForm('pmaform', ['testForm']);
248 $this->assertEquals('pmaform', $this->object->name
);
252 * Test for Form::cleanGroupPaths
254 public function testCleanGroupPaths(): void
256 $this->object = $this->getMockBuilder(Form
::class)
257 ->disableOriginalConstructor()
258 ->onlyMethods(['readFormPaths', 'readTypes'])
261 $this->object->expects($this->exactly(1))->method('readFormPaths')->with([
262 ':group:OpenDocument-OpenOffice 試算表',
264 'Export/ods_columns',
269 $this->object->loadForm('pmaform', [
270 ':group:OpenDocument/OpenOffice 試算表',
272 'Export/ods_columns',