Passed
Branch master (ecb760)
by Antonio Carlos
05:12
created

GeoIpTest::test_get_country()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PragmaRX\Firewall\Tests;
4
5
use PragmaRX\Firewall\Vendor\Laravel\Facade as Firewall;
6
7
class GeoIpTest extends TestCase
8
{
9
    public function setUp()
10
    {
11
        parent::setUp();
12
13
        Firewall::updateGeoIp();
14
    }
15
16
    public function test_get_country()
17
    {
18
        $this->assertEquals('us', Firewall::getCountryFromIp('8.8.8.8'));
19
20
        $this->assertEquals('br', Firewall::getCountryFromIp('200.222.0.24'));
21
    }
22
23
    public function test_block_per_country()
24
    {
25
        Firewall::blacklist('country:us');
26
27
        $this->assertTrue(Firewall::isBlacklisted('8.8.8.8'));
28
29
        $this->assertFalse(Firewall::isWhitelisted('8.8.8.8'));
30
    }
31
32
    public function test_make_country()
33
    {
34
        $this->assertEquals('country:br', Firewall::makeCountryFromString('br'));
35
36
        $this->assertEquals('country:br', Firewall::makeCountryFromString('country:br'));
37
38
        $this->assertEquals('country:br', Firewall::makeCountryFromString('200.222.0.21'));
39
    }
40
41
    public function test_country_ip_listing()
42
    {
43
        Firewall::blacklist('8.8.8.7');
44
        Firewall::blacklist('8.8.8.8');
45
        Firewall::blacklist('8.8.8.9');
46
47
        Firewall::blacklist('200.222.0.21');
48
        Firewall::blacklist('200.222.0.22');
49
50
        $this->assertCount(2, Firewall::allByCountry('br'));
51
52
        $this->assertCount(3, Firewall::allByCountry('us'));
53
    }
54
55
    public function test_country_is_valid()
56
    {
57
        $this->assertTrue(Firewall::validCountry('country:us'));
58
59
        $this->assertTrue(Firewall::validCountry('country:br'));
60
61
        $this->assertFalse(Firewall::validCountry('country:xx'));
62
    }
63
}
64