<commit_before><?php

namespace Spatie\PaginateRoute\Test;

class PaginateRouteTest extends TestCase
{
    /**
     * @test
     */
    public function it_returns_models_without_querying_a_page_number()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertNotEmpty($response['models']['data']);
        $this->assertEquals(1, $response['models']['current_page']);
    }

    /**
     * @test
     */
    public function it_returns_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/1');

        $models = $response['models']['data'];

        $this->assertNotEmpty($models);
        $this->assertContains(['id' => '1', 'name' => 'Dummy 1'], $models);
        $this->assertContains(['id' => '5', 'name' => 'Dummy 5'], $models);
        $this->assertNotContains(['id' => '6', 'name' => 'Dummy 6'], $models);

        $this->assertEquals(1, $response['models']['current_page']);
    }

    /**
     * @test
     * @group foo
     */
    public function it_returns_the_second_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/2');

        $models = $response['models']['data'];

        $this->assertNotEmpty($models);
        $this->assertNotContains(['id' => '5', 'name' => 'Dummy 5'], $models);
        $this->assertContains(['id' => '6', 'name' => 'Dummy 6'], $models);
        $this->assertContains(['id' => '10', 'name' => 'Dummy 10'], $models);
        $this->assertNotContains(['id' => '11', 'name' => 'Dummy 11'], $models);

        $this->assertEquals(2, $response['models']['current_page']);
    }

    /**
     * @test
     */
    public function it_returns_a_previous_page_url()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/3');

        $this->assertTrue($response['hasPrevious']);
        $this->assertEquals($this->hostName.'/dummies/page/2', $response['previousPageUrl']);
    }

    /**
     * @test
     */
    public function it_doesnt_return_a_previous_page_url_on_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertFalse($response['hasPrevious']);
    }

    /**
     * @test
     */
    public function it_returns_a_pretty_previous_page_url_for_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/2');

        $this->assertTrue($response['hasPrevious']);
        $this->assertEquals($this->hostName.'/dummies', $response['previousPageUrl']);
    }

    /**
     * @test
     */
    public function it_returns_a_next_page_url()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertTrue($response['hasNext']);
        $this->assertEquals($this->hostName.'/dummies/page/2', $response['nextPageUrl']);
    }

    /**
     * @test
     */
    public function it_doesnt_return_a_next_page_url_on_the_last_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/4');

        $this->assertFalse($response['hasNext']);
        $this->assertNull($response['nextPageUrl']);
    }

    /**
     * @test
     */
    public function it_returns_all_urls()
    {
        $this->app['router']->paginate('dummies', function () {
            $dummies = Dummy::paginate(5);
            $paginateRoute = $this->app['paginateroute'];

            return [
                'allUrls' => $this->app['paginateroute']->allUrls($dummies),
                'allUrlsFull' => $this->app['paginateroute']->allUrls($dummies, true),
            ];
        });

        $response = $this->callRoute('/');

        $allUrls = [
            $this->hostName.'/dummies',
            $this->hostName.'/dummies/page/2',
            $this->hostName.'/dummies/page/3',
            $this->hostName.'/dummies/page/4',
        ];

        $this->assertEquals($allUrls, $response['allUrls']);

        $allUrlsFull = $allUrls;
        $allUrlsFull[0] = $this->hostName.'/dummies/page/1';

        $this->assertEquals($allUrlsFull, $response['allUrlsFull']);
    }

    /**
     * @test
     */
    public function it_renders_an_html_list()
    {<commit_msg>Creating method to test the left and right point<commit_after><?php

namespace Spatie\PaginateRoute\Test;

class PaginateRouteTest extends TestCase
{
    /**
     * @test
     */
    public function it_returns_models_without_querying_a_page_number()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertNotEmpty($response['models']['data']);
        $this->assertEquals(1, $response['models']['current_page']);
    }

    /**
     * @test
     */
    public function it_returns_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/1');

        $models = $response['models']['data'];

        $this->assertNotEmpty($models);
        $this->assertContains(['id' => '1', 'name' => 'Dummy 1'], $models);
        $this->assertContains(['id' => '5', 'name' => 'Dummy 5'], $models);
        $this->assertNotContains(['id' => '6', 'name' => 'Dummy 6'], $models);

        $this->assertEquals(1, $response['models']['current_page']);
    }

    /**
     * @test
     * @group foo
     */
    public function it_returns_the_second_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/2');

        $models = $response['models']['data'];

        $this->assertNotEmpty($models);
        $this->assertNotContains(['id' => '5', 'name' => 'Dummy 5'], $models);
        $this->assertContains(['id' => '6', 'name' => 'Dummy 6'], $models);
        $this->assertContains(['id' => '10', 'name' => 'Dummy 10'], $models);
        $this->assertNotContains(['id' => '11', 'name' => 'Dummy 11'], $models);

        $this->assertEquals(2, $response['models']['current_page']);
    }

    /**
     * @test
     */
    public function it_returns_a_previous_page_url()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/3');

        $this->assertTrue($response['hasPrevious']);
        $this->assertEquals($this->hostName.'/dummies/page/2', $response['previousPageUrl']);
    }

    /**
     * @test
     */
    public function it_doesnt_return_a_previous_page_url_on_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertFalse($response['hasPrevious']);
    }

    /**
     * @test
     */
    public function it_returns_a_pretty_previous_page_url_for_the_first_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/2');

        $this->assertTrue($response['hasPrevious']);
        $this->assertEquals($this->hostName.'/dummies', $response['previousPageUrl']);
    }

    /**
     * @test
     */
    public function it_returns_a_next_page_url()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/');

        $this->assertTrue($response['hasNext']);
        $this->assertEquals($this->hostName.'/dummies/page/2', $response['nextPageUrl']);
    }

    /**
     * @test
     */
    public function it_doesnt_return_a_next_page_url_on_the_last_page()
    {
        $this->registerDefaultRoute();

        $response = $this->callRoute('/page/4');

        $this->assertFalse($response['hasNext']);
        $this->assertNull($response['nextPageUrl']);
    }

    /**
     * @test
     */
    public function it_returns_all_urls()
    {
        $this->app['router']->paginate('dummies', function () {
            $dummies = Dummy::paginate(5);
            $paginateRoute = $this->app['paginateroute'];

            return [
                'allUrls' => $this->app['paginateroute']->allUrls($dummies),
                'allUrlsFull' => $this->app['paginateroute']->allUrls($dummies, true),
            ];
        });

        $response = $this->callRoute('/');

        $allUrls = [
            $this->hostName.'/dummies',
            $this->hostName.'/dummies/page/2',
            $this->hostName.'/dummies/page/3',
            $this->hostName.'/dummies/page/4',
        ];

        $this->assertEquals($allUrls, $response['allUrls']);

        $allUrlsFull = $allUrls;
        $allUrlsFull[0] = $this->hostName.'/dummies/page/1';

        $this->assertEquals($allUrlsFull, $response['allUrlsFull']);
    }
    
    /**
     * @test
     */
    public function it_returns_limited_urls_with_on_each_side()
    { 
        $this->app['router']->paginate('dummies', function () {
            $dummies = Dummy::paginate(5)->onEachSide(5);
            $paginateRoute = $this->app['paginateroute'];

            return [
                'allUrls' => $this->app['paginateroute']->allUrls($dummies),
                'allUrlsFull' => $this->app['paginateroute']->allUrls($dummies, true),
            ];
        });

        $response = $this->callRoute('/');

        // 5 items plus 5 on the side and 1 current item = 11 items visible
        $allUrls = [
            $this->hostName.'/dummies',
            $this->hostName.'/dummies/page/2',
            $this->hostName.'/dummies/page/3',
            $this->hostName.'/dummies/page/4',
            $this->hostName.'/dummies/page/5',
            $this->hostName.'/dummies/page/6',
            $this->hostName.'/dummies/page/7',
            $this->hostName.'/dummies/page/8',
            $this->hostName.'/dummies/page/9',
            $this->hostName.'/dummies/page/10',
            $this->hostName.'/dummies/page/11',
        ];

        $this->assertEquals($allUrls, $response['allUrls']);

        $allUrlsFull = $allUrls;
        $allUrlsFull[0] = $this->hostName.'/dummies/page/1';

        $this->assertEquals($allUrlsFull, $response['allUrlsFull']);
    }
    
    /**
     * @test
     */
    public function it_return_zero_on_left_and_ten_on_right_with_on_each_side()
    {
        $this->registerDefaultRouteWithEachSide();

        $response = $this->callRoute('/page/1');
        
        $this->assertEquals($response['leftPoint'], 1);
        $this->assertEquals($response['rightPoint'], 11);
    }
    
    /**
     * @test
     */
    public function it_return_five_on_left_and_five_on_right_with_on_each_side()
    {
        $this->registerDefaultRouteWithEachSide();
        $response = $this->callRoute('/page/6');

        $this->assertEquals($response['leftPoint'], 1);
        $this->assertEquals($response['rightPoint'], 11);
    }
    
    /**
     * @test
     */
    public function it_return_ten_on_left_and_zero_on_right_with_on_each_side()
    {
        $this->registerDefaultRouteWithEachSide();
        $dummies = Dummy::paginate(5)->onEachSide(5);
        $end = $dummies->lastPage();
        $response = $this->callRoute('/page/' . $end);

        $this->assertEquals($response['leftPoint'], $end - 10);
        $this->assertEquals($response['rightPoint'], $end);
    }

    /**
     * @test
     */
    public function it_renders_an_html_list()
    {
{'fraction_non_alphanumeric': 0.18786569448195156, 'fraction_numerical': 0.00909172742821136, 'mean_word_length': 2.492612386042125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 186, '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': '6483340', 'n_tokens_mistral': 3588, 'n_tokens_neox': 3472, 'n_words': 433}