Translated using Weblate (Portuguese)
[phpmyadmin.git] / tests / unit / Plugins / Export / ExportPdfTest.php
blob96ee8077ffb9b9357dc887720b19abf70c22f065
1 <?php
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;
21 use ReflectionMethod;
22 use ReflectionProperty;
24 use function __;
26 #[CoversClass(ExportPdf::class)]
27 #[Medium]
28 class ExportPdfTest extends AbstractTestCase
30 protected ExportPdf $object;
32 /**
33 * Configures global environment.
35 protected function setUp(): void
37 parent::setUp();
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(
47 new Relation($dbi),
48 new Export($dbi),
49 new Transformations(),
53 /**
54 * tearDown for test cases
56 protected function tearDown(): void
58 parent::tearDown();
60 unset($this->object);
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);
73 self::assertSame(
74 'PDF',
75 $properties->getText(),
78 self::assertSame(
79 'pdf',
80 $properties->getExtension(),
83 self::assertSame(
84 'application/pdf',
85 $properties->getMimeType(),
88 self::assertSame(
89 'Options',
90 $properties->getOptionsText(),
93 self::assertTrue(
94 $properties->getForceFile(),
97 $options = $properties->getOptions();
99 self::assertInstanceOf(OptionsPropertyRootGroup::class, $options);
101 self::assertSame(
102 'Format Specific Options',
103 $options->getName(),
106 $generalOptionsArray = $options->getProperties();
108 $generalOptions = $generalOptionsArray->current();
109 $generalOptionsArray->next();
111 self::assertInstanceOf(OptionsPropertyMainGroup::class, $generalOptions);
113 self::assertSame(
114 'general_opts',
115 $generalOptions->getName(),
118 $generalProperties = $generalOptions->getProperties();
120 $property = $generalProperties->current();
122 self::assertInstanceOf(TextPropertyItem::class, $property);
124 self::assertSame(
125 'report_title',
126 $property->getName(),
129 $generalOptions = $generalOptionsArray->current();
131 self::assertInstanceOf(OptionsPropertyMainGroup::class, $generalOptions);
133 self::assertSame(
134 'dump_what',
135 $generalOptions->getName(),
138 self::assertSame(
139 'Dump table',
140 $generalOptions->getText(),
143 $generalProperties = $generalOptions->getProperties();
145 $property = $generalProperties->current();
147 self::assertInstanceOf(RadioPropertyItem::class, $property);
149 self::assertSame(
150 'structure_or_data',
151 $property->getName(),
154 self::assertSame(
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()
164 ->getMock();
166 $pdf->expects(self::once())
167 ->method('Open');
169 $pdf->expects(self::once())
170 ->method('setTopMargin');
172 $attrPdf = new ReflectionProperty(ExportPdf::class, 'pdf');
173 $attrPdf->setValue($this->object, $pdf);
175 self::assertTrue(
176 $this->object->exportHeader(),
180 public function testExportFooter(): void
182 $pdf = $this->getMockBuilder(Pdf::class)
183 ->disableOriginalConstructor()
184 ->getMock();
186 $pdf->expects(self::once())
187 ->method('getPDFData')
188 ->willReturn('');
190 $attrPdf = new ReflectionProperty(ExportPdf::class, 'pdf');
191 $attrPdf->setValue($this->object, $pdf);
193 self::assertTrue(
194 $this->object->exportFooter(),
198 public function testExportDBHeader(): void
200 self::assertTrue(
201 $this->object->exportDBHeader('testDB'),
205 public function testExportDBFooter(): void
207 self::assertTrue(
208 $this->object->exportDBFooter('testDB'),
212 public function testExportDBCreate(): void
214 self::assertTrue(
215 $this->object->exportDBCreate('testDB'),
219 public function testExportData(): void
221 $pdf = $this->getMockBuilder(Pdf::class)
222 ->disableOriginalConstructor()
223 ->getMock();
225 $pdf->expects(self::once())
226 ->method('mysqlReport')
227 ->with('SELECT');
229 $attrPdf = new ReflectionProperty(ExportPdf::class, 'pdf');
230 $attrPdf->setValue($this->object, $pdf);
232 self::assertTrue(
233 $this->object->exportData(
234 'db',
235 'table',
236 'SELECT',
242 * Test for
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(
253 Pdf::class,
254 $getter->invoke($this->object),