Replace `global` keyword with `$GLOBALS`
[phpmyadmin.git] / test / classes / Export / OptionsTest.php
blob92acd16137a94864e4ab01320990919220bcfaa8
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Export;
7 use PhpMyAdmin\Config;
8 use PhpMyAdmin\ConfigStorage\Relation;
9 use PhpMyAdmin\DatabaseInterface;
10 use PhpMyAdmin\Encoding;
11 use PhpMyAdmin\Export\Options;
12 use PhpMyAdmin\Export\TemplateModel;
13 use PhpMyAdmin\Plugins;
14 use PhpMyAdmin\Tests\AbstractTestCase;
15 use PhpMyAdmin\Util;
17 /**
18 * @covers \PhpMyAdmin\Export\Options
20 class OptionsTest extends AbstractTestCase
22 /** @var Options */
23 private $export;
25 protected function setUp(): void
27 parent::setUp();
28 parent::setLanguage();
29 parent::setGlobalConfig();
30 $GLOBALS['cfg']['Server']['host'] = 'localhost';
31 $GLOBALS['cfg']['Server']['user'] = 'pma_user';
32 $GLOBALS['server'] = 0;
34 $GLOBALS['table'] = 'table';
35 $GLOBALS['db'] = 'PMA';
37 $pmaconfig = $this->getMockBuilder(Config::class)
38 ->disableOriginalConstructor()
39 ->getMock();
41 $pmaconfig->expects($this->any())
42 ->method('getUserValue')
43 ->will($this->returnValue('user value for test'));
45 $GLOBALS['config'] = $pmaconfig;
47 $this->export = new Options(
48 new Relation($GLOBALS['dbi']),
49 new TemplateModel($GLOBALS['dbi'])
53 public function testGetOptions(): void
55 $GLOBALS['cfg']['Export']['method'] = 'XML';
56 $GLOBALS['cfg']['SaveDir'] = '/tmp';
57 $GLOBALS['cfg']['ZipDump'] = false;
58 $GLOBALS['cfg']['GZipDump'] = false;
60 $export_type = 'server';
61 $db = 'PMA';
62 $table = 'PMA_test';
63 $num_tables_str = '10';
64 $unlim_num_rows_str = 'unlim_num_rows_str';
65 //$single_table = "single_table";
66 $GLOBALS['dbi']->getCache()->cacheTableContent([$db, $table, 'ENGINE'], 'MERGE');
68 $columns_info = [
69 'test_column1' => ['COLUMN_NAME' => 'test_column1'],
70 'test_column2' => ['COLUMN_NAME' => 'test_column2'],
72 $dbi = $this->getMockBuilder(DatabaseInterface::class)
73 ->disableOriginalConstructor()
74 ->getMock();
76 $dbi->expects($this->any())->method('getColumnsFull')
77 ->will($this->returnValue($columns_info));
78 $dbi->expects($this->any())->method('getCompatibilities')
79 ->will($this->returnValue([]));
81 $GLOBALS['dbi'] = $dbi;
83 $exportList = Plugins::getExport($export_type, true);
84 $dropdown = Plugins::getChoice($exportList, 'sql');
86 //Call the test function
87 $actual = $this->export->getOptions(
88 $export_type,
89 $db,
90 $table,
91 '',
92 $num_tables_str,
93 $unlim_num_rows_str,
94 $exportList
97 $expected = [
98 'export_type' => $export_type,
99 'db' => $db,
100 'table' => $table,
101 'templates' => [
102 'is_enabled' => '',
103 'templates' => [],
104 'selected' => null,
106 'sql_query' => '',
107 'hidden_inputs' => [
108 'db' => $db,
109 'table' => $table,
110 'export_type' => $export_type,
111 'export_method' => $GLOBALS['cfg']['Export']['method'],
112 'template_id' => '',
114 'export_method' => $GLOBALS['cfg']['Export']['method'],
115 'plugins_choice' => $dropdown,
116 'options' => Plugins::getOptions('Export', $exportList),
117 'can_convert_kanji' => Encoding::canConvertKanji(),
118 'exec_time_limit' => $GLOBALS['cfg']['ExecTimeLimit'],
119 'rows' => [],
120 'has_save_dir' => true,
121 'save_dir' => Util::userDir($GLOBALS['cfg']['SaveDir']),
122 'export_is_checked' => $GLOBALS['cfg']['Export']['quick_export_onserver'],
123 'export_overwrite_is_checked' => $GLOBALS['cfg']['Export']['quick_export_onserver_overwrite'],
124 'has_aliases' => false,
125 'aliases' => [],
126 'is_checked_lock_tables' => $GLOBALS['cfg']['Export']['lock_tables'],
127 'is_checked_asfile' => $GLOBALS['cfg']['Export']['asfile'],
128 'is_checked_as_separate_files' => $GLOBALS['cfg']['Export']['as_separate_files'],
129 'is_checked_export' => $GLOBALS['cfg']['Export']['onserver'],
130 'is_checked_export_overwrite' => $GLOBALS['cfg']['Export']['onserver_overwrite'],
131 'is_checked_remember_file_template' => $GLOBALS['cfg']['Export']['remember_file_template'],
132 'repopulate' => '',
133 'lock_tables' => '',
134 'is_encoding_supported' => true,
135 'encodings' => Encoding::listEncodings(),
136 'export_charset' => $GLOBALS['cfg']['Export']['charset'],
137 'export_asfile' => $GLOBALS['cfg']['Export']['asfile'],
138 'has_zip' => $GLOBALS['cfg']['ZipDump'],
139 'has_gzip' => $GLOBALS['cfg']['GZipDump'],
140 'selected_compression' => 'none',
141 'filename_template' => 'user value for test',
144 $this->assertIsArray($actual);
145 $this->assertEquals($expected, $actual);