Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-27 02:55:36 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-27 02:55:36 +0300
commitc6c28498e46f197597025485cb8318a2e02438cb (patch)
tree52590f0743549937c2ce8952409aa389f6cccebc /test
parent01cf9ce82e904d363a8f40c939328821296388ce (diff)
Add basic tests for Controllers\Table\Maintenance classes
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Controllers/Table/Maintenance/AnalyzeControllerTest.php54
-rw-r--r--test/classes/Controllers/Table/Maintenance/CheckControllerTest.php54
-rw-r--r--test/classes/Controllers/Table/Maintenance/ChecksumControllerTest.php54
-rw-r--r--test/classes/Controllers/Table/Maintenance/OptimizeControllerTest.php54
-rw-r--r--test/classes/Controllers/Table/Maintenance/RepairControllerTest.php54
5 files changed, 270 insertions, 0 deletions
diff --git a/test/classes/Controllers/Table/Maintenance/AnalyzeControllerTest.php b/test/classes/Controllers/Table/Maintenance/AnalyzeControllerTest.php
new file mode 100644
index 0000000000..37f817404a
--- /dev/null
+++ b/test/classes/Controllers/Table/Maintenance/AnalyzeControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
+
+use PhpMyAdmin\Config;
+use PhpMyAdmin\Controllers\Table\Maintenance\AnalyzeController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Table\Maintenance;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Maintenance\AnalyzeController
+ */
+class AnalyzeControllerTest extends AbstractTestCase
+{
+ /**
+ * @param string[][]|string[]|string|null $tables
+ *
+ * @dataProvider providerForTestNoTableSelected
+ */
+ public function testNoTableSelected($tables): void
+ {
+ $request = $this->createStub(ServerRequest::class);
+ $request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
+ $dbi = $this->createDatabaseInterface();
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $controller = new AnalyzeController($response, new Template(), new Maintenance($dbi), new Config());
+ $controller($request);
+ $this->assertFalse($response->hasSuccessState());
+ $this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
+ $this->assertSame('', $response->getHTMLResult());
+ }
+
+ /**
+ * @return array<int, array{string[][]|string[]|string|null}>
+ */
+ public function providerForTestNoTableSelected(): array
+ {
+ return [
+ [null],
+ [''],
+ ['table'],
+ [[]],
+ [['']],
+ [['table', '']],
+ [[['table']]],
+ ];
+ }
+}
diff --git a/test/classes/Controllers/Table/Maintenance/CheckControllerTest.php b/test/classes/Controllers/Table/Maintenance/CheckControllerTest.php
new file mode 100644
index 0000000000..fd38a7db07
--- /dev/null
+++ b/test/classes/Controllers/Table/Maintenance/CheckControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
+
+use PhpMyAdmin\Config;
+use PhpMyAdmin\Controllers\Table\Maintenance\CheckController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Table\Maintenance;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Maintenance\CheckController
+ */
+class CheckControllerTest extends AbstractTestCase
+{
+ /**
+ * @param string[][]|string[]|string|null $tables
+ *
+ * @dataProvider providerForTestNoTableSelected
+ */
+ public function testNoTableSelected($tables): void
+ {
+ $request = $this->createStub(ServerRequest::class);
+ $request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
+ $dbi = $this->createDatabaseInterface();
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $controller = new CheckController($response, new Template(), new Maintenance($dbi), new Config());
+ $controller($request);
+ $this->assertFalse($response->hasSuccessState());
+ $this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
+ $this->assertSame('', $response->getHTMLResult());
+ }
+
+ /**
+ * @return array<int, array{string[][]|string[]|string|null}>
+ */
+ public function providerForTestNoTableSelected(): array
+ {
+ return [
+ [null],
+ [''],
+ ['table'],
+ [[]],
+ [['']],
+ [['table', '']],
+ [[['table']]],
+ ];
+ }
+}
diff --git a/test/classes/Controllers/Table/Maintenance/ChecksumControllerTest.php b/test/classes/Controllers/Table/Maintenance/ChecksumControllerTest.php
new file mode 100644
index 0000000000..f779d179e2
--- /dev/null
+++ b/test/classes/Controllers/Table/Maintenance/ChecksumControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
+
+use PhpMyAdmin\Config;
+use PhpMyAdmin\Controllers\Table\Maintenance\ChecksumController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Table\Maintenance;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Maintenance\ChecksumController
+ */
+class ChecksumControllerTest extends AbstractTestCase
+{
+ /**
+ * @param string[][]|string[]|string|null $tables
+ *
+ * @dataProvider providerForTestNoTableSelected
+ */
+ public function testNoTableSelected($tables): void
+ {
+ $request = $this->createStub(ServerRequest::class);
+ $request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
+ $dbi = $this->createDatabaseInterface();
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $controller = new ChecksumController($response, new Template(), new Maintenance($dbi), new Config());
+ $controller($request);
+ $this->assertFalse($response->hasSuccessState());
+ $this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
+ $this->assertSame('', $response->getHTMLResult());
+ }
+
+ /**
+ * @return array<int, array{string[][]|string[]|string|null}>
+ */
+ public function providerForTestNoTableSelected(): array
+ {
+ return [
+ [null],
+ [''],
+ ['table'],
+ [[]],
+ [['']],
+ [['table', '']],
+ [[['table']]],
+ ];
+ }
+}
diff --git a/test/classes/Controllers/Table/Maintenance/OptimizeControllerTest.php b/test/classes/Controllers/Table/Maintenance/OptimizeControllerTest.php
new file mode 100644
index 0000000000..09eb4473f9
--- /dev/null
+++ b/test/classes/Controllers/Table/Maintenance/OptimizeControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
+
+use PhpMyAdmin\Config;
+use PhpMyAdmin\Controllers\Table\Maintenance\OptimizeController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Table\Maintenance;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Maintenance\OptimizeController
+ */
+class OptimizeControllerTest extends AbstractTestCase
+{
+ /**
+ * @param string[][]|string[]|string|null $tables
+ *
+ * @dataProvider providerForTestNoTableSelected
+ */
+ public function testNoTableSelected($tables): void
+ {
+ $request = $this->createStub(ServerRequest::class);
+ $request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
+ $dbi = $this->createDatabaseInterface();
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $controller = new OptimizeController($response, new Template(), new Maintenance($dbi), new Config());
+ $controller($request);
+ $this->assertFalse($response->hasSuccessState());
+ $this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
+ $this->assertSame('', $response->getHTMLResult());
+ }
+
+ /**
+ * @return array<int, array{string[][]|string[]|string|null}>
+ */
+ public function providerForTestNoTableSelected(): array
+ {
+ return [
+ [null],
+ [''],
+ ['table'],
+ [[]],
+ [['']],
+ [['table', '']],
+ [[['table']]],
+ ];
+ }
+}
diff --git a/test/classes/Controllers/Table/Maintenance/RepairControllerTest.php b/test/classes/Controllers/Table/Maintenance/RepairControllerTest.php
new file mode 100644
index 0000000000..7ed1a0a3d4
--- /dev/null
+++ b/test/classes/Controllers/Table/Maintenance/RepairControllerTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
+
+use PhpMyAdmin\Config;
+use PhpMyAdmin\Controllers\Table\Maintenance\RepairController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Table\Maintenance;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Maintenance\RepairController
+ */
+class RepairControllerTest extends AbstractTestCase
+{
+ /**
+ * @param string[][]|string[]|string|null $tables
+ *
+ * @dataProvider providerForTestNoTableSelected
+ */
+ public function testNoTableSelected($tables): void
+ {
+ $request = $this->createStub(ServerRequest::class);
+ $request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
+ $dbi = $this->createDatabaseInterface();
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $controller = new RepairController($response, new Template(), new Maintenance($dbi), new Config());
+ $controller($request);
+ $this->assertFalse($response->hasSuccessState());
+ $this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
+ $this->assertSame('', $response->getHTMLResult());
+ }
+
+ /**
+ * @return array<int, array{string[][]|string[]|string|null}>
+ */
+ public function providerForTestNoTableSelected(): array
+ {
+ return [
+ [null],
+ [''],
+ ['table'],
+ [[]],
+ [['']],
+ [['table', '']],
+ [[['table']]],
+ ];
+ }
+}