Code Duplication    Length = 17-18 lines in 4 locations

Tests/fields/JFormFieldCheckboxTest.php 4 locations

@@ 42-58 (lines=17) @@
39
	 *
40
	 * @since   1.0
41
	 */
42
	public function testGetInputNoValueNoChecked()
43
	{
44
		$formField = \Joomla\Form\FormHelper::loadFieldType('checkbox');
45
46
		// Test with no checked element
47
		$element = simplexml_load_string(
48
			'<field name="color" type="checkbox" value="red" />');
49
		TestHelper::setValue($formField, 'element', $element);
50
		TestHelper::setValue($formField, 'id', 'myTestId');
51
		TestHelper::setValue($formField, 'name', 'myTestName');
52
53
		$this->assertEquals(
54
			'<input type="checkbox" name="myTestName" id="myTestId" value="red" />',
55
			TestHelper::invoke($formField, 'getInput'),
56
			'The field with no value and no checked attribute did not produce the right html'
57
		);
58
	}
59
60
	/**
61
	 * Test the getInput method where there is a value from the element
@@ 68-85 (lines=18) @@
65
	 *
66
	 * @since   1.0
67
	 */
68
	public function testGetInputValueNoChecked()
69
	{
70
		$formField = \Joomla\Form\FormHelper::loadFieldType('checkbox');
71
72
		// Test with no checked element
73
		$element = simplexml_load_string(
74
			'<field name="color" type="checkbox" value="red" />');
75
		TestHelper::setValue($formField, 'element', $element);
76
		TestHelper::setValue($formField, 'id', 'myTestId');
77
		TestHelper::setValue($formField, 'name', 'myTestName');
78
		TestHelper::setValue($formField, 'value', 'red');
79
80
		$this->assertEquals(
81
			'<input type="checkbox" name="myTestName" id="myTestId" value="red" checked="checked" />',
82
			TestHelper::invoke($formField, 'getInput'),
83
			'The field with a value and no checked attribute did not produce the right html'
84
		);
85
	}
86
87
	/**
88
	 * Test the getInput method where there is a checked attribute
@@ 94-110 (lines=17) @@
91
	 *
92
	 * @since   1.0
93
	 */
94
	public function testGetInputNoValueChecked()
95
	{
96
		$formField = \Joomla\Form\FormHelper::loadFieldType('checkbox');
97
98
		// Test with checked element
99
		$element = simplexml_load_string(
100
			'<field name="color" type="checkbox" value="red" checked="checked" />');
101
		TestHelper::setValue($formField, 'element', $element);
102
		TestHelper::setValue($formField, 'id', 'myTestId');
103
		TestHelper::setValue($formField, 'name', 'myTestName');
104
105
		$this->assertEquals(
106
			'<input type="checkbox" name="myTestName" id="myTestId" value="red" checked="checked" />',
107
			TestHelper::invoke($formField, 'getInput'),
108
			'The field with no value and the checked attribute did not produce the right html'
109
		);
110
	}
111
112
	/**
113
	 * Test the getInput method where the field is disabled
@@ 119-135 (lines=17) @@
116
	 *
117
	 * @since   1.0
118
	 */
119
	public function testGetInputDisabled()
120
	{
121
		$formField = \Joomla\Form\FormHelper::loadFieldType('checkbox');
122
123
		// Test with checked element
124
		$element = simplexml_load_string(
125
			'<field name="color" type="checkbox" value="red" disabled="true" />');
126
		TestHelper::setValue($formField, 'element', $element);
127
		TestHelper::setValue($formField, 'id', 'myTestId');
128
		TestHelper::setValue($formField, 'name', 'myTestName');
129
130
		$this->assertEquals(
131
			'<input type="checkbox" name="myTestName" id="myTestId" value="red" disabled="disabled" />',
132
			TestHelper::invoke($formField, 'getInput'),
133
			'The field set to disabled did not produce the right html'
134
		);
135
	}
136
}
137