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

GeoIpTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A test_get_country() 0 6 1
A test_block_per_country() 0 8 1
A test_make_country() 0 8 1
A test_country_ip_listing() 0 13 1
A test_country_is_valid() 0 8 1
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