|
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->_urls); |
|
36
|
|
|
|
|
37
|
|
|
$actual = Data::payload($this->_urls); |
|
38
|
|
|
$this->assertEquals($expected, $actual); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testPayloadSingleUrl() |
|
42
|
|
|
{ |
|
43
|
|
|
$url = [ |
|
44
|
|
|
'https://www.google.com', |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
$expected = self::_payload($url); |
|
48
|
|
|
|
|
49
|
|
|
$actual = Data::payload($url); |
|
50
|
|
|
$this->assertEquals($expected, $actual); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testPayloadNoUrls() |
|
54
|
|
|
{ |
|
55
|
|
|
$urls = []; |
|
56
|
|
|
|
|
57
|
|
|
$expected = self::_payload($urls); |
|
58
|
|
|
|
|
59
|
|
|
$actual = Data::payload($urls); |
|
60
|
|
|
$this->assertEquals($expected, $actual); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testFormatUrlsMultiple() |
|
64
|
|
|
{ |
|
65
|
|
|
$expected = $this->_formattedUrls; |
|
66
|
|
|
|
|
67
|
|
|
$actual = Data::formatUrls($this->_urls); |
|
68
|
|
|
$this->assertEquals($expected, $actual); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testFormatUrlsSingle() |
|
72
|
|
|
{ |
|
73
|
|
|
$url = ['https://www.google.com']; |
|
74
|
|
|
|
|
75
|
|
|
$expected = [ |
|
76
|
|
|
['url' => 'https://www.google.com'], |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
$actual = Data::formatUrls($url); |
|
80
|
|
|
$this->assertEquals($expected, $actual); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testFormatUrlsNone() |
|
84
|
|
|
{ |
|
85
|
|
|
$urls = []; |
|
86
|
|
|
|
|
87
|
|
|
$expected = []; |
|
88
|
|
|
|
|
89
|
|
|
$actual = Data::formatUrls($urls); |
|
90
|
|
|
$this->assertEquals($expected, $actual); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
private static function _payload(array $urls, array $threatTypes = [], array $platformTypes = [], array $threatEntryTypes = []): array |
|
94
|
|
|
{ |
|
95
|
|
|
return [ |
|
96
|
|
|
'client' => [ |
|
97
|
|
|
'clientId' => Config::clientId(), |
|
98
|
|
|
'clientVersion' => Config::clientVersion(), |
|
99
|
|
|
], |
|
100
|
|
|
'threatInfo' => [ |
|
101
|
|
|
'threatTypes' => !empty($threatTypes) ? $threatTypes : Config::threatTypes(), |
|
102
|
|
|
'platformTypes' => !empty($platformTypes) ? $platformTypes : Config::platformTypes(), |
|
103
|
|
|
'threatEntryTypes' => !empty($threatEntryTypes) ? $threatEntryTypes : Config::threatEntryTypes(), |
|
104
|
|
|
'threatEntries' => Data::formatUrls($urls), |
|
105
|
|
|
], |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|