1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Setup;
use PhpMyAdmin\Config\FormDisplay;
use PhpMyAdmin\Setup\FormProcessing;
use PhpMyAdmin\Tests\AbstractNetworkTestCase;
use function ob_get_clean;
use function ob_start;
/**
* @covers \PhpMyAdmin\Setup\FormProcessing
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Setup\FormProcessing::class)]
class FormProcessingTest extends AbstractNetworkTestCase
{
/**
* Prepares environment for the test.
*/
protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
$GLOBALS['server'] = 1;
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$GLOBALS['cfg']['ServerDefault'] = 1;
}
/**
* Test for process_formset()
*
* @requires PHPUnit < 10
*/
#[\PHPUnit\Framework\Attributes\RequiresPhpunit('< 10')]
public function testProcessFormSet(): void
{
$this->mockResponse(
[
['status: 303 See Other'],
['Location: index.php?lang=en'],
303,
]
);
// case 1
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'getDisplay'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->willReturn(false);
$formDisplay->expects($this->once())
->method('getDisplay');
FormProcessing::process($formDisplay);
// case 2
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'hasErrors', 'displayErrors'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->willReturn(true);
$formDisplay->expects($this->once())
->method('hasErrors')
->with()
->willReturn(true);
ob_start();
FormProcessing::process($formDisplay);
$result = ob_get_clean();
self::assertIsString($result);
self::assertStringContainsString('<div class="error">', $result);
self::assertStringContainsString('mode=revert', $result);
self::assertStringContainsString('<a class="btn" href="index.php?', $result);
self::assertStringContainsString('mode=edit', $result);
// case 3
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'hasErrors'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->willReturn(true);
$formDisplay->expects($this->once())
->method('hasErrors')
->with()
->willReturn(false);
FormProcessing::process($formDisplay);
}
}
|