public function t1estQueryBuilderPaginator() { $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula')->limit(500, 0); //var_dump($builder->getPhql()); return; $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_pages, 218); //Middle page $paginator->setCurrentPage(100); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 99); $this->assertEquals($page->next, 101); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 100); $this->assertEquals($page->total_pages, 218); //Last page $paginator->setCurrentPage(218); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 217); $this->assertEquals($page->next, 218); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 218); $this->assertEquals($page->total_pages, 218); }
public function testQueryBuilderPaginator() { require 'unit-tests/config.db.php'; if (empty($configMysql)) { $this->markTestSkipped('Test skipped'); return; } $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_pages, 218); //Middle page $paginator->setCurrentPage(100); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 99); $this->assertEquals($page->next, 101); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 100); $this->assertEquals($page->total_pages, 218); //Last page $paginator->setCurrentPage(218); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 217); $this->assertEquals($page->next, 218); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 218); $this->assertEquals($page->total_pages, 218); // test of getter/setters of querybuilder adapter // -- current page -- $currentPage = $paginator->getCurrentPage(); $this->assertEquals($currentPage, 218); // -- limit -- $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 10); $setterResult = $paginator->setLimit(25); $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 25); $this->assertEquals($setterResult, $paginator); // -- builder -- $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder, $queryBuilder); $builder2 = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes'); $setterResult = $paginator->setQueryBuilder($builder2); $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder2, $queryBuilder); $this->assertEquals($setterResult, $paginator); // test raw value $builder = $di['modelsManager']->createBuilder()->columns('*')->from('Personnes')->where('tipo_documento_id = :tipo_documento_id:', array('tipo_documento_id' => 1))->andWhere('estado = :estado:', array('estado' => new Phalcon\Db\RawValue("'A'")))->orderBy('cedula'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertTrue(count($page->items) > 0); $this->assertEquals($page->current, 1); $this->assertTrue($page->total_pages > 0); $bind_params = array('rawsql' => new Phalcon\Db\RawValue('tipo_documento_id=1')); $bind_types = array('rawsql' => PDO::PARAM_STR); $users = $di->modelsManager->createBuilder()->from('Personnes')->andwhere(":rawsql:", $bind_params, $bind_types); $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $users, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals($bind_params, array('rawsql' => new Phalcon\Db\RawValue('tipo_documento_id=1'))); $this->assertEquals($bind_types, array('rawsql' => PDO::PARAM_STR)); $bind_params = array('rawsql' => new Phalcon\Db\RawValue('tipo_documento_id=1'), 'estado' => 'A'); $bind_types = array('rawsql' => PDO::PARAM_STR, 'estado' => PDO::PARAM_STR); $users = $di->modelsManager->executeQuery("SELECT * FROM Personnes WHERE :rawsql: AND estado = :estado: LIMIT 2", $bind_params, $bind_types); $this->assertEquals($bind_params, array('rawsql' => new Phalcon\Db\RawValue('tipo_documento_id=1'), 'estado' => 'A')); $this->assertEquals($bind_types, array('rawsql' => PDO::PARAM_STR, 'estado' => PDO::PARAM_STR)); }
public function testQueryBuilderPaginatorGroupBy() { require 'unit-tests/config.db.php'; if (empty($configMysql)) { $this->markTestSkipped('Test skipped'); return; } $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula')->groupBy(['email']); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 18); $this->assertEquals($page->limit, 10); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_items, 178); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Middle page $paginator->setCurrentPage(10); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 9); $this->assertEquals($page->next, 11); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 10); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Last page $paginator->setCurrentPage(18); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 9); $this->assertEquals($page->before, 17); $this->assertEquals($page->next, 18); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 18); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); // test of getter/setters of querybuilder adapter // -- current page -- $currentPage = $paginator->getCurrentPage(); $this->assertEquals($currentPage, 18); // -- limit -- $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 10); $setterResult = $paginator->setLimit(25); $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 25); $this->assertEquals($setterResult, $paginator); // -- builder -- $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder, $queryBuilder); $builder2 = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->groupBy(['email']); $setterResult = $paginator->setQueryBuilder($builder2); $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder2, $queryBuilder); $this->assertEquals($setterResult, $paginator); }
private function _paginatorBuilderTest($builder) { $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 18); $this->assertEquals($page->limit, 10); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_items, 178); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Middle page $paginator->setCurrentPage(10); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 9); $this->assertEquals($page->next, 11); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 10); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Last page $paginator->setCurrentPage(18); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 9); $this->assertEquals($page->before, 17); $this->assertEquals($page->next, 18); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 18); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); }