Visitar URL original
Add unit tests for `Table\ChangeRowsController` · phpmyadmin/phpmyadmin@5bc129d · GitHub
Skip to content

Commit 5bc129d

Browse files
committed
Add unit tests for Table\ChangeRowsController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 7aec652 commit 5bc129d

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table;
6+
7+
use PhpMyAdmin\Controllers\Table\ChangeController;
8+
use PhpMyAdmin\Controllers\Table\ChangeRowsController;
9+
use PhpMyAdmin\Template;
10+
use PhpMyAdmin\Tests\AbstractTestCase;
11+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
12+
13+
/**
14+
* @covers \PhpMyAdmin\Controllers\Table\ChangeRowsController
15+
*/
16+
class ChangeRowsControllerTest extends AbstractTestCase
17+
{
18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
$GLOBALS['server'] = 2;
22+
$GLOBALS['active_page'] = null;
23+
$GLOBALS['where_clause'] = null;
24+
$_POST = [];
25+
}
26+
27+
public function testChangeRowsController(): void
28+
{
29+
$_POST['rows_to_delete'] = 'row';
30+
31+
$mock = $this->createMock(ChangeController::class);
32+
$mock->expects($this->once())->method('__invoke');
33+
34+
(new ChangeRowsController(new ResponseRenderer(), new Template(), $mock))();
35+
36+
/** @psalm-suppress InvalidArrayOffset */
37+
$this->assertSame('index.php?route=/table/change&server=2&lang=en', $GLOBALS['active_page']);
38+
/** @psalm-suppress InvalidArrayOffset */
39+
$this->assertSame([], $GLOBALS['where_clause']);
40+
}
41+
42+
public function testWithoutRowsToDelete(): void
43+
{
44+
$_POST['goto'] = 'goto';
45+
46+
$mock = $this->createMock(ChangeController::class);
47+
$mock->expects($this->never())->method('__invoke');
48+
49+
$response = new ResponseRenderer();
50+
(new ChangeRowsController($response, new Template(), $mock))();
51+
52+
$this->assertSame(['message' => 'No row selected.'], $response->getJSONResult());
53+
$this->assertFalse($response->hasSuccessState());
54+
/** @psalm-suppress InvalidArrayOffset */
55+
$this->assertNull($GLOBALS['active_page']);
56+
/** @psalm-suppress InvalidArrayOffset */
57+
$this->assertNull($GLOBALS['where_clause']);
58+
}
59+
60+
public function testWithRowsToDelete(): void
61+
{
62+
$_POST['goto'] = 'goto';
63+
$_POST['rows_to_delete'] = ['key1' => 'row1', 'key2' => 'row2'];
64+
65+
$mock = $this->createMock(ChangeController::class);
66+
$mock->expects($this->once())->method('__invoke');
67+
68+
(new ChangeRowsController(new ResponseRenderer(), new Template(), $mock))();
69+
70+
/** @psalm-suppress InvalidArrayOffset */
71+
$this->assertSame('index.php?route=/table/change&server=2&lang=en', $GLOBALS['active_page']);
72+
/** @psalm-suppress InvalidArrayOffset */
73+
$this->assertSame(['row1', 'row2'], $GLOBALS['where_clause']);
74+
}
75+
}

0 commit comments

Comments
 (0)