diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-07-27 21:29:02 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-07-27 21:29:02 +0300 |
commit | b0c4426a43e82decacf60cbd14f8b318482add69 (patch) | |
tree | 290888ec2c83413f1e5da4c483f7d594388f5538 /test | |
parent | c6c28498e46f197597025485cb8318a2e02438cb (diff) |
Add basic tests for Controllers\Table\Partition classes
Adds better message for invalid partition name.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
7 files changed, 364 insertions, 0 deletions
diff --git a/test/classes/Controllers/Table/Partition/AnalyzeControllerTest.php b/test/classes/Controllers/Table/Partition/AnalyzeControllerTest.php new file mode 100644 index 0000000000..46eb3bbb63 --- /dev/null +++ b/test/classes/Controllers/Table/Partition/AnalyzeControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\AnalyzeController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\AnalyzeController + */ +class AnalyzeControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new AnalyzeController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/CheckControllerTest.php b/test/classes/Controllers/Table/Partition/CheckControllerTest.php new file mode 100644 index 0000000000..c2e0d4699d --- /dev/null +++ b/test/classes/Controllers/Table/Partition/CheckControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\CheckController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\CheckController + */ +class CheckControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new CheckController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/DropControllerTest.php b/test/classes/Controllers/Table/Partition/DropControllerTest.php new file mode 100644 index 0000000000..45d4107c8e --- /dev/null +++ b/test/classes/Controllers/Table/Partition/DropControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\DropController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\DropController + */ +class DropControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new DropController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/OptimizeControllerTest.php b/test/classes/Controllers/Table/Partition/OptimizeControllerTest.php new file mode 100644 index 0000000000..67be53c1d2 --- /dev/null +++ b/test/classes/Controllers/Table/Partition/OptimizeControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\OptimizeController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\OptimizeController + */ +class OptimizeControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new OptimizeController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/RebuildControllerTest.php b/test/classes/Controllers/Table/Partition/RebuildControllerTest.php new file mode 100644 index 0000000000..f56fdad93d --- /dev/null +++ b/test/classes/Controllers/Table/Partition/RebuildControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\RebuildController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\RebuildController + */ +class RebuildControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new RebuildController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/RepairControllerTest.php b/test/classes/Controllers/Table/Partition/RepairControllerTest.php new file mode 100644 index 0000000000..583b6c26b5 --- /dev/null +++ b/test/classes/Controllers/Table/Partition/RepairControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\RepairController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\RepairController + */ +class RepairControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new RepairController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} diff --git a/test/classes/Controllers/Table/Partition/TruncateControllerTest.php b/test/classes/Controllers/Table/Partition/TruncateControllerTest.php new file mode 100644 index 0000000000..7ba59de054 --- /dev/null +++ b/test/classes/Controllers/Table/Partition/TruncateControllerTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\Partition\TruncateController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Table\Partition\TruncateController + */ +class TruncateControllerTest extends AbstractTestCase +{ + /** + * @dataProvider providerForTestInvalidDatabaseAndTable + */ + public function testInvalidDatabaseAndTable(?string $partition, ?string $db, ?string $table, string $message): void + { + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]); + $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]); + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + + $controller = new TruncateController($response, new Template(), new Maintenance($dbi)); + $controller($request); + + $this->assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult()); + } + + /** + * @return array<int, array{string|null, string|null, string|null, non-empty-string}> + */ + public function providerForTestInvalidDatabaseAndTable(): iterable + { + return [ + [null, null, null, 'The partition name must be a non-empty string.'], + ['', null, null, 'The partition name must be a non-empty string.'], + ['partitionName', null, null, 'The database name must be a non-empty string.'], + ['partitionName', '', null, 'The database name must be a non-empty string.'], + ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'], + ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'], + ]; + } +} |