Skip to content

Commit e10961d

Browse files
Merge pull request #18767 from MauricioFauth/schema-tests
Add some basic unit tests to schema plugins
2 parents 6620108 + c803c13 commit e10961d

5 files changed

Lines changed: 338 additions & 17 deletions

File tree

psalm-baseline.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9859,11 +9859,6 @@
98599859
<code>UploadSession</code>
98609860
</UnusedClass>
98619861
</file>
9862-
<file src="src/Plugins/Plugin.php">
9863-
<PossiblyUnusedMethod>
9864-
<code>getName</code>
9865-
</PossiblyUnusedMethod>
9866-
</file>
98679862
<file src="src/Plugins/Schema/Dia/DiaRelationSchema.php">
98689863
<MixedArgument>
98699864
<code>$oneField</code>
@@ -10326,33 +10321,21 @@
1032610321
<DeprecatedMethod>
1032710322
<code>DatabaseInterface::getInstance()</code>
1032810323
</DeprecatedMethod>
10329-
<UnusedClass>
10330-
<code>SchemaDia</code>
10331-
</UnusedClass>
1033210324
</file>
1033310325
<file src="src/Plugins/Schema/SchemaEps.php">
1033410326
<DeprecatedMethod>
1033510327
<code>DatabaseInterface::getInstance()</code>
1033610328
</DeprecatedMethod>
10337-
<UnusedClass>
10338-
<code>SchemaEps</code>
10339-
</UnusedClass>
1034010329
</file>
1034110330
<file src="src/Plugins/Schema/SchemaPdf.php">
1034210331
<DeprecatedMethod>
1034310332
<code>DatabaseInterface::getInstance()</code>
1034410333
</DeprecatedMethod>
10345-
<UnusedClass>
10346-
<code>SchemaPdf</code>
10347-
</UnusedClass>
1034810334
</file>
1034910335
<file src="src/Plugins/Schema/SchemaSvg.php">
1035010336
<DeprecatedMethod>
1035110337
<code>DatabaseInterface::getInstance()</code>
1035210338
</DeprecatedMethod>
10353-
<UnusedClass>
10354-
<code>SchemaSvg</code>
10355-
</UnusedClass>
1035610339
</file>
1035710340
<file src="src/Plugins/Schema/Svg/RelationStatsSvg.php">
1035810341
<MixedMethodCall>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\SchemaDia;
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(SchemaDia::class)]
16+
final class SchemaDiaTest extends AbstractTestCase
17+
{
18+
public function testGetName(): void
19+
{
20+
self::assertSame('dia', (new SchemaDia())->getName());
21+
}
22+
23+
public function testSetProperties(): void
24+
{
25+
$properties = (new SchemaDia())->getProperties();
26+
self::assertSame('Dia', $properties->getText());
27+
self::assertSame('dia', $properties->getExtension());
28+
self::assertSame('application/dia', $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(4, $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(SelectPropertyItem::class, $specificOptionProperty);
54+
self::assertSame('orientation', $specificOptionProperty->getName());
55+
self::assertSame('Orientation', $specificOptionProperty->getText());
56+
self::assertSame(['L' => 'Landscape', 'P' => 'Portrait'], $specificOptionProperty->getValues());
57+
58+
$specificOptionProperties->next();
59+
$specificOptionProperty = $specificOptionProperties->current();
60+
self::assertInstanceOf(SelectPropertyItem::class, $specificOptionProperty);
61+
self::assertSame('paper', $specificOptionProperty->getName());
62+
self::assertSame('Paper size', $specificOptionProperty->getText());
63+
self::assertSame(
64+
['A3' => 'A3', 'A4' => 'A4', 'A5' => 'A5', 'letter' => 'letter', 'legal' => 'legal'],
65+
$specificOptionProperty->getValues(),
66+
);
67+
}
68+
69+
public function testGetExportInfo(): void
70+
{
71+
$_REQUEST['page_number'] = '0';
72+
$_REQUEST['dia_orientation'] = 'L';
73+
$_REQUEST['dia_paper'] = 'A4';
74+
75+
$actual = (new SchemaDia())->getExportInfo(DatabaseName::from('test_db'));
76+
77+
self::assertSame('test_db.dia', $actual['fileName']);
78+
self::assertSame('application/x-dia-diagram', $actual['mediaType']);
79+
self::assertStringStartsWith('<?xml version="1.0" encoding="UTF-8"?>', $actual['fileData']);
80+
}
81+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\SchemaEps;
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(SchemaEps::class)]
16+
final class SchemaEpsTest extends AbstractTestCase
17+
{
18+
public function testGetName(): void
19+
{
20+
self::assertSame('eps', (new SchemaEps())->getName());
21+
}
22+
23+
public function testSetProperties(): void
24+
{
25+
$properties = (new SchemaEps())->getProperties();
26+
self::assertSame('EPS', $properties->getText());
27+
self::assertSame('eps', $properties->getExtension());
28+
self::assertSame('application/eps', $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(4, $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+
65+
public function testGetExportInfo(): void
66+
{
67+
$_REQUEST['page_number'] = '0';
68+
$_REQUEST['eps_orientation'] = 'L';
69+
70+
$actual = (new SchemaEps())->getExportInfo(DatabaseName::from('test_db'));
71+
72+
self::assertSame('test_db.eps', $actual['fileName']);
73+
self::assertSame('image/x-eps', $actual['mediaType']);
74+
self::assertStringStartsWith('%!PS-Adobe-3.0 EPSF-3.0', $actual['fileData']);
75+
}
76+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\SchemaSvg;
9+
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
10+
use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;
11+
use PhpMyAdmin\Tests\AbstractTestCase;
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
14+
#[CoversClass(SchemaSvg::class)]
15+
final class SchemaSvgTest extends AbstractTestCase
16+
{
17+
public function testGetName(): void
18+
{
19+
self::assertSame('svg', (new SchemaSvg())->getName());
20+
}
21+
22+
public function testSetProperties(): void
23+
{
24+
$properties = (new SchemaSvg())->getProperties();
25+
self::assertSame('SVG', $properties->getText());
26+
self::assertSame('svg', $properties->getExtension());
27+
self::assertSame('application/svg', $properties->getMimeType());
28+
$options = $properties->getOptions();
29+
self::assertNotNull($options);
30+
self::assertSame('Format Specific Options', $options->getName());
31+
$specificOptions = $options->getProperties();
32+
self::assertCount(1, $specificOptions);
33+
$specificOption = $specificOptions->current();
34+
self::assertInstanceOf(OptionsPropertyMainGroup::class, $specificOption);
35+
self::assertSame('general_opts', $specificOption->getName());
36+
self::assertCount(3, $specificOption);
37+
$specificOptionProperties = $specificOption->getProperties();
38+
39+
$specificOptionProperty = $specificOptionProperties->current();
40+
self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty);
41+
self::assertSame('show_color', $specificOptionProperty->getName());
42+
self::assertSame('Show color', $specificOptionProperty->getText());
43+
44+
$specificOptionProperties->next();
45+
$specificOptionProperty = $specificOptionProperties->current();
46+
self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty);
47+
self::assertSame('show_keys', $specificOptionProperty->getName());
48+
self::assertSame('Only show keys', $specificOptionProperty->getText());
49+
50+
$specificOptionProperties->next();
51+
$specificOptionProperty = $specificOptionProperties->current();
52+
self::assertInstanceOf(BoolPropertyItem::class, $specificOptionProperty);
53+
self::assertSame('all_tables_same_width', $specificOptionProperty->getName());
54+
self::assertSame('Same width for all tables', $specificOptionProperty->getText());
55+
}
56+
57+
public function testGetExportInfo(): void
58+
{
59+
$_REQUEST['page_number'] = '0';
60+
61+
$actual = (new SchemaSvg())->getExportInfo(DatabaseName::from('test_db'));
62+
63+
self::assertSame('test_db.svg', $actual['fileName']);
64+
self::assertSame('image/svg+xml', $actual['mediaType']);
65+
self::assertStringStartsWith('<?xml version="1.0" encoding="UTF-8"?>', $actual['fileData']);
66+
}
67+
}

0 commit comments

Comments
 (0)