<commit_before><?php

Bundle::start('orchestra');

class RoutingForgotTest extends Orchestra\Testable\TestCase {

	/**
	 * User instance
	 *
	 * @var Orchestra\Model\User
	 */
	private $user = null;

	/**
	 * Setup the test environment.
	 */
	public function setUp()
	{
		parent::setUp();
		$this->user = Orchestra\Model\User::find(1);
	}

	/**
	 * Teardown the test environment.
	 */
	public function tearDown()
	{
		unset($this->user);
		$this->be(null);
		
		parent::tearDown();
	}
	/**
	 * Test Request GET (orchestra)/forgot
	 *
	 * @test
	 */
	public function testGetForgotPage()
	{
		$response = $this->call('orchestra::forgot@index');

		$this->assertInstanceOf('Laravel\Response', $response);
		$this->assertEquals(200, $response->foundation->getStatusCode());
		$this->assertEquals('orchestra::forgot.index', $response->content->view);
	}

	/**
	 * Test Request GET (orchestra)/forgot with auth
	 *
	 * @test
	 */
	public function testGetForgotPageWithAuth()
	{
		$this->be($this->user);

		$response = $this->call('orchestra::forgot@index');

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra'), 
			$response->foundation->headers->get('location'));
	}

	/**
	 * Test Request POST (orchestra)/forgot with invalid csrf
	 *
	 * @test
	 */
	public function testPostForgotPageFailedInvalidCsrf()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email' => '<EMAIL>',
		));

		$this->assertInstanceOf('Laravel\Response', $response);
		$this->assertEquals(500, $response->foundation->getStatusCode());
	}

	/**
	 * Test Request POST (orchestra)/forgot
	 *
	 * @test
	 */
	public function testPostForgotPage()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email'             => '<EMAIL>',
			Session::csrf_token => Session::token(),
		));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::forgot'), 
			$response->foundation->headers->get('location'));

		// Mimic shutting down Orchestra.
		Orchestra\Core::shutdown();

		$meta = Orchestra\Model\User\Meta::where('user_id', '=', 1)
					->where('name', '=', 'reset_password_hash')
					->first();

		$this->assertNotNull($meta);
		$this->assertNotNull($meta->value);
	}

	/**
	 * Test Request GET (orchestra)/forgot/reset/(id)/(hash)
	 *
	 * @test
	 */
	public function testGetResetPasswordPage()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email'             => '<EMAIL>',
			Session::csrf_token => Session::token(),
		));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::forgot'), 
			$response->foundation->headers->get('location'));

		// Mimic restarting Orchestra.
		Orchestra\Core::shutdown();
		Orchestra\Core::start();
		
		$meta = Orchestra\Model\User\Meta::where('user_id', '=', 1)
					->where('name', '=', 'reset_password_hash')
					->first();

		$this->assertNotNull($meta);
		$this->assertNotNull($meta->value);

		$response = $this->call('orchestra::forgot@reset', array(1, $meta->value));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::login'), 
			$response->foundation->headers->get('location'));

		$user = Orchestra\Model\User::find(1);

		$this->assertFalse(Hash::check('<PASSWORD>', $user->password));
	}
}<commit_msg>Improvement to Orchestra\Model unit test.<commit_after><?php

Bundle::start('orchestra');

class RoutingForgotTest extends Orchestra\Testable\TestCase {

	/**
	 * User instance
	 *
	 * @var Orchestra\Model\User
	 */
	private $user = null;

	/**
	 * Setup the test environment.
	 */
	public function setUp()
	{
		parent::setUp();
		$this->user = Orchestra\Model\User::find(1);
	}

	/**
	 * Teardown the test environment.
	 */
	public function tearDown()
	{
		unset($this->user);
		$this->be(null);
		
		parent::tearDown();
	}
	/**
	 * Test Request GET (orchestra)/forgot
	 *
	 * @test
	 */
	public function testGetForgotPage()
	{
		$response = $this->call('orchestra::forgot@index');

		$this->assertInstanceOf('Laravel\Response', $response);
		$this->assertEquals(200, $response->foundation->getStatusCode());
		$this->assertEquals('orchestra::forgot.index', $response->content->view);
	}

	/**
	 * Test Request GET (orchestra)/forgot with auth
	 *
	 * @test
	 */
	public function testGetForgotPageWithAuth()
	{
		$this->be($this->user);

		$response = $this->call('orchestra::forgot@index');

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra'), 
			$response->foundation->headers->get('location'));
	}

	/**
	 * Test Request POST (orchestra)/forgot with invalid csrf
	 *
	 * @test
	 */
	public function testPostForgotPageFailedInvalidCsrf()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email' => '<EMAIL>',
		));

		$this->assertInstanceOf('Laravel\Response', $response);
		$this->assertEquals(500, $response->foundation->getStatusCode());
	}

	/**
	 * Test Request POST (orchestra)/forgot
	 *
	 * @test
	 */
	public function testPostForgotPage()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email'             => '<EMAIL>',
			Session::csrf_token => Session::token(),
		));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::forgot'), 
			$response->foundation->headers->get('location'));

		// Mimic shutting down Orchestra.
		Orchestra\Core::shutdown();

		$meta = Orchestra\Model\User\Meta::where('user_id', '=', 1)
					->where('name', '=', 'reset_password_hash')
					->first();

		$this->assertNotNull($meta);
		$this->assertNotNull($meta->value);
	}

	/**
	 * Test Request GET (orchestra)/forgot/reset/(id)/(hash)
	 *
	 * @test
	 */
	public function testGetResetPasswordPage()
	{
		$response = $this->call('orchestra::forgot@index', array(), 'POST', array(
			'email'             => '<EMAIL>',
			Session::csrf_token => Session::token(),
		));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::forgot'), 
			$response->foundation->headers->get('location'));

		// Mimic restarting Orchestra.
		Orchestra\Core::shutdown();
		Orchestra\Core::start();
		
		$meta = Orchestra\Model\User\Meta::where('user_id', '=', 1)
					->where('name', '=', 'reset_password_hash')
					->first();

		$this->assertNotNull($meta);
		$this->assertNotNull($meta->value);

		$user = $meta->users()->first();

		$this->assertEquals(1, $user->id);

		$response = $this->call('orchestra::forgot@reset', array(1, $meta->value));

		$this->assertInstanceOf('Laravel\Redirect', $response);
		$this->assertEquals(302, $response->foundation->getStatusCode());
		$this->assertEquals(handles('orchestra::login'), 
			$response->foundation->headers->get('location'));

		$user = Orchestra\Model\User::find(1);

		$this->assertFalse(Hash::check('<PASSWORD>', $user->password));
	}
}
{'fraction_non_alphanumeric': 0.20385232744783308, 'fraction_numerical': 0.0062867843766720175, 'mean_word_length': 4.604947526236882, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 159, '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': '336427', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2423, 'n_words': 360}