<commit_before><?php

namespace Illuminate\Tests\Routing;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Routing\Redirector;

class RoutingRedirectorTest extends TestCase
{
    protected $headers;
    protected $request;
    protected $url;
    protected $session;
    protected $redirect;

    public function setUp()
    {
        $this->headers = m::mock('Symfony\Component\HttpFoundation\HeaderBag');

        $this->request = m::mock('Illuminate\Http\Request');
        $this->request->headers = $this->headers;

        $this->url = m::mock('Illuminate\Routing\UrlGenerator');
        $this->url->shouldReceive('getRequest')->andReturn($this->request);
        $this->url->shouldReceive('to')->with('bar', [], null)->andReturn('http://foo.com/bar');
        $this->url->shouldReceive('to')->with('bar', [], true)->andReturn('https://foo.com/bar');
        $this->url->shouldReceive('to')->with('login', [], null)->andReturn('http://foo.com/login');
        $this->url->shouldReceive('to')->with('http://foo.com/bar', [], null)->andReturn('http://foo.com/bar');
        $this->url->shouldReceive('to')->with('/', [], null)->andReturn('http://foo.com/');

        $this->session = m::mock('Illuminate\Session\Store');

        $this->redirect = new Redirector($this->url);
        $this->redirect->setSession($this->session);
    }

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

    public function testBasicRedirectTo()
    {
        $response = $this->redirect->to('bar');

        $this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response);
        $this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
        $this->assertEquals(302, $response->getStatusCode());
        $this->assertEquals($this->session, $response->getSession());
    }

    public function testComplexRedirectTo()
    {
        $response = $this->redirect->to('bar', 303, ['X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 59], true);

        $this->assertEquals('https://foo.com/bar', $response->getTargetUrl());
        $this->assertEquals(303, $response->getStatusCode());
        $this->assertEquals(60, $response->headers->get('X-RateLimit-Limit'));
        $this->assertEquals(59, $response->headers->get('X-RateLimit-Remaining'));
    }

    public function testGuestPutCurrentUrlInSession()
    {
        $this->url->shouldReceive('full')->andReturn('http://foo.com/bar');
        $this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');

        $response = $this->redirect->guest('login');

        $this->assertEquals('http://foo.com/login', $response->getTargetUrl());
    }

    public function testIntendedRedirectToIntendedUrlInSession()
    {
        $this->session->shouldReceive('pull')->with('url.intended', '/')->andReturn('http://foo.com/bar');
<commit_msg>#25196: Test intended fallback behavior.<commit_after><?php

namespace Illuminate\Tests\Routing;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Routing\Redirector;

class RoutingRedirectorTest extends TestCase
{
    protected $headers;
    protected $request;
    protected $url;
    protected $session;
    protected $redirect;

    public function setUp()
    {
        $this->headers = m::mock('Symfony\Component\HttpFoundation\HeaderBag');

        $this->request = m::mock('Illuminate\Http\Request');
        $this->request->headers = $this->headers;

        $this->url = m::mock('Illuminate\Routing\UrlGenerator');
        $this->url->shouldReceive('getRequest')->andReturn($this->request);
        $this->url->shouldReceive('to')->with('bar', [], null)->andReturn('http://foo.com/bar');
        $this->url->shouldReceive('to')->with('bar', [], true)->andReturn('https://foo.com/bar');
        $this->url->shouldReceive('to')->with('login', [], null)->andReturn('http://foo.com/login');
        $this->url->shouldReceive('to')->with('http://foo.com/bar', [], null)->andReturn('http://foo.com/bar');
        $this->url->shouldReceive('to')->with('/', [], null)->andReturn('http://foo.com/');

        $this->session = m::mock('Illuminate\Session\Store');

        $this->redirect = new Redirector($this->url);
        $this->redirect->setSession($this->session);
    }

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

    public function testBasicRedirectTo()
    {
        $response = $this->redirect->to('bar');

        $this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response);
        $this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
        $this->assertEquals(302, $response->getStatusCode());
        $this->assertEquals($this->session, $response->getSession());
    }

    public function testComplexRedirectTo()
    {
        $response = $this->redirect->to('bar', 303, ['X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 59], true);

        $this->assertEquals('https://foo.com/bar', $response->getTargetUrl());
        $this->assertEquals(303, $response->getStatusCode());
        $this->assertEquals(60, $response->headers->get('X-RateLimit-Limit'));
        $this->assertEquals(59, $response->headers->get('X-RateLimit-Remaining'));
    }

    public function testGuestPutCurrentUrlInSession()
    {
        $this->url->shouldReceive('full')->andReturn('http://foo.com/bar');
        $this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');

        $response = $this->redirect->guest('login');

        $this->assertEquals('http://foo.com/login', $response->getTargetUrl());
    }

    public function testGuestPutPreviousUrlInSession()
    {
        $this->request->shouldReceive('method')->andReturn('POST');
        $this->session->shouldReceive('get')->once()->with('_previous.url')->andReturn('http://foo.com/bar');
        $this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');

        $response = $this->redirect->guest('login');

        $this->assertEquals('http://foo.com/login', $response->getTargetUrl());
    }

    public function testIntendedRedirectToIntendedUrlInSession()
    {
        $this->session->shouldReceive('pull')->with('url.intended', '/')->andReturn('http://foo.com/bar');

{'fraction_non_alphanumeric': 0.20992611628654032, 'fraction_numerical': 0.006264053967234179, 'mean_word_length': 3.6366344005956814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 169, 'https://': 4, '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': '5987700', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1800, 'n_words': 223}