phpmyadmin/test/classes/Setup/FormProcessingTest.php
Maurício Meneghini Fauth 92cc67fbf7 Replace assertContains() with assertStringContainsString()
Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.
Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
2019-02-24 16:32:28 -03:00

127 lines
3.1 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for methods under Formset processing library
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Setup;
use PhpMyAdmin\Setup\FormProcessing;
use PhpMyAdmin\Tests\PmaTestCase;
/**
* tests for methods under Formset processing library
*
* @package PhpMyAdmin-test
*/
class FormProcessingTest extends PmaTestCase
{
/**
* Prepares environment for the test.
*
* @return void
*/
protected function setUp(): void
{
$GLOBALS['server'] = 1;
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$GLOBALS['cfg']['ServerDefault'] = 1;
}
/**
* Test for process_formset()
*
* @return void
*/
public function testProcessFormSet()
{
$this->mockResponse(
[
['status: 303 See Other'],
['Location: index.php?lang=en'],
303,
]
);
// case 1
$formDisplay = $this->getMockBuilder('PhpMyAdmin\Config\FormDisplay')
->disableOriginalConstructor()
->setMethods(['process', 'getDisplay'])
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->will($this->returnValue(false));
$formDisplay->expects($this->once())
->method('getDisplay')
->with(true, true);
FormProcessing::process($formDisplay);
// case 2
$formDisplay = $this->getMockBuilder('PhpMyAdmin\Config\FormDisplay')
->disableOriginalConstructor()
->setMethods(['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->assertStringContainsString(
'<div class="error">',
$result
);
$this->assertStringContainsString(
'mode=revert',
$result
);
$this->assertStringContainsString(
'<a class="btn" href="index.php?',
$result
);
$this->assertStringContainsString(
'mode=edit',
$result
);
// case 3
$formDisplay = $this->getMockBuilder('PhpMyAdmin\Config\FormDisplay')
->disableOriginalConstructor()
->setMethods(['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);
}
}