blob: 548770f7aeac367616de4a8097732833885eb730 (
plain)
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
115
116
117
118
119
120
121
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for methods under Formset processing library
*
* @package PhpMyAdmin-test
*/
/*
* Include to test
*/
require_once 'setup/lib/form_processing.lib.php';
require_once 'libraries/config/ConfigFile.class.php';
require_once 'libraries/core.lib.php';
require_once 'libraries/Util.class.php';
/**
* tests for methods under Formset processing library
*
* @package PhpMyAdmin-test
*/
class PMA_From_Processing_Test extends PHPUnit_Framework_TestCase
{
/**
* Test for process_formset()
*
* @return void
*/
public function testProcessFormSet()
{
if (!defined('PMA_TEST_HEADERS')) {
$this->markTestSkipped(
'Cannot redefine constant/function - missing runkit extension'
);
}
// case 1
$formDisplay = $this->getMockBuilder('FormDisplay')
->disableOriginalConstructor()
->setMethods(array('process', 'getDisplay'))
->getMock();
$formDisplay->expects($this->once())
->method('process')
->with(false)
->will($this->returnValue(false));
$formDisplay->expects($this->once())
->method('getDisplay')
->with(true, true);
PMA_Process_formset($formDisplay);
// case 2
$formDisplay = $this->getMockBuilder('FormDisplay')
->disableOriginalConstructor()
->setMethods(array('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();
PMA_Process_formset($formDisplay);
$result = ob_get_clean();
$this->assertContains(
'<div class="error">',
$result
);
$this->assertContains(
'<a href="?lang=en&token=token&page=&mode=revert">',
$result
);
$this->assertContains(
'<a class="btn" href="index.php?lang=en&token=token">',
$result
);
$this->assertContains(
'<a class="btn" href="?lang=en&token=token&page=&mode=edit">',
$result
);
// case 3
$formDisplay = $this->getMockBuilder('FormDisplay')
->disableOriginalConstructor()
->setMethods(array('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));
PMA_Process_formset($formDisplay);
$this->assertEquals(
array('HTTP/1.1 303 See Other', 'Location: index.php?lang=en&token=token'),
$GLOBALS['header']
);
}
}
|