|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RattfieldNz\SafeUrls\Libraries\Data; |
|
6
|
|
|
|
|
7
|
|
|
use RattfieldNz\SafeUrls\Libraries\Config\Config; |
|
8
|
|
|
use RattfieldNz\SafeUrls\Tests\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class DataTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private $formattedUrls = [ |
|
13
|
|
|
['url' => 'https://www.google.com'], |
|
14
|
|
|
['url' => 'https://github.com'], |
|
15
|
|
|
['url' => 'https://github.styleci.io'], |
|
16
|
|
|
['url' => 'https://travis-ci.org'], |
|
17
|
|
|
['url' => 'https://packagist.org'], |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
private $urls = [ |
|
21
|
|
|
'https://www.google.com', |
|
22
|
|
|
'https://github.com', |
|
23
|
|
|
'https://github.styleci.io', |
|
24
|
|
|
'https://travis-ci.org', |
|
25
|
|
|
'https://packagist.org', |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
protected function setUp(): void |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testPayloadMultipleUrls() |
|
34
|
|
|
{ |
|
35
|
|
|
$expected = self::payload($this->formattedUrls); |
|
36
|
|
|
|
|
37
|
|
|
$actual = Data::payload($this->urls); |
|
38
|
|
|
$this->assertEquals($expected, $actual); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testPayloadSingleUrl() |
|
42
|
|
|
{ |
|
43
|
|
|
$formattedUrl = [ |
|
44
|
|
|
['url' => 'https://www.google.com'], |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
$url = [ |
|
48
|
|
|
'https://www.google.com', |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
$expected = self::payload($formattedUrl); |
|
52
|
|
|
|
|
53
|
|
|
$actual = Data::payload($url); |
|
54
|
|
|
$this->assertEquals($expected, $actual); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testPayloadNoUrls() |
|
58
|
|
|
{ |
|
59
|
|
|
$formattedUrls = [ |
|
60
|
|
|
//['url' => ''], |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
$urls = []; |
|
64
|
|
|
|
|
65
|
|
|
$expected = self::payload($formattedUrls); |
|
66
|
|
|
|
|
67
|
|
|
$actual = Data::payload($urls); |
|
68
|
|
|
$this->assertEquals($expected, $actual); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testFormatUrlsMultiple() |
|
72
|
|
|
{ |
|
73
|
|
|
$expected = $this->formattedUrls; |
|
74
|
|
|
|
|
75
|
|
|
$actual = Data::formatUrls($this->urls); |
|
76
|
|
|
$this->assertEquals($expected, $actual); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testFormatUrlsSingle() |
|
80
|
|
|
{ |
|
81
|
|
|
$url = ['https://www.google.com']; |
|
82
|
|
|
|
|
83
|
|
|
$expected = [ |
|
84
|
|
|
['url' => 'https://www.google.com'], |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
$actual = Data::formatUrls($url); |
|
88
|
|
|
$this->assertEquals($expected, $actual); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testFormatUrlsNone() |
|
92
|
|
|
{ |
|
93
|
|
|
$urls = []; |
|
94
|
|
|
|
|
95
|
|
|
$expected = []; |
|
96
|
|
|
|
|
97
|
|
|
$actual = Data::formatUrls($urls); |
|
98
|
|
|
$this->assertEquals($expected, $actual); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private static function payload(array $urls): array{ |
|
102
|
|
|
return [ |
|
103
|
|
|
'client' => [ |
|
104
|
|
|
'clientId' => Config::clientId(), |
|
105
|
|
|
'clientVersion' => Config::clientVersion(), |
|
106
|
|
|
], |
|
107
|
|
|
'threatInfo' => [ |
|
108
|
|
|
'threatTypes' => Config::threatTypes(), |
|
109
|
|
|
'platformTypes' => Config::platformTypes(), |
|
110
|
|
|
'threatEntryTypes' => Config::threatEntryTypes(), |
|
111
|
|
|
'threatEntries' => $urls, |
|
112
|
|
|
], |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|