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_Hidden; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test class for JForm. |
14
|
|
|
* |
15
|
|
|
* @since 1.0 |
16
|
|
|
*/ |
17
|
|
|
class JFormFieldHiddenTest 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('hidden'); |
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
|
|
|
// Test a traditional hidden field type. |
42
|
|
|
|
43
|
|
|
$this->assertThat( |
44
|
|
|
$form->load('<form><field name="hidden" type="hidden" label="foo" /></form>'), |
45
|
|
|
$this->isTrue(), |
46
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
/** @var Field_Hidden $field */ |
50
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('hidden'); |
|
|
|
|
51
|
|
|
$field->setForm($form); |
52
|
|
|
|
53
|
|
|
$this->assertThat( |
54
|
|
|
$form->getLabel('hidden'), |
55
|
|
|
$this->equalTo(''), |
56
|
|
|
'Line:' . __LINE__ . ' The label of a hidden element should be nothing.' |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// Test a field with attribute hidden = true. |
60
|
|
|
|
61
|
|
|
$this->assertThat( |
62
|
|
|
$form->load('<form><field name="hidden" type="text" label="foo" hidden="true" /></form>'), |
63
|
|
|
$this->isTrue(), |
64
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
/** @var Field_Hidden $field */ |
68
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('hidden'); |
|
|
|
|
69
|
|
|
$field->setForm($form); |
70
|
|
|
|
71
|
|
|
$this->assertThat( |
72
|
|
|
$form->getLabel('hidden'), |
73
|
|
|
$this->equalTo(''), |
74
|
|
|
'Line:' . __LINE__ . ' The label of a hidden element should be nothing.' |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
// Test a field with attribute hidden = false. |
78
|
|
|
|
79
|
|
|
$this->assertThat( |
80
|
|
|
$form->load('<form><field name="hidden" type="text" label="foo" hidden="false" /></form>'), |
81
|
|
|
$this->isTrue(), |
82
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
/** @var Field_Hidden $field */ |
86
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('hidden'); |
|
|
|
|
87
|
|
|
$field->setForm($form); |
88
|
|
|
|
89
|
|
|
$this->assertThat( |
90
|
|
|
$form->getLabel('hidden'), |
91
|
|
|
$this->equalTo('<label id="hidden-lbl" for="hidden" class="">foo</label>'), |
92
|
|
|
'Line:' . __LINE__ . ' The label of a non-hidden element should be some HTML.' |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.