JFormHelperTest::testAddRulePath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 25
loc 25
rs 9.52
c 0
b 0
f 0
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\Form\Rule;
10
use Joomla\Form\FormHelper;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17
class JFormHelperTest extends \PHPUnit_Framework_TestCase
18
{
19
	/**
20
	 * Tests the Form::addFieldPath method.
21
	 *
22
	 * This method is used to add additional lookup paths for field helpers.
23
	 *
24
	 * @return void
25
	 */
26 View Code Duplication
	public function testAddFieldPath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
	{
28
		// Check the default behaviour.
29
		$paths = FormHelper::addFieldPath();
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addFieldPath() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
30
31
		// The default path is the class file folder/forms
32
		// use of realpath to ensure test works for on all platforms
33
		$valid = dirname(__DIR__) . '/field';
34
35
		$this->assertThat(
36
			in_array($valid, $paths),
37
			$this->isTrue(),
38
			'Line:' . __LINE__ . ' The libraries fields path should be included by default.'
39
		);
40
41
		// Test adding a custom folder.
42
		FormHelper::addFieldPath(__DIR__);
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addFieldPath() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
43
		$paths = FormHelper::addFieldPath();
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addFieldPath() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
44
45
		$this->assertThat(
46
			in_array(__DIR__, $paths),
47
			$this->isTrue(),
48
			'Line:' . __LINE__ . ' An added path should be in the returned array.'
49
		);
50
	}
51
52
	/**
53
	 * Tests the Form::addFormPath method.
54
	 *
55
	 * This method is used to add additional lookup paths for form XML files.
56
	 *
57
	 * @return void
58
	 */
59 View Code Duplication
	public function testAddFormPath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
	{
61
		// Check the default behaviour.
62
		$paths = FormHelper::addFormPath();
63
64
		// The default path is the class file folder/forms
65
		// use of realpath to ensure test works for on all platforms
66
		$valid = dirname(__DIR__) . '/form';
67
68
		$this->assertThat(
69
			in_array($valid, $paths),
70
			$this->isTrue(),
71
			'Line:' . __LINE__ . ' The libraries forms path should be included by default.'
72
		);
73
74
		// Test adding a custom folder.
75
		FormHelper::addFormPath(__DIR__);
76
		$paths = FormHelper::addFormPath();
77
78
		$this->assertThat(
79
			in_array(__DIR__, $paths),
80
			$this->isTrue(),
81
			'Line:' . __LINE__ . ' An added path should be in the returned array.'
82
		);
83
	}
84
85
	/**
86
	 * Tests the Form::addRulePath method.
87
	 *
88
	 * This method is used to add additional lookup paths for form XML files.
89
	 *
90
	 * @return void
91
	 */
92 View Code Duplication
	public function testAddRulePath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
	{
94
		// Check the default behaviour.
95
		$paths = FormHelper::addRulePath();
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addRulePath() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
96
97
		// The default path is the class file folder/rules
98
		// use of realpath to ensure test works for on all platforms
99
		$valid = dirname(__DIR__) . '/rule';
100
101
		$this->assertThat(
102
			in_array($valid, $paths),
103
			$this->isTrue(),
104
			'Line:' . __LINE__ . ' The libraries rule path should be included by default.'
105
		);
106
107
		// Test adding a custom folder.
108
		FormHelper::addRulePath(__DIR__);
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addRulePath() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
109
		$paths = FormHelper::addRulePath();
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addRulePath() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
110
111
		$this->assertThat(
112
			in_array(__DIR__, $paths),
113
			$this->isTrue(),
114
			'Line:' . __LINE__ . ' An added path should be in the returned array.'
115
		);
116
	}
117
118
	/**
119
	 * Test the Form::loadFieldType method.
120
	 *
121
	 * @return void
122
	 */
123
	public function testLoadFieldType()
124
	{
125
		$this->assertThat(
126
			FormHelper::loadFieldType('bogus'),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
127
			$this->isFalse(),
128
			'Line:' . __LINE__ . ' loadFieldType should return false if class not found.'
129
		);
130
131
		$this->assertThat(
132
			(FormHelper::loadFieldType('list') instanceof \Joomla\Form\Field_List),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
133
			$this->isTrue(),
134
			'Line:' . __LINE__ . ' loadFieldType should return the correct class.'
135
		);
136
137
		// Add custom path.
138
		FormHelper::addFieldPath(__DIR__ . '/_testfields');
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addFieldPath() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
139
140
		include_once '_testfields/test.php';
141
		$this->assertThat(
142
			(FormHelper::loadFieldType('test') instanceof \Joomla\Form\Field_Test),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
143
			$this->isTrue(),
144
			'Line:' . __LINE__ . ' loadFieldType should return the correct custom class.'
145
		);
146
147
		include_once '_testfields/bar.php';
148
		$this->assertThat(
149
			(FormHelper::loadFieldType('foo.bar') instanceof \Foo\Form\Field_Bar),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
150
			$this->isTrue(),
151
			'Line:' . __LINE__ . ' loadFieldType should return the correct custom class.'
152
		);
153
154
		include_once '_testfields/modal/foo.php';
155
		$this->assertThat(
156
			(FormHelper::loadFieldType('modal_foo') instanceof \Joomla\Form\Field_Modal_Foo),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
157
			$this->isTrue(),
158
			'Line:' . __LINE__ . ' loadFieldType should return the correct custom class.'
159
		);
160
161
		include_once '_testfields/modal/bar.php';
162
		$this->assertThat(
163
			(FormHelper::loadFieldType('foo.modal_bar') instanceof \Foo\Form\Field_Modal_Bar),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

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.

Loading history...
164
			$this->isTrue(),
165
			'Line:' . __LINE__ . ' loadFieldType should return the correct custom class.'
166
		);
167
	}
168
169
	/**
170
	 * Test for Form::loadRuleType method.
171
	 *
172
	 * @return void
173
	 */
174
	public function testLoadRuleType()
175
	{
176
		// Test error handling.
177
178
		$this->assertThat(
179
			FormHelper::loadRuleType('bogus'),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
180
			$this->isFalse(),
181
			'Line:' . __LINE__ . ' Loading an unknown rule should return false.'
182
		);
183
184
		// Test loading a custom rule.
185
186
		FormHelper::addRulePath(__DIR__ . '/_testrules');
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::addRulePath() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
187
188
		$this->assertThat(
189
			(FormHelper::loadRuleType('custom') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
190
			$this->isTrue(),
191
			'Line:' . __LINE__ . ' Loading a known rule should return a rule object.'
192
		);
193
194
		// Test all the stock rules load.
195
196
		$this->assertThat(
197
			(FormHelper::loadRuleType('boolean') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
198
			$this->isTrue(),
199
			'Line:' . __LINE__ . ' Loading the boolean rule should return a rule object.'
200
		);
201
202
		$this->assertThat(
203
			(FormHelper::loadRuleType('email') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
204
			$this->isTrue(),
205
			'Line:' . __LINE__ . ' Loading the email rule should return a rule object.'
206
		);
207
208
		$this->assertThat(
209
			(FormHelper::loadRuleType('equals') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
210
			$this->isTrue(),
211
			'Line:' . __LINE__ . ' Loading the equals rule should return a rule object.'
212
		);
213
214
		$this->assertThat(
215
			(FormHelper::loadRuleType('options') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
216
			$this->isTrue(),
217
			'Line:' . __LINE__ . ' Loading the options rule should return a rule object.'
218
		);
219
220
		$this->assertThat(
221
			(FormHelper::loadRuleType('color') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
222
			$this->isTrue(),
223
			'Line:' . __LINE__ . ' Loading the color rule should return a rule object.'
224
		);
225
226
		$this->assertThat(
227
			(FormHelper::loadRuleType('tel') instanceof Rule),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadRuleType() has been deprecated with message: 2.0 Rule objects should be autoloaded

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.

Loading history...
228
			$this->isTrue(),
229
			'Line:' . __LINE__ . ' Loading the tel rule should return a rule object.'
230
		);
231
	}
232
}
233