forked from geekwright/RegDom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PublicSuffixListTest.php
94 lines (77 loc) · 2.95 KB
/
PublicSuffixListTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php declare(strict_types=1);
namespace Xoops\RegDom;
use PHPUnit\Framework\TestCase;
class PublicSuffixListTest extends TestCase
{
/**
* @var PublicSuffixList
*/
protected PublicSuffixList $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp(): void
{
$this->object = new PublicSuffixList();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown(): void
{
// $this->object->clearDataDirectory();
}
public function testContracts()
{
$this->assertInstanceOf(PublicSuffixList::class, $this->object);
}
public function testGetSet()
{
$tree = $this->object->getTree();
$this->assertIsArray($tree);
$this->assertArrayHasKey('com', $tree);
}
public function testClearDataDirectory()
{
$this->object->clearDataDirectory();
$tree = $this->object->getTree();
$this->assertIsArray($tree);
$this->assertArrayHasKey('com', $tree);
}
public function testClearDataDirectoryCacheOnly()
{
$this->object->clearDataDirectory(true);
$tree = $this->object->getTree();
$this->assertIsArray($tree);
$this->assertArrayHasKey('com', $tree);
}
public function testSetURL()
{
$url = 'https://example.com';
$this->object->setURL($url);
// Use reflection to call the protected setFallbackURL method
$reflection = new \ReflectionClass($this->object);
// Check the URL property to verify the fallback URL is set correctly
$property = $reflection->getProperty('url');
$property->setAccessible(true);
$this->assertSame($url, $property->getValue($this->object));
}
public function testFallbackURL()
{
// Set URL to null and trigger the fallback mechanism
$this->object->setURL(null);
// Use reflection to call the protected setFallbackURL method
$reflection = new \ReflectionClass($this->object);
$method = $reflection->getMethod('setFallbackURL');
$method->setAccessible(true);
$method->invoke($this->object);
// Check the URL property to verify the fallback URL is set correctly
$property = $reflection->getProperty('url');
$property->setAccessible(true);
// $expectedUrl = file_exists(dirname(__DIR__, 2) . '/data/public_suffix_list.dat') ? dirname(__DIR__, 2) . '/data/public_suffix_list.dat' : 'https://publicsuffix.org/list/public_suffix_list.dat';
$expectedUrl = \file_exists(\dirname(__DIR__, 2) . '/data/public_suffix_list.dat') ? '/../data/public_suffix_list.dat' : 'https://publicsuffix.org/list/public_suffix_list.dat';
$this->assertSame($expectedUrl, $property->getValue($this->object));
}
}