JFormRuleBooleanTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B testBoolean() 0 75 1
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\Rule\Boolean as RuleBoolean;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17
class JFormRuleBooleanTest extends \PHPUnit_Framework_TestCase
18
{
19
	/**
20
	 * Test the Joomla\Form\Rule\Boolean::test method.
21
	 *
22
	 * @return void
23
	 */
24
	public function testBoolean()
25
	{
26
		$rule = new RuleBoolean;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Boolean has been deprecated with message: The joomla/form package is deprecated

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.

Loading history...
27
		$xml = simplexml_load_string('<form><field name="foo" /></form>');
28
29
		// Test fail conditions.
30
31
		$this->assertThat(
32
			$rule->test($xml->field, 'bogus'),
33
			$this->isFalse(),
34
			'Line:' . __LINE__ . ' The rule should fail and return false.'
35
		);
36
37
		$this->assertThat(
38
			$rule->test($xml->field, '0_anything'),
39
			$this->isFalse(),
40
			'Line:' . __LINE__ . ' The rule should fail and return false.'
41
		);
42
43
		$this->assertThat(
44
			$rule->test($xml->field, 'anything_1_anything'),
45
			$this->isFalse(),
46
			'Line:' . __LINE__ . ' The rule should fail and return false.'
47
		);
48
49
		$this->assertThat(
50
			$rule->test($xml->field, 'anything_true_anything'),
51
			$this->isFalse(),
52
			'Line:' . __LINE__ . ' The rule should fail and return false.'
53
		);
54
55
		$this->assertThat(
56
			$rule->test($xml->field, 'anything_false'),
57
			$this->isFalse(),
58
			'Line:' . __LINE__ . ' The rule should fail and return false.'
59
		);
60
61
		// Test pass conditions.
62
63
		$this->assertThat(
64
			$rule->test($xml->field, 0),
65
			$this->isTrue(),
66
			'Line:' . __LINE__ . ' The rule should pass and return true.'
67
		);
68
69
		$this->assertThat(
70
			$rule->test($xml->field, '0'),
71
			$this->isTrue(),
72
			'Line:' . __LINE__ . ' The rule should pass and return true.'
73
		);
74
75
		$this->assertThat(
76
			$rule->test($xml->field, 1),
77
			$this->isTrue(),
78
			'Line:' . __LINE__ . ' The rule should pass and return true.'
79
		);
80
81
		$this->assertThat(
82
			$rule->test($xml->field, '1'),
83
			$this->isTrue(),
84
			'Line:' . __LINE__ . ' The rule should pass and return true.'
85
		);
86
87
		$this->assertThat(
88
			$rule->test($xml->field, 'true'),
89
			$this->isTrue(),
90
			'Line:' . __LINE__ . ' The rule should pass and return true.'
91
		);
92
93
		$this->assertThat(
94
			$rule->test($xml->field, 'false'),
95
			$this->isTrue(),
96
			'Line:' . __LINE__ . ' The rule should pass and return true.'
97
		);
98
	}
99
}
100