Remove some useless comments
[phpmyadmin.git] / test / classes / Config / FormTest.php
blob2a61f445b25fb05e1c07e334e9d606a4120c2c46
1 <?php
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;
10 use ReflectionClass;
11 use ReflectionProperty;
12 use function array_keys;
13 use function preg_match;
15 class FormTest extends AbstractTestCase
17 /** @var Form */
18 protected $object;
20 /**
21 * Configures global environment.
23 protected function setUp(): void
25 parent::setUp();
26 parent::defineVersionConstants();
27 parent::setTheme();
28 parent::loadDefaultConfig();
29 parent::setGlobalConfig();
30 $GLOBALS['server'] = 0;
31 $this->object = new Form(
32 'pma_form_name',
34 'pma_form1',
35 'pma_form2',
37 new ConfigFile(),
42 /**
43 * tearDown for test cases
45 protected function tearDown(): void
47 parent::tearDown();
48 unset($this->object);
51 /**
52 * Test for Form::__constructor
54 * @group medium
56 public function testContructor(): void
58 $this->assertEquals(
60 $this->object->index
62 $this->assertEquals(
63 'pma_form_name',
64 $this->object->name
66 $this->assertArrayHasKey(
67 'pma_form1',
68 $this->object->fields
72 /**
73 * Test for Form::getOptionType
75 public function testGetOptionType(): void
77 $attrFieldsTypes = new ReflectionProperty(Form::class, 'fieldsTypes');
78 $attrFieldsTypes->setAccessible(true);
79 $attrFieldsTypes->setValue(
80 $this->object,
81 ['7' => 'Seven']
84 $this->assertNull(
85 $this->object->getOptionType('123/4/5/6')
88 $this->assertEquals(
89 'Seven',
90 $this->object->getOptionType('123/4/5/7')
94 /**
95 * Test for Form::getOptionValueList
97 public function testGetOptionValueList(): void
99 $this->assertEquals(
101 'NHibernate C# DO',
102 'NHibernate XML',
104 $this->object->getOptionValueList('Export/codegen_format')
107 $this->assertEquals(
109 'auto' => 'auto',
110 '1' => 1,
111 '0' => 0,
113 $this->object->getOptionValueList('OBGzip')
116 $this->assertEquals(
118 'none' => 'Nowhere',
119 'left' => 'Left',
120 'right' => 'Right',
121 'both' => 'Both',
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);
136 $array = [
137 'foo' => [
138 'bar' => [
139 'test' => 1,
140 1 => ':group:end',
145 $method->invoke($this->object, $array, 'foo', 'pref');
147 $result = $this->object->fields;
149 $this->assertCount(
151 $result
154 $this->assertEquals(
155 'pma_form1',
156 $result['pma_form1']
159 $this->assertEquals(
160 'pma_form2',
161 $result['pma_form2']
164 $this->assertEquals(
165 'preffoo/foo/bar/test',
166 $result[0]
169 // needs regexp because the counter is static
171 // assertMatchesRegularExpression added in 9.1
172 $this->assertRegExp(
173 '/^preffoo\/foo\/bar\/\:group\:end\:\d+$/',
174 $result[1]
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);
187 $array = [
188 'foo' => [
189 'bar' => [
190 'test' => 1,
191 1 => ':group:end',
196 $method->invoke($this->object, $array);
198 $result = $this->object->fields;
200 $this->assertCount(
202 $result
205 $this->assertEquals(
206 'foo/bar/test',
207 $result['test']
210 unset($result['test']);
212 // needs regexp because the counter is static
214 $keys = array_keys($result);
215 $key = $keys[0];
217 // assertMatchesRegularExpression added in 9.1
218 $this->assertRegExp(
219 '/^\:group\:end\:(\d+)$/',
220 $key
223 preg_match('/^\:group\:end\:(\d+)$/', $key, $matches);
224 $digit = $matches[1];
226 $this->assertEquals(
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);
253 $this->assertEquals(
255 'pma_form1' => 'integer',
256 'pma_form2' => 'select',
257 ':group:end:0' => 'group',
258 '1' => 'NULL',
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'])
272 ->getMock();
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']);
283 $this->assertEquals(
284 'pmaform',
285 $this->object->name
290 * Test for Form::cleanGroupPaths
292 public function testCleanGroupPaths(): void
294 $this->object = $this->getMockBuilder(Form::class)
295 ->disableOriginalConstructor()
296 ->setMethods(['readFormPaths', 'readTypes'])
297 ->getMock();
299 $this->object->expects($this->exactly(1))->method('readFormPaths')->with([
300 ':group:OpenDocument-OpenOffice 試算表',
301 'group:test/data',
302 'Export/ods_columns',
303 'Export/ods_null',
304 ':group:end',
307 $this->object->loadForm('pmaform', [
308 ':group:OpenDocument/OpenOffice 試算表',
309 'group:test/data',
310 'Export/ods_columns',
311 'Export/ods_null',
312 ':group:end',