Debian Codegraph @

tests/phpunit/unit/includes/libs/CookieTest.php

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