Skip to content

Commit c6c2849

Browse files
committed
Add basic tests for Controllers\Table\Maintenance classes
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 01cf9ce commit c6c2849

5 files changed

Lines changed: 270 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
6+
7+
use PhpMyAdmin\Config;
8+
use PhpMyAdmin\Controllers\Table\Maintenance\AnalyzeController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
use PhpMyAdmin\Table\Maintenance;
11+
use PhpMyAdmin\Template;
12+
use PhpMyAdmin\Tests\AbstractTestCase;
13+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\Maintenance\AnalyzeController
17+
*/
18+
class AnalyzeControllerTest extends AbstractTestCase
19+
{
20+
/**
21+
* @param string[][]|string[]|string|null $tables
22+
*
23+
* @dataProvider providerForTestNoTableSelected
24+
*/
25+
public function testNoTableSelected($tables): void
26+
{
27+
$request = $this->createStub(ServerRequest::class);
28+
$request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
29+
$dbi = $this->createDatabaseInterface();
30+
$GLOBALS['dbi'] = $dbi;
31+
$response = new ResponseRenderer();
32+
$controller = new AnalyzeController($response, new Template(), new Maintenance($dbi), new Config());
33+
$controller($request);
34+
$this->assertFalse($response->hasSuccessState());
35+
$this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
36+
$this->assertSame('', $response->getHTMLResult());
37+
}
38+
39+
/**
40+
* @return array<int, array{string[][]|string[]|string|null}>
41+
*/
42+
public function providerForTestNoTableSelected(): array
43+
{
44+
return [
45+
[null],
46+
[''],
47+
['table'],
48+
[[]],
49+
[['']],
50+
[['table', '']],
51+
[[['table']]],
52+
];
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
6+
7+
use PhpMyAdmin\Config;
8+
use PhpMyAdmin\Controllers\Table\Maintenance\CheckController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
use PhpMyAdmin\Table\Maintenance;
11+
use PhpMyAdmin\Template;
12+
use PhpMyAdmin\Tests\AbstractTestCase;
13+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\Maintenance\CheckController
17+
*/
18+
class CheckControllerTest extends AbstractTestCase
19+
{
20+
/**
21+
* @param string[][]|string[]|string|null $tables
22+
*
23+
* @dataProvider providerForTestNoTableSelected
24+
*/
25+
public function testNoTableSelected($tables): void
26+
{
27+
$request = $this->createStub(ServerRequest::class);
28+
$request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
29+
$dbi = $this->createDatabaseInterface();
30+
$GLOBALS['dbi'] = $dbi;
31+
$response = new ResponseRenderer();
32+
$controller = new CheckController($response, new Template(), new Maintenance($dbi), new Config());
33+
$controller($request);
34+
$this->assertFalse($response->hasSuccessState());
35+
$this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
36+
$this->assertSame('', $response->getHTMLResult());
37+
}
38+
39+
/**
40+
* @return array<int, array{string[][]|string[]|string|null}>
41+
*/
42+
public function providerForTestNoTableSelected(): array
43+
{
44+
return [
45+
[null],
46+
[''],
47+
['table'],
48+
[[]],
49+
[['']],
50+
[['table', '']],
51+
[[['table']]],
52+
];
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
6+
7+
use PhpMyAdmin\Config;
8+
use PhpMyAdmin\Controllers\Table\Maintenance\ChecksumController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
use PhpMyAdmin\Table\Maintenance;
11+
use PhpMyAdmin\Template;
12+
use PhpMyAdmin\Tests\AbstractTestCase;
13+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\Maintenance\ChecksumController
17+
*/
18+
class ChecksumControllerTest extends AbstractTestCase
19+
{
20+
/**
21+
* @param string[][]|string[]|string|null $tables
22+
*
23+
* @dataProvider providerForTestNoTableSelected
24+
*/
25+
public function testNoTableSelected($tables): void
26+
{
27+
$request = $this->createStub(ServerRequest::class);
28+
$request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
29+
$dbi = $this->createDatabaseInterface();
30+
$GLOBALS['dbi'] = $dbi;
31+
$response = new ResponseRenderer();
32+
$controller = new ChecksumController($response, new Template(), new Maintenance($dbi), new Config());
33+
$controller($request);
34+
$this->assertFalse($response->hasSuccessState());
35+
$this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
36+
$this->assertSame('', $response->getHTMLResult());
37+
}
38+
39+
/**
40+
* @return array<int, array{string[][]|string[]|string|null}>
41+
*/
42+
public function providerForTestNoTableSelected(): array
43+
{
44+
return [
45+
[null],
46+
[''],
47+
['table'],
48+
[[]],
49+
[['']],
50+
[['table', '']],
51+
[[['table']]],
52+
];
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
6+
7+
use PhpMyAdmin\Config;
8+
use PhpMyAdmin\Controllers\Table\Maintenance\OptimizeController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
use PhpMyAdmin\Table\Maintenance;
11+
use PhpMyAdmin\Template;
12+
use PhpMyAdmin\Tests\AbstractTestCase;
13+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\Maintenance\OptimizeController
17+
*/
18+
class OptimizeControllerTest extends AbstractTestCase
19+
{
20+
/**
21+
* @param string[][]|string[]|string|null $tables
22+
*
23+
* @dataProvider providerForTestNoTableSelected
24+
*/
25+
public function testNoTableSelected($tables): void
26+
{
27+
$request = $this->createStub(ServerRequest::class);
28+
$request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
29+
$dbi = $this->createDatabaseInterface();
30+
$GLOBALS['dbi'] = $dbi;
31+
$response = new ResponseRenderer();
32+
$controller = new OptimizeController($response, new Template(), new Maintenance($dbi), new Config());
33+
$controller($request);
34+
$this->assertFalse($response->hasSuccessState());
35+
$this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
36+
$this->assertSame('', $response->getHTMLResult());
37+
}
38+
39+
/**
40+
* @return array<int, array{string[][]|string[]|string|null}>
41+
*/
42+
public function providerForTestNoTableSelected(): array
43+
{
44+
return [
45+
[null],
46+
[''],
47+
['table'],
48+
[[]],
49+
[['']],
50+
[['table', '']],
51+
[[['table']]],
52+
];
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table\Maintenance;
6+
7+
use PhpMyAdmin\Config;
8+
use PhpMyAdmin\Controllers\Table\Maintenance\RepairController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
use PhpMyAdmin\Table\Maintenance;
11+
use PhpMyAdmin\Template;
12+
use PhpMyAdmin\Tests\AbstractTestCase;
13+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\Maintenance\RepairController
17+
*/
18+
class RepairControllerTest extends AbstractTestCase
19+
{
20+
/**
21+
* @param string[][]|string[]|string|null $tables
22+
*
23+
* @dataProvider providerForTestNoTableSelected
24+
*/
25+
public function testNoTableSelected($tables): void
26+
{
27+
$request = $this->createStub(ServerRequest::class);
28+
$request->method('getParsedBodyParam')->willReturnMap([['selected_tbl', null, $tables]]);
29+
$dbi = $this->createDatabaseInterface();
30+
$GLOBALS['dbi'] = $dbi;
31+
$response = new ResponseRenderer();
32+
$controller = new RepairController($response, new Template(), new Maintenance($dbi), new Config());
33+
$controller($request);
34+
$this->assertFalse($response->hasSuccessState());
35+
$this->assertSame(['message' => 'No table selected.'], $response->getJSONResult());
36+
$this->assertSame('', $response->getHTMLResult());
37+
}
38+
39+
/**
40+
* @return array<int, array{string[][]|string[]|string|null}>
41+
*/
42+
public function providerForTestNoTableSelected(): array
43+
{
44+
return [
45+
[null],
46+
[''],
47+
['table'],
48+
[[]],
49+
[['']],
50+
[['table', '']],
51+
[[['table']]],
52+
];
53+
}
54+
}

0 commit comments

Comments
 (0)