/** * Check if paginate works as expected. */ public function testPaginate() { $container = self::createClient()->getContainer(); $counter = new CountAdapter(10); $pagerService = new PagerService($counter); $pagerService->setLimit(2); $pagerService->setPage(2); /** @var \Twig_Environment $environment */ $environment = $container->get('twig'); $environment->setLoader(new \Twig_Loader_String()); $paginateTemplate = '{{ ongr_paginate_path(route, pager.getFirstPage, parameters) }} {{ ongr_paginate_path(route, pager.getLastPage, parameters) }}'; $mainTemplate = "{{ ongr_paginate(pager, 'test_page', [], '" . $paginateTemplate . "') }}"; $result = trim($environment->render($mainTemplate, ['pager' => $pagerService])); $this->assertStringStartsWith('/', $result); $this->assertStringEndsWith('/?page=5', $result); }
/** * Tests getOffset method. * * @param int $page Current page. * @param int $limit Max count of results per page. * @param int $expected Expected result. * * @dataProvider getTestGetOffsetData */ public function testGetOffset($page, $limit, $expected) { $mockPagerAdapter = $this->getPagerAdapterMock(); $pager = new PagerService($mockPagerAdapter, ['page' => $page, 'limit' => $limit]); $result = $pager->getOffset(); $this->assertEquals($expected, $result); }