|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
|
4
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Joomla\Form\Tests; |
|
8
|
|
|
|
|
9
|
|
|
use Joomla\Test\TestHelper; |
|
10
|
|
|
use Joomla\Form\Field_Spacer; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Test class for JForm. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
class JFormFieldSpacerTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Sets up dependancies for the test. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
// The real class cannot be autoloaded |
|
27
|
|
|
\Joomla\Form\FormHelper::loadFieldClass('spacer'); |
|
28
|
|
|
|
|
29
|
|
|
parent::setUp(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Test the getInput method. |
|
34
|
|
|
* |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testGetInput() |
|
38
|
|
|
{ |
|
39
|
|
|
$form = new JFormInspector('form1'); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertThat( |
|
42
|
|
|
$form->load('<form><field name="spacer" type="spacer" /></form>'), |
|
43
|
|
|
$this->isTrue(), |
|
44
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
/** @var Field_Spacer $field */ |
|
48
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('spacer'); |
|
|
|
|
|
|
49
|
|
|
$field->setForm($form); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertThat( |
|
52
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
53
|
|
|
$this->isTrue(), |
|
54
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertThat( |
|
58
|
|
|
strlen($field->input), |
|
|
|
|
|
|
59
|
|
|
$this->greaterThan(0), |
|
60
|
|
|
'Line:' . __LINE__ . ' The getInput method should return something without error.' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Test the getLabel method. |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testGetLabel() |
|
70
|
|
|
{ |
|
71
|
|
|
$form = new JFormInspector('form1'); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertThat( |
|
74
|
|
|
$form->load('<form><field name="spacer" type="spacer" description="spacer" /></form>'), |
|
75
|
|
|
$this->isTrue(), |
|
76
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
/** @var Field_Spacer $field */ |
|
80
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('spacer'); |
|
|
|
|
|
|
81
|
|
|
$field->setForm($form); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertThat( |
|
84
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
85
|
|
|
$this->isTrue(), |
|
86
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$equals = '<span class="spacer"><span class="before"></span><span class="">' . |
|
90
|
|
|
'<label id="spacer-lbl" class="hasTip" title="spacer::spacer">spacer</label></span>' . |
|
91
|
|
|
'<span class="after"></span></span>'; |
|
92
|
|
|
|
|
93
|
|
|
$this->assertEquals( |
|
94
|
|
|
$field->label, |
|
|
|
|
|
|
95
|
|
|
$equals, |
|
96
|
|
|
'Line:' . __LINE__ . ' The getLabel method should return something without error.' |
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertThat( |
|
100
|
|
|
$form->load('<form><field name="spacer" type="spacer" class="text" /></form>'), |
|
101
|
|
|
$this->isTrue(), |
|
102
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
/** @var Field_Spacer $field */ |
|
106
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('spacer'); |
|
|
|
|
|
|
107
|
|
|
$field->setForm($form); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertThat( |
|
110
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
111
|
|
|
$this->isTrue(), |
|
112
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
$equals = '<span class="spacer"><span class="before"></span><span class="text">' . |
|
116
|
|
|
'<label id="spacer-lbl" class="">spacer</label></span><span class="after"></span></span>'; |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals( |
|
119
|
|
|
$field->label, |
|
|
|
|
|
|
120
|
|
|
$equals, |
|
121
|
|
|
'Line:' . __LINE__ . ' The getLabel method should return something without error.' |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertThat( |
|
125
|
|
|
$form->load('<form><field name="spacer" type="spacer" class="text" label="MyLabel" /></form>'), |
|
126
|
|
|
$this->isTrue(), |
|
127
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
|
|
$field = new Field_Spacer($form); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
$this->assertThat( |
|
133
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
134
|
|
|
$this->isTrue(), |
|
135
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
136
|
|
|
); |
|
137
|
|
|
|
|
138
|
|
|
$equals = '<span class="spacer"><span class="before"></span><span class="text">' . |
|
139
|
|
|
'<label id="spacer-lbl" class="">MyLabel</label></span><span class="after"></span></span>'; |
|
140
|
|
|
|
|
141
|
|
|
$this->assertEquals( |
|
142
|
|
|
$field->label, |
|
|
|
|
|
|
143
|
|
|
$equals, |
|
144
|
|
|
'Line:' . __LINE__ . ' The getLabel method should return something without error.' |
|
145
|
|
|
); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertThat( |
|
148
|
|
|
$form->load('<form><field name="spacer" type="spacer" hr="true" /></form>'), |
|
149
|
|
|
$this->isTrue(), |
|
150
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
151
|
|
|
); |
|
152
|
|
|
|
|
153
|
|
|
$field = new Field_Spacer($form); |
|
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
$this->assertThat( |
|
156
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
157
|
|
|
$this->isTrue(), |
|
158
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
159
|
|
|
); |
|
160
|
|
|
|
|
161
|
|
|
$expected = '<span class="spacer"><span class="before"></span><span class=""><hr class="" /></span>' . |
|
162
|
|
|
'<span class="after"></span></span>'; |
|
163
|
|
|
|
|
164
|
|
|
$this->assertEquals( |
|
165
|
|
|
$field->label, |
|
|
|
|
|
|
166
|
|
|
$expected, |
|
167
|
|
|
'Line:' . __LINE__ . ' The getLabel method should return something without error.' |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Test the getTitle method. |
|
173
|
|
|
* |
|
174
|
|
|
* @return void |
|
175
|
|
|
*/ |
|
176
|
|
|
public function testGetTitle() |
|
177
|
|
|
{ |
|
178
|
|
|
$this->testGetLabel(); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.