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\Url as RuleUrl; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test class for JForm. |
14
|
|
|
* |
15
|
|
|
* @since 1.0 |
16
|
|
|
*/ |
17
|
|
|
class JFormRuleUrlTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Test the Joomla\Form\Rule\Url::test method. |
21
|
|
|
* |
22
|
|
|
* @param string $xmlfield @todo |
23
|
|
|
* @param string $url @todo |
24
|
|
|
* @param string $expected @todo |
25
|
|
|
* |
26
|
|
|
* @dataProvider provider |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function testUrl($xmlfield, $url, $expected) |
31
|
|
|
{ |
32
|
|
|
$rule = new RuleUrl; |
|
|
|
|
33
|
|
|
|
34
|
|
|
// The field allows you to optionally limit the accepted schemes to a specific list. |
35
|
|
|
// Url1 tests without a list, Url2 tests with a list. |
36
|
|
|
$xml = simplexml_load_string('<form><field name="url1" /> |
37
|
|
|
<field name="url2" schemes="gopher" /></form>'); |
38
|
|
|
|
39
|
|
View Code Duplication |
if ($xmlfield == '0') |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
if ($expected == 'false') |
42
|
|
|
{ |
43
|
|
|
// Test fail conditions. |
44
|
|
|
$this->assertThat( |
45
|
|
|
$rule->test($xml->field[0], $url), |
46
|
|
|
$this->isFalse(), |
47
|
|
|
'Line:' . __LINE__ . ' The rule should return' . $expected . '.' |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($expected == 'true') |
52
|
|
|
{ |
53
|
|
|
// Test pass conditions. |
54
|
|
|
$this->assertThat( |
55
|
|
|
$rule->test($xml->field[0], $url), |
56
|
|
|
$this->isTrue(), |
57
|
|
|
'Line:' . __LINE__ . ' The rule should return' . $expected . '.' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
if ($xmlfield == '1') |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
if ($expected == 'false') |
65
|
|
|
{ |
66
|
|
|
// Test fail conditions. |
67
|
|
|
$this->assertThat( |
68
|
|
|
$rule->test($xml->field[1], $url), |
69
|
|
|
$this->isFalse(), |
70
|
|
|
'Line:' . __LINE__ . ' The rule should return' . $expected . '.' |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($expected == 'true') |
75
|
|
|
{ |
76
|
|
|
// Test pass conditions. |
77
|
|
|
$this->assertThat( |
78
|
|
|
$rule->test($xml->field[1], $url), |
79
|
|
|
$this->isTrue(), |
80
|
|
|
'Line:' . __LINE__ . ' The rule should return' . $expected . '.' |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Test... |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function provider() |
92
|
|
|
{ |
93
|
|
|
// Most test urls are directly from or based on the RFCs noted in the rule. |
94
|
|
|
return |
95
|
|
|
array( |
96
|
|
|
array('Simple String' => '0', 'bogus', 'false'), |
97
|
|
|
array('No scheme' => '0', 'mydomain.com', 'false'), |
98
|
|
|
array('No ://' => '0', 'httpmydomain.com', 'false'), |
99
|
|
|
array('Three slashes' => '0', 'http:///mydomain.com', 'false'), |
100
|
|
|
array('No :' => '0', 'http//mydomain.com', 'false'), |
101
|
|
|
array('Port only' => '0', 'http://:80', 'false'), |
102
|
|
|
array('Improper @' => '0', 'http://user@:80', 'false'), |
103
|
|
|
array('array(http with one slash' => '0', 'http:/mydomain.com', 'false'), |
104
|
|
|
array('Scheme not in options list' => '1', 'http://mydomain.com', 'false'), |
105
|
|
|
array('http' => '0', 'http://mydomain.com', 'true'), |
106
|
|
|
array('Upper case scheme' => '0', 'HTTP://mydomain.com', 'true'), |
107
|
|
|
array('FTP' => '0', 'ftp://ftp.is.co.za/rfc/rfc1808.txt', 'true'), |
108
|
|
|
array('Path with slash' => '0', 'http://www.ietf.org/rfc/rfc2396.txt', 'true'), |
109
|
|
|
array('LDAP' => '0', 'ldap://[2001:db8::7]/c=GB?objectClass?one', 'true'), |
110
|
|
|
array('Mailto' => '0', 'mailto:[email protected]', 'true'), |
111
|
|
|
array('News' => '0', 'news:comp.infosystems.www.servers.unix', 'true'), |
112
|
|
|
array('Tel with +' => '0', 'tel:+1-816-555-1212', 'true'), |
113
|
|
|
array('Telnet to IP with port' => '0', 'telnet://192.0.2.16:80/', 'true'), |
114
|
|
|
array('File with no slashes' => '0', 'file:document.extension', 'true'), |
115
|
|
|
array('File with 3 slashes' => '0', 'file:///document.extension', 'true'), |
116
|
|
|
array('Only gopher allowed' => '1', 'gopher://gopher.mydomain.com', 'true'), |
117
|
|
|
array('URN' => '0', 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2', 'true'), |
118
|
|
|
array('Space in path' => '0', 'http://mydomain.com/Laguna%20Beach.htm', 'true'), |
119
|
|
|
array('UTF-8 in path' => '0', 'http://mydomain.com/объектов', 'true'), |
120
|
|
|
array('Puny code in domain' => '0', 'http://www.österreich.at', 'true'), |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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.