JFormRuleEmailTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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\Test\TestHelper;
10
use Joomla\Form\Rule\Email as RuleEmail;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17
class JFormRuleEmailTest extends \PHPUnit_Framework_TestCase
18
{
19
	/**
20
	 * set up for testing
21
	 *
22
	 * @return void
23
	 */
24
	public function setUp()
25
	{
26
		parent::setUp();
27
	}
28
29
	/**
30
	 * Tear down test
31
	 *
32
	 * @return void
33
	 */
34
	protected function tearDown()
35
	{
36
	}
37
38
	/**
39
	 * Test the Joomla\Form\Rule\Email::test method.
40
	 *
41
	 * @return void
42
	 */
43 View Code Duplication
	public function testEmail()
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...
44
	{
45
		$rule = new RuleEmail;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Email 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...
46
		$xml = simplexml_load_string('<form><field name="email1" /><field name="email2" unique="true" /></form>');
47
48
		// Test fail conditions.
49
50
		$this->assertThat(
51
			$rule->test($xml->field[0], 'bogus'),
52
			$this->isFalse(),
53
			'Line:' . __LINE__ . ' The rule should fail and return false.'
54
		);
55
56
		// Test pass conditions.
57
58
		$this->assertThat(
59
			$rule->test($xml->field[0], '[email protected]'),
60
			$this->isTrue(),
61
			'Line:' . __LINE__ . ' The basic rule should pass and return true.'
62
		);
63
64
		$this->markTestIncomplete('More tests required');
65
66
		/*
67
		 TODO: Need to test the "field" attribute which adds to the unique test where clause.
68
		 TODO: Database error is prevents the following tests from working properly.
69
		*/
70
		$this->assertThat(
71
			$rule->test($xml->field[1], '[email protected]'),
72
			$this->isTrue(),
73
			'Line:' . __LINE__ . ' The unique rule should pass and return true.'
74
		);
75
	}
76
77
	/**
78
	 * Data Provider  for email rule test with no multiple attribute and no tld attribute
79
	 *
80
	 * @return array
81
	 *
82
	 * @since 11.1
83
	 */
84
	public function emailData1()
85
	{
86
		return array(
87
			array('[email protected]', true),
88
			array('badaddress.com', false),
89
			array('[email protected]', true),
90
			array('[email protected]', true),
91
			array('[email protected]', true),
92
			array('[email protected]', true),
93
			array('[email protected]', true),
94
			array('[email protected]', true),
95
			array('firstname@localhost', true)
96
		);
97
	}
98
99
	/**
100
	 * Test the email rule
101
	 *
102
	 * @param   string   $emailAddress    Email to be tested
103
	 * @param   boolean  $expectedResult  Result of test
104
	 *
105
	 * @dataProvider emailData1
106
	 *
107
	 * @return void
108
	 *
109
	 * @since 11.1
110
	 */
111 View Code Duplication
	public function testEmailData($emailAddress, $expectedResult)
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...
112
	{
113
		$rule = new RuleEmail;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Email 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...
114
		$xml = simplexml_load_string('<form><field name="email1" /></form>');
115
		$this->assertThat(
116
			$rule->test($xml->field[0], $emailAddress),
117
			$this->equalTo($expectedResult),
118
			$emailAddress . ' should have returned ' . ($expectedResult ? 'true' : 'false') . ' but did not'
119
		);
120
	}
121
122
	/**
123
	 * Data Provider  for email rule test with multiple attribute and no tld attribute
124
	 *
125
	 * @return array
126
	 *
127
	 * @since 12.3
128
	 */
129
	public function emailData2()
130
	{
131
		return array(
132
			array('[email protected]', true),
133
			array('[email protected],[email protected],test3@localhost', true),
134
		);
135
	}
136
137
	/**
138
	 * Test the email rule with the multiple attribute
139
	 *
140
	 * @param   string   $emailAddress    Email to be tested
141
	 * @param   boolean  $expectedResult  Result of test
142
	 *
143
	 * @dataProvider emailData2
144
	 *
145
	 * @return void
146
	 *
147
	 * @since 12.3
148
	 */
149 View Code Duplication
	public function testEmailData2($emailAddress, $expectedResult)
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...
150
	{
151
		$rule = new RuleEmail;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Email 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...
152
		$xml = simplexml_load_string('<form><field name="email1" multiple="multiple" /></form>');
153
		$this->assertThat(
154
			$rule->test($xml->field[0], $emailAddress),
155
			$this->equalTo($expectedResult),
156
			$emailAddress . ' should have returned ' . ($expectedResult ? 'true' : 'false') . ' but did not'
157
		);
158
	}
159
160
	/**
161
	 * Data Provider  for email rule test with tld attribute
162
	 *
163
	 * @return array
164
	 *
165
	 * @since 12.3
166
	 */
167
	public function emailData3()
168
	{
169
		return array(
170
			array('[email protected]', true),
171
			array('test3@localhost', false),
172
			array('[email protected]', true),
173
			array('[email protected]', true),
174
			array('[email protected]', true),
175
		);
176
	}
177
178
	/**
179
	 * Test the email rule with the tld attribute
180
	 *
181
	 * @param   string   $emailAddress    Email to be tested
182
	 * @param   boolean  $expectedResult  Result of test
183
	 *
184
	 * @dataProvider emailData3
185
	 *
186
	 * @return void
187
	 *
188
	 * @since 12.3
189
	 */
190 View Code Duplication
	public function testEmailData3($emailAddress, $expectedResult)
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...
191
	{
192
		$rule = new RuleEmail;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Email 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...
193
		$xml = simplexml_load_string('<form><field name="email1" tld="tld" /></form>');
194
		$this->assertThat(
195
			$rule->test($xml->field[0], $emailAddress),
196
			$this->equalTo($expectedResult),
197
			$emailAddress . ' should have returned ' . ($expectedResult ? 'true' : 'false') . ' but did not'
198
		);
199
	}
200
}
201