1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests\Plugins\Export; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\ConfigStorage\Relation; |
8
|
|
|
use PhpMyAdmin\DatabaseInterface; |
9
|
|
|
use PhpMyAdmin\Export\Export; |
10
|
|
|
use PhpMyAdmin\Plugins\Export\ExportExcel; |
11
|
|
|
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; |
12
|
|
|
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; |
13
|
|
|
use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; |
14
|
|
|
use PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem; |
15
|
|
|
use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem; |
16
|
|
|
use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; |
17
|
|
|
use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; |
18
|
|
|
use PhpMyAdmin\Tests\AbstractTestCase; |
19
|
|
|
use PhpMyAdmin\Transformations; |
20
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
21
|
|
|
use PHPUnit\Framework\Attributes\Medium; |
22
|
|
|
use ReflectionMethod; |
23
|
|
|
use ReflectionProperty; |
24
|
|
|
|
25
|
|
|
#[CoversClass(ExportExcel::class)] |
26
|
|
|
#[Medium] |
27
|
|
|
class ExportExcelTest extends AbstractTestCase |
28
|
|
|
{ |
29
|
|
|
protected ExportExcel $object; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Configures global environment. |
33
|
|
|
*/ |
34
|
|
|
protected function setUp(): void |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
|
38
|
|
|
$dbi = $this->createDatabaseInterface(); |
39
|
|
|
DatabaseInterface::$instance = $dbi; |
40
|
|
|
$this->object = new ExportExcel( |
41
|
|
|
new Relation($dbi), |
42
|
|
|
new Export($dbi), |
43
|
|
|
new Transformations(), |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* tearDown for test cases |
49
|
|
|
*/ |
50
|
|
|
protected function tearDown(): void |
51
|
|
|
{ |
52
|
|
|
parent::tearDown(); |
53
|
|
|
|
54
|
|
|
unset($this->object); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSetProperties(): void |
58
|
|
|
{ |
59
|
|
|
$method = new ReflectionMethod(ExportExcel::class, 'setProperties'); |
60
|
|
|
$method->invoke($this->object, null); |
61
|
|
|
|
62
|
|
|
$attrProperties = new ReflectionProperty(ExportExcel::class, 'properties'); |
63
|
|
|
$properties = $attrProperties->getValue($this->object); |
64
|
|
|
|
65
|
|
|
self::assertInstanceOf(ExportPluginProperties::class, $properties); |
66
|
|
|
|
67
|
|
|
self::assertSame( |
68
|
|
|
'CSV for MS Excel', |
69
|
|
|
$properties->getText(), |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
self::assertSame( |
73
|
|
|
'csv', |
74
|
|
|
$properties->getExtension(), |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
self::assertSame( |
78
|
|
|
'text/comma-separated-values', |
79
|
|
|
$properties->getMimeType(), |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
self::assertSame( |
83
|
|
|
'Options', |
84
|
|
|
$properties->getOptionsText(), |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$options = $properties->getOptions(); |
88
|
|
|
|
89
|
|
|
self::assertInstanceOf(OptionsPropertyRootGroup::class, $options); |
90
|
|
|
|
91
|
|
|
self::assertSame( |
92
|
|
|
'Format Specific Options', |
93
|
|
|
$options->getName(), |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$generalOptionsArray = $options->getProperties(); |
97
|
|
|
$generalOptions = $generalOptionsArray->current(); |
98
|
|
|
|
99
|
|
|
self::assertInstanceOf(OptionsPropertyMainGroup::class, $generalOptions); |
100
|
|
|
|
101
|
|
|
self::assertSame( |
102
|
|
|
'general_opts', |
103
|
|
|
$generalOptions->getName(), |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$generalProperties = $generalOptions->getProperties(); |
107
|
|
|
|
108
|
|
|
$property = $generalProperties->current(); |
109
|
|
|
$generalProperties->next(); |
110
|
|
|
|
111
|
|
|
self::assertInstanceOf(TextPropertyItem::class, $property); |
112
|
|
|
|
113
|
|
|
self::assertSame( |
114
|
|
|
'null', |
115
|
|
|
$property->getName(), |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
self::assertSame( |
119
|
|
|
'Replace NULL with:', |
120
|
|
|
$property->getText(), |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$property = $generalProperties->current(); |
124
|
|
|
$generalProperties->next(); |
125
|
|
|
|
126
|
|
|
self::assertInstanceOf(BoolPropertyItem::class, $property); |
127
|
|
|
|
128
|
|
|
self::assertSame( |
129
|
|
|
'removeCRLF', |
130
|
|
|
$property->getName(), |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
self::assertSame( |
134
|
|
|
'Remove carriage return/line feed characters within columns', |
135
|
|
|
$property->getText(), |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$property = $generalProperties->current(); |
139
|
|
|
$generalProperties->next(); |
140
|
|
|
|
141
|
|
|
self::assertInstanceOf(BoolPropertyItem::class, $property); |
142
|
|
|
|
143
|
|
|
self::assertSame( |
144
|
|
|
'columns', |
145
|
|
|
$property->getName(), |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
self::assertSame( |
149
|
|
|
'Put columns names in the first row', |
150
|
|
|
$property->getText(), |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$property = $generalProperties->current(); |
154
|
|
|
$generalProperties->next(); |
155
|
|
|
|
156
|
|
|
self::assertInstanceOf(SelectPropertyItem::class, $property); |
157
|
|
|
|
158
|
|
|
self::assertSame( |
159
|
|
|
'edition', |
160
|
|
|
$property->getName(), |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
self::assertSame( |
164
|
|
|
[ |
165
|
|
|
'win' => 'Windows', |
166
|
|
|
'mac_excel2003' => 'Excel 2003 / Macintosh', |
167
|
|
|
'mac_excel2008' => 'Excel 2008 / Macintosh', |
168
|
|
|
], |
169
|
|
|
$property->getValues(), |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
self::assertSame( |
173
|
|
|
'Excel edition:', |
174
|
|
|
$property->getText(), |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$property = $generalProperties->current(); |
178
|
|
|
|
179
|
|
|
self::assertInstanceOf(HiddenPropertyItem::class, $property); |
180
|
|
|
|
181
|
|
|
self::assertSame( |
182
|
|
|
'structure_or_data', |
183
|
|
|
$property->getName(), |
184
|
|
|
); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|