Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / libs / CookieTest.php
1 <?php
2
3 /**
4 * @covers Cookie
5 */
6 class CookieTest extends \PHPUnit\Framework\TestCase {
7
8 /**
9 * @dataProvider cookieDomains
10 * @covers Cookie::validateCookieDomain
11 */
12 public function testValidateCookieDomain( $expected, $domain, $origin = null ) {
13 if ( $origin ) {
14 $ok = Cookie::validateCookieDomain( $domain, $origin );
15 $msg = "$domain against origin $origin";
16 } else {
17 $ok = Cookie::validateCookieDomain( $domain );
18 $msg = "$domain";
19 }
20 $this->assertEquals( $expected, $ok, $msg );
21 }
22
23 public static function cookieDomains() {
24 return [
25 [ false, "org" ],
26 [ false, ".org" ],
27 [ true, "wikipedia.org" ],
28 [ true, ".wikipedia.org" ],
29 [ false, "co.uk" ],
30 [ false, ".co.uk" ],
31 [ false, "gov.uk" ],
32 [ false, ".gov.uk" ],
33 [ true, "supermarket.uk" ],
34 [ false, "uk" ],
35 [ false, ".uk" ],
36 [ false, "127.0.0." ],
37 [ false, "127." ],
38 [ false, "127.0.0.1." ],
39 [ true, "127.0.0.1" ],
40 [ false, "333.0.0.1" ],
41 [ true, "example.com" ],
42 [ false, "example.com." ],
43 [ true, ".example.com" ],
44
45 [ true, ".example.com", "www.example.com" ],
46 [ false, "example.com", "www.example.com" ],
47 [ true, "127.0.0.1", "127.0.0.1" ],
48 [ false, "127.0.0.1", "localhost" ],
49 ];
50 }
51
52 }