File: OptionsTest.php

package info (click to toggle)
phpmyadmin 4%3A5.2.2-really%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 140,312 kB
  • sloc: javascript: 228,447; php: 166,904; xml: 17,847; sql: 504; sh: 275; makefile: 209; python: 205
file content (150 lines) | stat: -rw-r--r-- 5,014 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Export;

use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Export\Options;
use PhpMyAdmin\Export\TemplateModel;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Util;

/**
 * @covers \PhpMyAdmin\Export\Options
 */
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Export\Options::class)]
class OptionsTest extends AbstractTestCase
{
    /** @var Options */
    private $export;

    protected function setUp(): void
    {
        parent::setUp();
        parent::setLanguage();
        parent::setGlobalConfig();
        $GLOBALS['cfg']['Server']['host'] = 'localhost';
        $GLOBALS['cfg']['Server']['user'] = 'pma_user';
        $GLOBALS['server'] = 0;

        $GLOBALS['table'] = 'table';
        $GLOBALS['db'] = 'PMA';

        $pmaconfig = $this->getMockBuilder(Config::class)
            ->disableOriginalConstructor()
            ->getMock();

        $pmaconfig->expects($this->any())
            ->method('getUserValue')
            ->willReturn('user value for test');

        $GLOBALS['config'] = $pmaconfig;

        $this->export = new Options(
            new Relation($GLOBALS['dbi']),
            new TemplateModel($GLOBALS['dbi'])
        );
    }

    public function testGetOptions(): void
    {
        global $cfg;

        $cfg['Export']['method'] = 'XML';
        $cfg['SaveDir'] = '/tmp';
        $cfg['ZipDump'] = false;
        $cfg['GZipDump'] = false;

        $export_type = 'server';
        $db = 'PMA';
        $table = 'PMA_test';
        $num_tables_str = '10';
        $unlim_num_rows_str = 'unlim_num_rows_str';
        //$single_table = "single_table";
        $GLOBALS['dbi']->getCache()->cacheTableContent([$db, $table, 'ENGINE'], 'MERGE');

        $columns_info = [
            'test_column1' => ['COLUMN_NAME' => 'test_column1'],
            'test_column2' => ['COLUMN_NAME' => 'test_column2'],
        ];
        $dbi = $this->getMockBuilder(DatabaseInterface::class)
            ->disableOriginalConstructor()
            ->getMock();

        $dbi->expects($this->any())->method('getColumnsFull')
            ->willReturn($columns_info);
        $dbi->expects($this->any())->method('getCompatibilities')
            ->willReturn([]);

        $GLOBALS['dbi'] = $dbi;

        $exportList = Plugins::getExport($export_type, true);
        $dropdown = Plugins::getChoice($exportList, 'sql');

        //Call the test function
        $actual = $this->export->getOptions(
            $export_type,
            $db,
            $table,
            '',
            $num_tables_str,
            $unlim_num_rows_str,
            $exportList
        );

        $expected = [
            'export_type' => $export_type,
            'db' => $db,
            'table' => $table,
            'templates' => [
                'is_enabled' => '',
                'templates' => [],
                'selected' => null,
            ],
            'sql_query' => '',
            'hidden_inputs' => [
                'db' => $db,
                'table' => $table,
                'export_type' => $export_type,
                'export_method' => $cfg['Export']['method'],
                'template_id' => '',
            ],
            'export_method' => $cfg['Export']['method'],
            'plugins_choice' => $dropdown,
            'options' => Plugins::getOptions('Export', $exportList),
            'can_convert_kanji' => Encoding::canConvertKanji(),
            'exec_time_limit' => $cfg['ExecTimeLimit'],
            'rows' => [],
            'has_save_dir' => true,
            'save_dir' => Util::userDir($cfg['SaveDir']),
            'export_is_checked' => $cfg['Export']['quick_export_onserver'],
            'export_overwrite_is_checked' => $cfg['Export']['quick_export_onserver_overwrite'],
            'has_aliases' => false,
            'aliases' => [],
            'is_checked_lock_tables' => $cfg['Export']['lock_tables'],
            'is_checked_asfile' => $cfg['Export']['asfile'],
            'is_checked_as_separate_files' => $cfg['Export']['as_separate_files'],
            'is_checked_export' => $cfg['Export']['onserver'],
            'is_checked_export_overwrite' => $cfg['Export']['onserver_overwrite'],
            'is_checked_remember_file_template' => $cfg['Export']['remember_file_template'],
            'repopulate' => '',
            'lock_tables' => '',
            'is_encoding_supported' => true,
            'encodings' => Encoding::listEncodings(),
            'export_charset' => $cfg['Export']['charset'],
            'export_asfile' => $cfg['Export']['asfile'],
            'has_zip' => $cfg['ZipDump'],
            'has_gzip' => $cfg['GZipDump'],
            'selected_compression' => 'none',
            'filename_template' => 'user value for test',
        ];

        self::assertIsArray($actual);
        self::assertEquals($expected, $actual);
    }
}