Exemplo n.º 1
0
 /**
  * @covers mychaelstyle\utils\Net::getRemoteAddress
  * @covers mychaelstyle\utils\Net::clear
  */
 public function testGetRemoteAddress()
 {
     $result = Net::getRemoteAddress();
     $this->assertEmpty($result);
     Net::clear();
     // REMOTE_HOSTのみ
     $expected = '127.0.0.1';
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $result = Net::getRemoteAddress();
     $this->assertEquals($expected, $result);
     Net::clear();
     // X-forwarded-for優先
     $expected = '127.0.0.2';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = $expected;
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $result = Net::getRemoteAddress();
     $this->assertEquals($expected, $result);
     Net::clear();
     // X-forwarded-for ,
     $expected = '127.0.0.2';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = $expected . ', 10.0.0.8';
     $result = Net::getRemoteAddress();
     $this->assertEquals($expected, $result);
     Net::clear();
     // X-forwarded-for :
     $expected = '127.0.0.2';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = $expected . ': 10.0.0.8';
     $result = Net::getRemoteAddress();
     $this->assertEquals($expected, $result);
     Net::clear();
     // X-forwarded-for ;
     $expected = '127.0.0.2';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = $expected . '; 10.0.0.8';
     $result = Net::getRemoteAddress();
     $this->assertEquals($expected, $result);
     Net::clear();
 }