<commit_before><?php

namespace Phalcon\Tests\Paginator;

use PHPUnit_Framework_TestCase as TestCase;
use Phalcon\Paginator\Pager;
use stdClass;

/**
 * \Phalcon\Tests\Paginator\PagerTest
 * Tests the Phalcon\Paginator\Pager component
 *
 * @copyright (c) 2011-2015 Phalcon Team
 * @link      http://www.phalconphp.com
 * @author    <NAME> <<EMAIL>>
 * @package   Phalcon\Tests\Paginator
 *
 * The contents of this file are subject to the New BSD License that is
 * bundled with this package in the file docs/LICENSE.txt
 *
 * If you did not receive a copy of the license and are unable to obtain it
 * through the world-wide-web, please send an email to <EMAIL>
 * so that we can send you a copy immediately.
 */
class PagerTest extends TestCase
{
    const BUILDER_CLASS = 'Phalcon\Paginator\Adapter\QueryBuilder';

    public function testCreatingPagerObjectWithoutOptionsShouldConstructObject()
    {
        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)
            ->disableOriginalConstructor()
            ->getMock();

        $pager = new Pager($adapter);
        $this->assertInstanceOf('Phalcon\Paginator\Pager', $pager);
    }

    public function testCallingGetPagesInRangeMethodWithDefaultOptionsShouldReturnExpectedArray()
    {
        // stub paginate
        $paginate = new stdClass();
        $paginate->total_pages = 20;
        $paginate->current = 5;
        $paginate->last = 20;

        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)
            ->disableOriginalConstructor()
            ->setMethods(array('getPaginate'))
            ->getMock();
        $adapter->expects($this->once())
            ->method('getPaginate')
            ->will($this->returnValue($paginate));

        $pager = new Pager($adapter);
        $this->assertEquals(
            array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
            $pager->getPagesInRange()
        );
    }

    public function testCallingGetPagesInRangeMethodWithSliderOnEndShouldReturnExpectedArray()
    {
        // stub paginate
        $paginate = new stdClass();
        $paginate->total_pages = 20;
        $paginate->current = 20;
        $paginate->last = 20;

        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)<commit_msg>Code coverage 100% for Pager test<commit_after><?php

namespace Phalcon\Tests\Paginator;

use PHPUnit_Framework_TestCase as TestCase;
use Phalcon\Paginator\Pager;
use stdClass;

/**
 * \Phalcon\Tests\Paginator\PagerTest
 * Tests the Phalcon\Paginator\Pager component
 *
 * @copyright (c) 2011-2015 Phalcon Team
 * @link      http://www.phalconphp.com
 * @author    <NAME> <<EMAIL>>
 * @package   Phalcon\Tests\Paginator
 *
 * The contents of this file are subject to the New BSD License that is
 * bundled with this package in the file docs/LICENSE.txt
 *
 * If you did not receive a copy of the license and are unable to obtain it
 * through the world-wide-web, please send an email to <EMAIL>
 * so that we can send you a copy immediately.
 */
class PagerTest extends TestCase
{
    const BUILDER_CLASS = 'Phalcon\Paginator\Adapter\QueryBuilder';

    public function testCreatingPagerObjectWithoutOptionsShouldConstructObject()
    {
        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)
            ->disableOriginalConstructor()
            ->getMock();

        $pager = new Pager($adapter);
        $this->assertInstanceOf('Phalcon\Paginator\Pager', $pager);
    }

    public function testCallingGetPagesInRangeMethodWithDefaultOptionsShouldReturnExpectedArray()
    {
        // stub paginate
        $paginate = new stdClass();
        $paginate->total_pages = 20;
        $paginate->current = 5;
        $paginate->last = 20;

        $defaultLimit = null;

        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)
            ->disableOriginalConstructor()
            ->setMethods(array('getPaginate', 'getLimit'))
            ->getMock();

        $adapter->expects($this->once())
            ->method('getPaginate')
            ->will($this->returnValue($paginate));

        $adapter->expects($this->once())
            ->method('getLimit')
            ->will($this->returnValue($defaultLimit));

        $pager = new Pager($adapter);
        $this->assertEquals(
            array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
            $pager->getPagesInRange()
        );

        $this->assertEquals(null, $pager->getLimit());
    }

    public function testCallingGetPagesInRangeMethodWithSliderOnEndShouldReturnExpectedArray()
    {
        // stub paginate
        $paginate = new stdClass();
        $paginate->total_pages = 20;
        $paginate->current = 20;
        $paginate->last = 20;

        $adapter = $this->getMockBuilder(self::BUILDER_CLASS)
{'fraction_non_alphanumeric': 0.11852166525063722, 'fraction_numerical': 0.013381478334749362, 'mean_word_length': 2.8160453808752024, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1066645', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1381, 'n_words': 324}