forked from joomla/joomla-platform
/
JFormFieldGroupedListTest.php
143 lines (131 loc) · 3.49 KB
/
JFormFieldGroupedListTest.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* @package Joomla.UnitTest
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
/**
* Test class for JFormFieldGroupedList.
*
* @package Joomla.UnitTest
* @subpackage Form
* @since 12.1
*/
class JFormFieldGroupedListTest extends TestCase
{
/**
* Sets up dependencies for the test.
*
* @return void
*
* @since 12.1
*/
protected function setUp()
{
require_once JPATH_PLATFORM . '/joomla/form/fields/groupedlist.php';
include_once dirname(__DIR__) . '/inspectors.php';
}
/**
* Test the getInput method.
*
* @return void
*
* @since 12.1
*/
public function testGetInput()
{
$form = new JFormInspector('form1');
$this->assertThat(
$form->load('<form><field name="groupedlist" type="groupedlist" /></form>'),
$this->isTrue(),
'Line:'.__LINE__.' XML string should load successfully.'
);
$field = new JFormFieldGroupedList($form);
$this->assertThat(
$field->setup($form->getXml()->field, 'value'),
$this->isTrue(),
'Line:'.__LINE__.' The setup method should return true.'
);
$this->assertThat(
strlen($field->input),
$this->greaterThan(0),
'Line:'.__LINE__.' The getInput method should return something without error.'
);
// TODO: Should check all the attributes have come in properly.
}
/**
* Data provider for testGetDefaultPreset
*
* @since 12.2
*/
public function caseGetDefaultPreset()
{
// $attributes, $options, $default, $preset
return array(
array(
'',
'<option value="1">1</option><option value="2">2</option><group name="Group"><option value="3">3</option></group>',
'',
''
),
array(
'default="1"',
'<option value="1">1</option><option value="2">2</option><group name="Group"><option value="3">3</option></group>',
'1',
'1'
),
array(
'preset="1"',
'<option value="1">1</option><option value="2">2</option><group name="Group"><option value="3">3</option></group>',
'',
'1'
),
array(
'preset="1" default="2"',
'<option value="1">1</option><option value="2">2</option><group name="Group"><option value="3">3</option></group>',
'2',
'1'
),
array(
'multiple="true"',
'<option value="1">1</option><option value="2">2</option><group name="Group"><option value="3">3</option></group>',
array(),
array()
),
array(
'multiple="true"',
'<option value="1" selected="true">1</option><option value="2" selected="true" default="true">2</option><group name="Group"><option value="3" default="true">3</option></group>',
array(2, 3),
array(1, 2)
),
);
}
/**
* Test the getDefault and getPreset method.
*
* @dataProvider caseGetDefaultPreset
*
* @since 12.2
*/
public function testGetDefaultPreset($attributes, $options, $default, $preset)
{
$form = new JFormInspector('form1');
$this->assertThat(
$form->load('<form><field name="groupedlist" type="groupedlist" ' . $attributes . ' >' . $options . '</field></form>'),
$this->isTrue(),
'Line:'.__LINE__.' XML string should load successfully.'
);
$this->assertThat(
$form->getField('groupedlist')->default,
$this->equalTo($default),
'Line:'.__LINE__.' The getDefault method should return correct default.'
);
$this->assertThat(
$form->getField('groupedlist')->preset,
$this->equalTo($preset),
'Line:'.__LINE__.' The getDefault method should return correct preset.'
);
}
}