3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests\Plugins\Export
;
7 use PhpMyAdmin\ConfigStorage\Relation
;
8 use PhpMyAdmin\Dbal\DatabaseInterface
;
9 use PhpMyAdmin\Export\Export
;
10 use PhpMyAdmin\Plugins\Export\ExportPdf
;
11 use PhpMyAdmin\Plugins\Export\Helpers\Pdf
;
12 use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup
;
13 use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup
;
14 use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem
;
15 use PhpMyAdmin\Properties\Options\Items\TextPropertyItem
;
16 use PhpMyAdmin\Properties\Plugins\ExportPluginProperties
;
17 use PhpMyAdmin\Tests\AbstractTestCase
;
18 use PhpMyAdmin\Transformations
;
19 use PHPUnit\Framework\Attributes\CoversClass
;
20 use PHPUnit\Framework\Attributes\Medium
;
22 use ReflectionProperty
;
26 #[CoversClass(ExportPdf::class)]
28 class ExportPdfTest
extends AbstractTestCase
30 protected ExportPdf
$object;
33 * Configures global environment.
35 protected function setUp(): void
39 $dbi = $this->createDatabaseInterface();
40 DatabaseInterface
::$instance = $dbi;
41 Export
::$outputKanjiConversion = false;
42 Export
::$outputCharsetConversion = false;
43 Export
::$bufferNeeded = false;
44 Export
::$asFile = true;
45 Export
::$saveOnServer = false;
46 $this->object = new ExportPdf(
49 new Transformations(),
54 * tearDown for test cases
56 protected function tearDown(): void
63 public function testSetProperties(): void
65 $method = new ReflectionMethod(ExportPdf
::class, 'setProperties');
66 $method->invoke($this->object, null);
68 $attrProperties = new ReflectionProperty(ExportPdf
::class, 'properties');
69 $properties = $attrProperties->getValue($this->object);
71 self
::assertInstanceOf(ExportPluginProperties
::class, $properties);
75 $properties->getText(),
80 $properties->getExtension(),
85 $properties->getMimeType(),
90 $properties->getOptionsText(),
94 $properties->getForceFile(),
97 $options = $properties->getOptions();
99 self
::assertInstanceOf(OptionsPropertyRootGroup
::class, $options);
102 'Format Specific Options',
106 $generalOptionsArray = $options->getProperties();
108 $generalOptions = $generalOptionsArray->current();
109 $generalOptionsArray->next();
111 self
::assertInstanceOf(OptionsPropertyMainGroup
::class, $generalOptions);
115 $generalOptions->getName(),
118 $generalProperties = $generalOptions->getProperties();
120 $property = $generalProperties->current();
122 self
::assertInstanceOf(TextPropertyItem
::class, $property);
126 $property->getName(),
129 $generalOptions = $generalOptionsArray->current();
131 self
::assertInstanceOf(OptionsPropertyMainGroup
::class, $generalOptions);
135 $generalOptions->getName(),
140 $generalOptions->getText(),
143 $generalProperties = $generalOptions->getProperties();
145 $property = $generalProperties->current();
147 self
::assertInstanceOf(RadioPropertyItem
::class, $property);
151 $property->getName(),
155 ['structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data')],
156 $property->getValues(),
160 public function testExportHeader(): void
162 $pdf = $this->getMockBuilder(Pdf
::class)
163 ->disableOriginalConstructor()
166 $pdf->expects(self
::once())
169 $pdf->expects(self
::once())
170 ->method('setTopMargin');
172 $attrPdf = new ReflectionProperty(ExportPdf
::class, 'pdf');
173 $attrPdf->setValue($this->object, $pdf);
176 $this->object->exportHeader(),
180 public function testExportFooter(): void
182 $pdf = $this->getMockBuilder(Pdf
::class)
183 ->disableOriginalConstructor()
186 $pdf->expects(self
::once())
187 ->method('getPDFData')
190 $attrPdf = new ReflectionProperty(ExportPdf
::class, 'pdf');
191 $attrPdf->setValue($this->object, $pdf);
194 $this->object->exportFooter(),
198 public function testExportDBHeader(): void
201 $this->object->exportDBHeader('testDB'),
205 public function testExportDBFooter(): void
208 $this->object->exportDBFooter('testDB'),
212 public function testExportDBCreate(): void
215 $this->object->exportDBCreate('testDB'),
219 public function testExportData(): void
221 $pdf = $this->getMockBuilder(Pdf
::class)
222 ->disableOriginalConstructor()
225 $pdf->expects(self
::once())
226 ->method('mysqlReport')
229 $attrPdf = new ReflectionProperty(ExportPdf
::class, 'pdf');
230 $attrPdf->setValue($this->object, $pdf);
233 $this->object->exportData(
243 * - PhpMyAdmin\Plugins\Export\ExportPdf::setPdf
244 * - PhpMyAdmin\Plugins\Export\ExportPdf::getPdf
246 public function testSetGetPdf(): void
248 $setter = new ReflectionMethod(ExportPdf
::class, 'setPdf');
249 $setter->invoke($this->object, new Pdf());
251 $getter = new ReflectionMethod(ExportPdf
::class, 'getPdf');
252 self
::assertInstanceOf(
254 $getter->invoke($this->object),