|
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\TestDatabase; |
|
10
|
|
|
use Joomla\Form\Field_Language; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Test class for JFormFieldLanguage. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
class JFormFieldLanguageTest extends TestDatabase |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Sets up dependencies for the test. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
* |
|
24
|
|
|
* @since 1.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
// The real class cannot be autoloaded |
|
29
|
|
|
\Joomla\Form\FormHelper::loadFieldClass('language'); |
|
30
|
|
|
|
|
31
|
|
|
parent::setUp(); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gets the data set to be loaded into the database during setup |
|
36
|
|
|
* |
|
37
|
|
|
* @return \PHPUnit_Extensions_Database_DataSet_XmlDataSet dataset |
|
38
|
|
|
* |
|
39
|
|
|
* @since 1.0 |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function getDataSet() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->createXMLDataSet(__DIR__ . '/testfiles/JFormField.xml'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Test the getInput method. |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
* |
|
51
|
|
|
* @since 1.0 |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testGetInput() |
|
54
|
|
|
{ |
|
55
|
|
|
$form = new JFormInspector('form1'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertThat( |
|
58
|
|
|
$form->load('<form><field name="language" type="language" /></form>'), |
|
59
|
|
|
$this->isTrue(), |
|
60
|
|
|
'Line:' . __LINE__ . ' XML string should load successfully.' |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
/** @var Field_Language $field */ |
|
64
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('language'); |
|
|
|
|
|
|
65
|
|
|
$field->setForm($form); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertThat( |
|
68
|
|
|
$field->setup($form->getXml()->field, 'value'), |
|
69
|
|
|
$this->isTrue(), |
|
70
|
|
|
'Line:' . __LINE__ . ' The setup method should return true.' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$this->markTestIncomplete('Problems encountered in next assertion'); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertThat( |
|
76
|
|
|
strlen($field->input), |
|
|
|
|
|
|
77
|
|
|
$this->greaterThan(0), |
|
78
|
|
|
'Line:' . __LINE__ . ' The getInput method should return something without error.' |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
// TODO: Should check all the attributes have come in properly. |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Test... |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testCreateLanguageList() |
|
90
|
|
|
{ |
|
91
|
|
|
/** @var Field_Language $field */ |
|
92
|
|
|
$field = \Joomla\Form\FormHelper::loadFieldType('language'); |
|
|
|
|
|
|
93
|
|
|
$field->setForm(new JFormInspector('form1')); |
|
94
|
|
|
$reflection = new \ReflectionClass($field); |
|
95
|
|
|
$method = $reflection->getMethod('createLanguageList'); |
|
96
|
|
|
$method->setAccessible(true); |
|
97
|
|
|
|
|
98
|
|
|
$list = $method->invokeArgs( |
|
99
|
|
|
$field, |
|
100
|
|
|
array( |
|
101
|
|
|
'en-GB', |
|
102
|
|
|
__DIR__ . '/data' |
|
103
|
|
|
) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$listCompareEqual = array( |
|
107
|
|
|
array( |
|
108
|
|
|
'text' => 'English (United Kingdom)', |
|
109
|
|
|
'value' => 'en-GB', |
|
110
|
|
|
'selected' => 'selected="selected"' |
|
111
|
|
|
) |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertEquals( |
|
115
|
|
|
$listCompareEqual, |
|
116
|
|
|
$list |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.