Skip to content

Commit 228696e

Browse files
committed
Merge #20004 - Add integration tests for export plugin structure methods
Pull-request: #20004 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents cd1b3ad + 80b2e5c commit 228696e

5 files changed

Lines changed: 114 additions & 0 deletions

File tree

phpstan-baseline.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16644,6 +16644,12 @@ parameters:
1664416644
count: 1
1664516645
path: tests/unit/Plugins/Export/ExportHtmlwordTest.php
1664616646

16647+
-
16648+
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, string\|false given\.$#'
16649+
identifier: argument.type
16650+
count: 1
16651+
path: tests/unit/Plugins/Export/ExportHtmlwordTest.php
16652+
1664716653
-
1664816654
message: '''
1664916655
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
@@ -16653,6 +16659,12 @@ parameters:
1665316659
count: 3
1665416660
path: tests/unit/Plugins/Export/ExportLatexTest.php
1665516661

16662+
-
16663+
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, string\|false given\.$#'
16664+
identifier: argument.type
16665+
count: 3
16666+
path: tests/unit/Plugins/Export/ExportLatexTest.php
16667+
1665616668
-
1665716669
message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: 80, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#'
1665816670
identifier: assign.propertyType

tests/unit/Plugins/Export/ExportHtmlwordTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpMyAdmin\ConfigStorage\RelationParameters;
1111
use PhpMyAdmin\Current;
1212
use PhpMyAdmin\Dbal\DatabaseInterface;
13+
use PhpMyAdmin\Export\Export;
1314
use PhpMyAdmin\Export\OutputHandler;
1415
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1516
use PhpMyAdmin\Identifiers\TableName;
@@ -687,4 +688,28 @@ public function testFormatOneColumnDefinition(): void
687688
$method->invoke($this->object, $column, $uniqueKeys),
688689
);
689690
}
691+
692+
public function testExportTableCallsExportStructureMethod(): void
693+
{
694+
$dbi = $this->getMockBuilder(DatabaseInterface::class)
695+
->disableOriginalConstructor()
696+
->getMock();
697+
DatabaseInterface::$instance = $dbi;
698+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/');
699+
$this->object->setExportOptions($request, ['htmlword_structure_or_data' => 'structure']);
700+
$export = new Export($dbi, new OutputHandler());
701+
ob_start();
702+
$export->exportTable(
703+
'test_db',
704+
'test_table',
705+
$this->object,
706+
null,
707+
'',
708+
'',
709+
'',
710+
[],
711+
);
712+
$output = ob_get_clean();
713+
self::assertStringContainsString('<h2>Table structure for table test_table</h2>', $output);
714+
}
690715
}

tests/unit/Plugins/Export/ExportLatexTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpMyAdmin\ConfigStorage\RelationParameters;
1111
use PhpMyAdmin\Current;
1212
use PhpMyAdmin\Dbal\DatabaseInterface;
13+
use PhpMyAdmin\Export\Export;
1314
use PhpMyAdmin\Export\OutputHandler;
1415
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1516
use PhpMyAdmin\Plugins\Export\ExportLatex;
@@ -794,4 +795,30 @@ public static function providerForGetTranslatedText(): iterable
794795
],
795796
];
796797
}
798+
799+
public function testExportTableCallsExportStructureMethod(): void
800+
{
801+
$dbi = $this->getMockBuilder(DatabaseInterface::class)
802+
->disableOriginalConstructor()
803+
->getMock();
804+
DatabaseInterface::$instance = $dbi;
805+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/');
806+
$this->object->setExportOptions($request, ['latex_structure_or_data' => 'structure']);
807+
ob_start();
808+
$export = new Export($dbi, new OutputHandler());
809+
$export->exportTable(
810+
'testdb',
811+
'testtable',
812+
$this->object,
813+
null,
814+
'0',
815+
'0',
816+
'',
817+
[],
818+
);
819+
$output = ob_get_clean();
820+
self::assertStringContainsString("% Database: 'testdb'", $output);
821+
self::assertStringContainsString("%\n", $output);
822+
self::assertStringContainsString('% Structure: testtable', $output);
823+
}
797824
}

tests/unit/Plugins/Export/ExportMediawikiTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpMyAdmin\ConfigStorage\Relation;
99
use PhpMyAdmin\Current;
1010
use PhpMyAdmin\Dbal\DatabaseInterface;
11+
use PhpMyAdmin\Export\Export;
1112
use PhpMyAdmin\Export\OutputHandler;
1213
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1314
use PhpMyAdmin\Plugins\Export\ExportMediawiki;
@@ -319,4 +320,30 @@ public function testExportData(): void
319320
$result,
320321
);
321322
}
323+
324+
public function testExportTableCallsExportStructureMethod(): void
325+
{
326+
$dbi = $this->getMockBuilder(DatabaseInterface::class)
327+
->disableOriginalConstructor()
328+
->getMock();
329+
DatabaseInterface::$instance = $dbi;
330+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/');
331+
$this->object->setExportOptions($request, ['mediawiki_structure_or_data' => 'structure']);
332+
ob_start();
333+
$export = new Export($dbi, new OutputHandler());
334+
$export->exportTable(
335+
'testdb',
336+
'testtable',
337+
$this->object,
338+
null,
339+
'0',
340+
'0',
341+
'',
342+
[],
343+
);
344+
$result = ob_get_clean();
345+
self::assertIsString($result);
346+
self::assertStringContainsString('Table structure for', $result);
347+
self::assertStringContainsString('testtable', $result);
348+
}
322349
}

tests/unit/Plugins/Export/ExportOdtTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpMyAdmin\ConfigStorage\RelationParameters;
1111
use PhpMyAdmin\Dbal\ConnectionType;
1212
use PhpMyAdmin\Dbal\DatabaseInterface;
13+
use PhpMyAdmin\Export\Export;
1314
use PhpMyAdmin\Export\OutputHandler;
1415
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
1516
use PhpMyAdmin\Identifiers\TableName;
@@ -892,4 +893,26 @@ public function testFormatOneColumnDefinition(): void
892893
$method->invoke($this->object, $column, ''),
893894
);
894895
}
896+
897+
public function testExportTableCallsExportStructureMethod(): void
898+
{
899+
$dbi = $this->getMockBuilder(DatabaseInterface::class)
900+
->disableOriginalConstructor()
901+
->getMock();
902+
DatabaseInterface::$instance = $dbi;
903+
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/');
904+
$this->object->setExportOptions($request, ['odt_structure_or_data' => 'structure']);
905+
$export = new Export($dbi, new OutputHandler());
906+
$export->exportTable(
907+
'testdb',
908+
'testtable',
909+
$this->object,
910+
null,
911+
'0',
912+
'0',
913+
'',
914+
[],
915+
);
916+
self::assertStringContainsString('Table structure for table testtable', $this->object->buffer);
917+
}
895918
}

0 commit comments

Comments
 (0)