.dev/tests/unit/functions/function_check_ip_test.Test.php

Summary

Maintainability
A
1 hr
Test Coverage
<?php


require_once dirname(__DIR__) . '/yf_unit_tests_setup.php';

class function_check_ip_test extends yf\tests\wrapper
{
    public function test_1()
    {
        $test_array = [
            '172.19.177.198, 170.51.255.218' => '170.51.255.218',
            '172.19.177.198, 10.21.0.218' => '',
            '172.44.141.63, 189.204.26.200' => '189.204.26.200',
            '100.43.83.158' => '100.43.83.158',
            '141.63.172.26, 189.204.26.200' => '141.63.172.26',
            '50.23.132.250, % 188.165.140.51  & .19.177.198, 170.51.255.218 170.51.255.217 | 170.51.255.215 5 . %%%234.123.345.234' => '170.51.255.218',
            '110.45.192.73,108_168_141_178' => '110.45.192.73',
            '118.70.127.134,108.168.141.178' => '118.70.127.134',
            '110.45.192.73 | 94.23.1.212' => '110.45.192.73',
            '213.186.127.8, 94.23.1.212' => '213.186.127.8',
            '213.186.127.10 " remote_addr_ip":"94.23.1.212"' => '213.186.127.10',
            '213.186.127.7","emote_addr_ip":"94.23.1.212"' => '213.186.127.7',
            '213.86.127.9","remote_addr_ip":"94.23.1.212"' => '213.86.127.9',
            '213.86.127.13","remote_addr_ip":"94.23.1.212"' => '213.86.127.13',
            '102.219.202.23, 124.81.238.226' => '124.81.238.226',
        ];
        $ignore_ips = [
            '172.19.177.198',
            '172.44.141.63',
            '50.23.132.250',
            '188.165.140.51',
            '102.219.202.23',
        ];
        $ignore_ips = array_combine($ignore_ips, $ignore_ips);
        foreach ((array) $test_array as $test_ip => $expect_ip) {
            $_SERVER['HTTP_X_FORWARDED_FOR'] = $key;
            $this->assertEquals($expect_ip, _class('client_utils', 'classes/common/')->_check_ip($test_ip, $ignore_ips/*, 'GEO'*/));
        }
    }
}