JFormFieldHiddenTest::testGetInput()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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');
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...
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');
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...
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');
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...
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