|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpMyAdmin\Tests\Plugins\Schema; |
| 6 | + |
| 7 | +use PhpMyAdmin\Identifiers\DatabaseName; |
| 8 | +use PhpMyAdmin\Plugins\Schema\SchemaPdf; |
| 9 | +use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; |
| 10 | +use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; |
| 11 | +use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem; |
| 12 | +use PhpMyAdmin\Tests\AbstractTestCase; |
| 13 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 14 | + |
| 15 | +#[CoversClass(SchemaPdf::class)] |
| 16 | +final class SchemaPdfTest extends AbstractTestCase |
| 17 | +{ |
| 18 | + public function testGetName(): void |
| 19 | + { |
| 20 | + self::assertSame('pdf', (new SchemaPdf())->getName()); |
| 21 | + } |
| 22 | + |
| 23 | + public function testSetProperties(): void |
| 24 | + { |
| 25 | + $properties = (new SchemaPdf())->getProperties(); |
| 26 | + self::assertSame('PDF', $properties->getText()); |
| 27 | + self::assertSame('pdf', $properties->getExtension()); |
| 28 | + self::assertSame('application/pdf', $properties->getMimeType()); |
| 29 | + $options = $properties->getOptions(); |
| 30 | + self::assertNotNull($options); |
| 31 | + self::assertSame('Format Specific Options', $options->getName()); |
| 32 | + $specificOptions = $options->getProperties(); |
| 33 | + self::assertCount(1, $specificOptions); |
| 34 | + $specificOption = $specificOptions->current(); |
| 35 | + self::assertInstanceOf(OptionsPropertyMainGroup::class, $specificOption); |
| 36 | + self::assertSame('general_opts', $specificOption->getName()); |
| 37 | + self::assertCount(8, $specificOption); |
| 38 | + $specificOptionProperties = $specificOption->getProperties(); |
| 39 | + |
| 40 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 41 | + self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty); |
| 42 | + self::assertSame('show_color', $specificOptionProperty->getName()); |
| 43 | + self::assertSame('Show color', $specificOptionProperty->getText()); |
| 44 | + |
| 45 | + $specificOptionProperties->next(); |
| 46 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 47 | + self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty); |
| 48 | + self::assertSame('show_keys', $specificOptionProperty->getName()); |
| 49 | + self::assertSame('Only show keys', $specificOptionProperty->getText()); |
| 50 | + |
| 51 | + $specificOptionProperties->next(); |
| 52 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 53 | + self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty); |
| 54 | + self::assertSame('all_tables_same_width', $specificOptionProperty->getName()); |
| 55 | + self::assertSame('Same width for all tables', $specificOptionProperty->getText()); |
| 56 | + |
| 57 | + $specificOptionProperties->next(); |
| 58 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 59 | + self::assertInstanceOf(SelectPropertyItem::class, $specificOptionProperty); |
| 60 | + self::assertSame('orientation', $specificOptionProperty->getName()); |
| 61 | + self::assertSame('Orientation', $specificOptionProperty->getText()); |
| 62 | + self::assertSame(['L' => 'Landscape', 'P' => 'Portrait'], $specificOptionProperty->getValues()); |
| 63 | + |
| 64 | + $specificOptionProperties->next(); |
| 65 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 66 | + self::assertInstanceOf(SelectPropertyItem::class, $specificOptionProperty); |
| 67 | + self::assertSame('paper', $specificOptionProperty->getName()); |
| 68 | + self::assertSame('Paper size', $specificOptionProperty->getText()); |
| 69 | + self::assertSame( |
| 70 | + ['A3' => 'A3', 'A4' => 'A4', 'A5' => 'A5', 'letter' => 'letter', 'legal' => 'legal'], |
| 71 | + $specificOptionProperty->getValues(), |
| 72 | + ); |
| 73 | + |
| 74 | + $specificOptionProperties->next(); |
| 75 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 76 | + self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty); |
| 77 | + self::assertSame('show_grid', $specificOptionProperty->getName()); |
| 78 | + self::assertSame('Show grid', $specificOptionProperty->getText()); |
| 79 | + |
| 80 | + $specificOptionProperties->next(); |
| 81 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 82 | + self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty); |
| 83 | + self::assertSame('with_doc', $specificOptionProperty->getName()); |
| 84 | + self::assertSame('Data dictionary', $specificOptionProperty->getText()); |
| 85 | + |
| 86 | + $specificOptionProperties->next(); |
| 87 | + $specificOptionProperty = $specificOptionProperties->current(); |
| 88 | + self::assertInstanceOf(SelectPropertyItem::class, $specificOptionProperty); |
| 89 | + self::assertSame('table_order', $specificOptionProperty->getName()); |
| 90 | + self::assertSame('Order of the tables', $specificOptionProperty->getText()); |
| 91 | + self::assertSame( |
| 92 | + ['' => 'None', 'name_asc' => 'Name (Ascending)', 'name_desc' => 'Name (Descending)'], |
| 93 | + $specificOptionProperty->getValues(), |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + public function testGetExportInfo(): void |
| 98 | + { |
| 99 | + if (! SchemaPdf::isAvailable()) { |
| 100 | + self::markTestSkipped('SchemaPdf plugin is not available.'); |
| 101 | + } |
| 102 | + |
| 103 | + $_REQUEST['page_number'] = '0'; |
| 104 | + $_REQUEST['pdf_table_order'] = ''; |
| 105 | + $_REQUEST['pdf_orientation'] = 'L'; |
| 106 | + $_REQUEST['pdf_paper'] = 'A4'; |
| 107 | + |
| 108 | + $actual = (new SchemaPdf())->getExportInfo(DatabaseName::from('test_db')); |
| 109 | + |
| 110 | + self::assertSame('test_db.pdf', $actual['fileName']); |
| 111 | + self::assertSame('application/pdf', $actual['mediaType']); |
| 112 | + self::assertNotEmpty($actual['fileData']); |
| 113 | + } |
| 114 | +} |
0 commit comments