This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
/
JFormFieldListTest.php
134 lines (122 loc) · 3.14 KB
/
JFormFieldListTest.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
<?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 JForm.
*
* @package Joomla.UnitTest
* @subpackage Form
*/
class JFormFieldListTest extends TestCase
{
/**
* Sets up dependancies for the test.
*/
protected function setUp()
{
require_once JPATH_PLATFORM.'/joomla/form/fields/list.php';
include_once dirname(__DIR__).'/inspectors.php';
}
/**
* Test the getInput method.
*/
public function testGetInput()
{
$form = new JFormInspector('form1');
$this->assertThat(
$form->load('<form><field name="list" type="list" /></form>'),
$this->isTrue(),
'Line:'.__LINE__.' XML string should load successfully.'
);
$field = new JFormFieldList($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><option value="3">3</option>',
'',
''
),
array(
'default="1"',
'<option value="1">1</option><option value="2">2</option><option value="3">3</option>',
'1',
'1'
),
array(
'preset="1"',
'<option value="1">1</option><option value="2">2</option><option value="3">3</option>',
'',
'1'
),
array(
'preset="1" default="2"',
'<option value="1">1</option><option value="2">2</option><option value="3">3</option>',
'2',
'1'
),
array(
'multiple="true"',
'<option value="1">1</option><option value="2">2</option><option value="3">3</option>',
array(),
array()
),
array(
'multiple="true"',
'<option value="1" selected="true">1</option><option value="2" selected="true" default="true">2</option><option value="3" default="true">3</option>',
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="list" type="list" ' . $attributes . ' >' . $options . '</field></form>'),
$this->isTrue(),
'Line:'.__LINE__.' XML string should load successfully.'
);
$this->assertThat(
$form->getField('list')->default,
$this->equalTo($default),
'Line:'.__LINE__.' The getDefault method should return correct default.'
);
$this->assertThat(
$form->getField('list')->preset,
$this->equalTo($preset),
'Line:'.__LINE__.' The getDefault method should return correct preset.'
);
}
}