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