phpmyadmin/test/classes/Setup/FormProcessingTest.php
Kamil Tekiela 276577ca2a
Remove $GLOBALS['PMA_PHP_SELF'] (#18149)
* Remove $GLOBALS['PMA_PHP_SELF']

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove $GLOBALS['PMA_PHP_SELF'] from tests

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Moved cleanupPathInfo to Routing

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove parse_url from getRootPath

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update baselines

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove invalid tests

Surely, we never expect PATH to be backslash delimited. The code is not designed to handle this and the tests for this don't make much sense.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Fix trailing slash in path

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

---------

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2023-02-27 17:56:27 -03:00

110 lines
2.9 KiB
PHP

<?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 */
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['cfg']['ServerDefault'] = 1;
}
/**
* Test for process_formset()
*/
public function testProcessFormSet(): void
{
$this->mockResponse(
[
['status: 303 See Other'],
['Location: ../setup/index.php?route=%2Fsetup&lang=en'],
303,
],
);
// case 1
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'getDisplay'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->will($this->returnValue(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)
->will($this->returnValue(true));
$formDisplay->expects($this->once())
->method('hasErrors')
->with()
->will($this->returnValue(true));
ob_start();
FormProcessing::process($formDisplay);
$result = ob_get_clean();
$this->assertIsString($result);
$this->assertStringContainsString('<div class="error">', $result);
$this->assertStringContainsString('mode=revert', $result);
$this->assertStringContainsString('<a class="btn" href="../setup/index.php?route=/setup&', $result);
$this->assertStringContainsString('mode=edit', $result);
// case 3
$formDisplay = $this->getMockBuilder(FormDisplay::class)
->disableOriginalConstructor()
->onlyMethods(['process', 'hasErrors'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->will($this->returnValue(true));
$formDisplay->expects($this->once())
->method('hasErrors')
->with()
->will($this->returnValue(false));
FormProcessing::process($formDisplay);
}
}