-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathIpAddressTest.php
executable file
·98 lines (87 loc) · 2.54 KB
/
IpAddressTest.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
95
96
97
98
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Test\Unit\Helper;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\IpAddress;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\Serialize\SerializerInterface;
class IpAddressTest extends AbstractAdyenTestCase
{
/**
* @var IpAddress
*/
private $ipAddressHelper;
protected function setUp(): void
{
$cache = $this->createConfiguredMock(CacheInterface::class, [
'load' => ['1.2.3.4', '20.20.20.20']
]);
$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('unserialize')->willReturnArgument(0);
$ipAddressUtil = $this->createMock(\Adyen\Util\IpAddress::class);
$adyenLogger = $this->createMock(AdyenLogger::class);
$configHelper = $this->createMock(Config::class);
$configHelper->method('getNotificationsIpCheck')->willReturn(true);
$this->ipAddressHelper = new IpAddress(
$ipAddressUtil,
$cache,
$serializer,
$adyenLogger,
$configHelper
);
}
/**
* @dataProvider ipAddressesProvider
*/
public function testIsIpAddressValid($ipAddress, $expectedResult)
{
$this->assertEquals($expectedResult, $this->ipAddressHelper->isIpAddressValid([$ipAddress]));
}
public function testUpdateCachedIpAddresses()
{
$this->assertNull($this->ipAddressHelper->updateCachedIpAddresses());
}
public function testSaveIpAddressesToCache()
{
$this->assertNull($this->ipAddressHelper->saveIpAddressesToCache([]));
}
public function testGetIpAddressesFromCache()
{
$this->assertTrue(is_array($this->ipAddressHelper->getIpAddressesFromCache()));
}
public static function ipAddressesProvider()
{
return array(
array(
'1.2.3.4',
true
),
array(
'20.20.20.20',
true
),
array(
'8.8.8.8',
false
),
array(
'192.168.100.10',
false
),
array(
'500.168.100.10',
false
)
);
}
}