<commit_before><?php

namespace mako\tests\unit\http;

use \mako\http\Request;

use \Mockery as m;

/**
 * @group unit
 */

class RequestTest extends \PHPUnit_Framework_TestCase
{
	/**
	 * 
	 */

	public function tearDown()
	{
		m::close();
	}

	/**
	 * 
	 */

	public function getServerData()
	{
		return [
			'HTTP_HOST' => 'example.local',
			'HTTP_CONNECTION' => 'keep-alive',
			'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
			'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36',
			'HTTP_DNT' => '1',
			'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
			'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8,da;q=0.6,fr;q=0.4,nb;q=0.2,sv;q=0.2',
			'PATH' => '/usr/local/bin:/usr/bin:/bin',
			'SERVER_SIGNATURE' => '<address>Apache/2.4.6 (Ubuntu) Server at example.local Port 80</address>',
			'SERVER_SOFTWARE' => 'Apache/2.4.6 (Ubuntu)',
			'SERVER_NAME' => 'example.local',
			'SERVER_ADDR' => '10.17.2.9',
			'SERVER_PORT' => '80',
			'REMOTE_ADDR' => '10.17.12.209',
			'DOCUMENT_ROOT' => '/var/www',
			'REQUEST_SCHEME' => 'http',
			'CONTEXT_PREFIX' => '',
			'CONTEXT_DOCUMENT_ROOT' => '/var/www',
			'SERVER_ADMIN' => '<EMAIL>@localhost',
			'REMOTE_PORT' => '53058',
			'GATEWAY_INTERFACE' => 'CGI/1.1',
			'SERVER_PROTOCOL' => 'HTTP/1.1',
			'REQUEST_METHOD' => 'GET',
			'QUERY_STRING' => '',
			'REQUEST_TIME_FLOAT' => 1398338683.59,
			'REQUEST_TIME' => 1398338683,
			'REQUEST_URI' => '/test/',
			'SCRIPT_NAME' => '/index.php',
			'PHP_SELF' => '/index.php/test/',
			'SCRIPT_FILENAME' => '/var/www/index.php',
			'PATH_INFO' => '/test/',
		];
	}

	/**
	 * 
	 */

	public function testIP()
	{
		$server = $this->getServerData();

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('10.17.12.209', $request->ip());

		//

		$server['REMOTE_ADDR'] = 'invalid ip';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('127.0.0.1', $request->ip());

		//

		$server['HTTP_X_FORWARDED_FOR'] = '10.17.12.210,10.17.12.211';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('10.17.12.210', $request->ip());

		//

		unset($server['HTTP_X_FORWARDED_FOR']);

		$server['HTTP_CLIENT_IP'] = '2001:0db8:0000:0000:0000:ff00:0042:8329';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('2001:0db8:0000:0000:0000:ff00:0042:8329', $request->ip());

		//

		unset($server['HTTP_CLIENT_IP']);

		$server['HTTP_X_CLUSTER_CLIENT_IP'] = '::1';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('::1', $request->ip());
	}

	/**
	 * 
	 */

	public function testIsAjax()
	{
		$server = $this->getServerData();

		$request = new Request(['SERVER' => $server]);

		$this->assertFalse($request->isAjax());

		//

		$server['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';

		$request = new Request(['SERVER' => $server]);

		$this->assertTrue($request->isAjax());
	}

	/**
	 * 
	 */<commit_msg>Fixed test<commit_after><?php

namespace mako\tests\unit\http;

use \mako\http\Request;

use \Mockery as m;

/**
 * @group unit
 */

class RequestTest extends \PHPUnit_Framework_TestCase
{
	/**
	 * 
	 */

	public function tearDown()
	{
		m::close();
	}

	/**
	 * 
	 */

	public function getServerData()
	{
		return [
			'HTTP_HOST' => 'example.local',
			'HTTP_CONNECTION' => 'keep-alive',
			'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
			'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36',
			'HTTP_DNT' => '1',
			'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
			'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8,da;q=0.6,fr;q=0.4,nb;q=0.2,sv;q=0.2',
			'PATH' => '/usr/local/bin:/usr/bin:/bin',
			'SERVER_SIGNATURE' => '<address>Apache/2.4.6 (Ubuntu) Server at example.local Port 80</address>',
			'SERVER_SOFTWARE' => 'Apache/2.4.6 (Ubuntu)',
			'SERVER_NAME' => 'example.local',
			'SERVER_ADDR' => '10.17.2.9',
			'SERVER_PORT' => '80',
			'REMOTE_ADDR' => '10.17.12.209',
			'DOCUMENT_ROOT' => '/var/www',
			'REQUEST_SCHEME' => 'http',
			'CONTEXT_PREFIX' => '',
			'CONTEXT_DOCUMENT_ROOT' => '/var/www',
			'SERVER_ADMIN' => '<EMAIL>',
			'REMOTE_PORT' => '53058',
			'GATEWAY_INTERFACE' => 'CGI/1.1',
			'SERVER_PROTOCOL' => 'HTTP/1.1',
			'REQUEST_METHOD' => 'GET',
			'QUERY_STRING' => '',
			'REQUEST_TIME_FLOAT' => 1398338683.59,
			'REQUEST_TIME' => 1398338683,
			'REQUEST_URI' => '/test/',
			'SCRIPT_NAME' => '/index.php',
			'PHP_SELF' => '/index.php/test/',
			'SCRIPT_FILENAME' => '/var/www/index.php',
			'PATH_INFO' => '/test/',
		];
	}

	/**
	 * 
	 */

	public function testIP()
	{
		$server = $this->getServerData();

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('10.17.12.209', $request->ip());

		//

		$server['REMOTE_ADDR'] = 'invalid ip';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('127.0.0.1', $request->ip());

		//

		$server['HTTP_X_FORWARDED_FOR'] = '10.17.12.210,10.17.12.211';

		$request = new Request(['SERVER' => $server]);

		$this->assertEquals('10.17.12.210', $request->ip());
	}

	/**
	 * 
	 */

	public function testIsAjax()
	{
		$server = $this->getServerData();

		$request = new Request(['SERVER' => $server]);

		$this->assertFalse($request->isAjax());

		//

		$server['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';

		$request = new Request(['SERVER' => $server]);

		$this->assertTrue($request->isAjax());
	}

	/**
	 * 
	 */
{'fraction_non_alphanumeric': 0.23208861890298374, 'fraction_numerical': 0.060032160085760226, 'mean_word_length': 3.7521222410865875, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 4}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603356', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2244, 'n_words': 313}