<commit_before><?php

class CoreRequestTokensTest extends PHPUnit_Framework_TestCase{
	protected function setUp(){
		$_SERVER['HTTPS'] = false;
		$_SERVER['HTTP_HOST'] = "host.com";
		$_SERVER['REQUEST_URI'] = "/uri";

		$this->utilStub = $this->getMockBuilder('Twittering\Util')
		->disableOriginalConstructor()
		->getMock();

		$this->twitterOAuthWrapperStub = $this->getMockBuilder('Twittering\TwitterOAuthWrapper')
			->disableOriginalConstructor()
			->getMock();
		$this->twitterOAuthStub = $this->getMockBuilder('\TwitterOAuth')
			->disableOriginalConstructor()
			->getMock();

		$this->twitterOAuthWrapperStub->expects($this->any())
			->method('connect')
			->will($this->returnValue($this->twitterOAuthStub));

		$fakeApiInfo = array(
			"api_key" => "1234",
			"api_secret" => "5678"
		);

		$this->core = new \Twittering\Core( $fakeApiInfo, $this->utilStub, $this->twitterOAuthWrapperStub );
	}

	protected function tearDown(){
	}

	public function testNoParameters(){
		$this->twitterOAuthStub->expects($this->any())
			->method('getAuthorizeURL')
			->will($this->returnValue("http://fake.url"));

		$this->core->requestTokens();
	}

	public function testURLParameter(){
		$fakeURL = "http://fake.url";
		$fakeTwitterURL = "http://twitter.com/api?u=".$fakeURL;
		$this->twitterOAuthStub->expects($this->any())
			->method('getAuthorizeURL')
			->will($this->returnValue($fakeTwitterURL));

		// Redirect should be called with correct URL
		$this->utilStub->expects($this->once())
			->method('redirect')
			->with( $fakeTwitterURL );

		$redirectURL = $this->core->requestTokens( $fakeURL );

	}

	public function testNoRedirectParameter(){
		$fakeURL = "http://fake.url";
		$fakeTwitterURL = "http://twitter.com/api?u=".$fakeURL;
		$this->twitterOAuthStub->expects($this->any())<commit_msg>Fixes unit tests<commit_after><?php

class CoreRequestTokensTest extends PHPUnit_Framework_TestCase{
	protected function setUp(){
		$_SERVER['HTTPS'] = false;
		$_SERVER['HTTP_HOST'] = "host.com";
		$_SERVER['REQUEST_URI'] = "/uri";

		$this->utilStub = $this->getMockBuilder('Twittering\Util')
		->disableOriginalConstructor()
		->getMock();

		$this->twitterOAuthWrapperStub = $this->getMockBuilder('Twittering\TwitterOAuthWrapper')
			->disableOriginalConstructor()
			->getMock();
		$this->twitterOAuthStub = $this->getMockBuilder('TwitterOAuth')
			->setMethods(array(
				'getRequestToken', 'getAuthorizeURL', 'getAccessToken'
			))
			->disableOriginalConstructor()
			->getMock();

		$this->twitterOAuthWrapperStub->expects($this->any())
			->method('connect')
			->will($this->returnValue($this->twitterOAuthStub));

		$fakeApiInfo = array(
			"api_key" => "1234",
			"api_secret" => "5678"
		);

		$this->core = new \Twittering\Core( $fakeApiInfo, $this->utilStub, $this->twitterOAuthWrapperStub );
	}

	protected function tearDown(){
	}

	public function testNoParameters(){

		$this->twitterOAuthStub->expects($this->any())
			->method('getRequestToken')
			->will($this->returnValue(array(
				"oauth_token" => "1234",
				"oauth_token_secret" => "5678"
			)));

		$this->twitterOAuthStub->expects($this->any())
			->method('getAuthorizeURL')
			->will($this->returnValue("http://fake.url"));

		$this->core->requestTokens();
	}

	public function testURLParameter(){
		$fakeURL = "http://fake.url";
		$fakeTwitterURL = "http://twitter.com/api?u=".$fakeURL;
		$this->twitterOAuthStub->expects($this->any())
			->method('getAuthorizeURL')
			->will($this->returnValue($fakeTwitterURL));

		// Redirect should be called with correct URL
		$this->utilStub->expects($this->once())
			->method('redirect')
			->with( $fakeTwitterURL );

		$redirectURL = $this->core->requestTokens( $fakeURL );

	}

	public function testNoRedirectParameter(){
		$fakeURL = "http://fake.url";
		$fakeTwitterURL = "http://twitter.com/api?u=".$fakeURL;
		$this->twitterOAuthStub->expects($this->any())
{'fraction_non_alphanumeric': 0.19301848049281314, 'fraction_numerical': 0.006160164271047228, 'mean_word_length': 5.117739403453689, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5095998', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1278, 'n_words': 178}