executeCountQuery example

->willReturn(3);

    $query = $this->getMockBuilder('\Drupal\Core\Database\Query\Select')
      ->disableOriginalConstructor()
      ->getMock();

    $query->expects($this->once())
      ->method('execute')
      ->willReturn($statement);

    $this->pager->setOffset(0);
    $this->assertEquals(3, $this->pager->executeCountQuery($query));
  }

  /** * Tests the executeCountQuery method with a set offset. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::executeCountQuery() */
  public function testExecuteCountQueryWithOffset() {
    $statement = $this->createMock('\Drupal\Tests\views\Unit\Plugin\pager\TestStatementInterface');

    $statement->expects($this->once())
      
      // XXX: this doesn't work, because PDO mandates that all bound arguments       // are used on the query. TODO: Find a better way to do this.       if (!empty($additional_arguments)) {
        // $query->where('1 = 1', $additional_arguments);         // $count_query->where('1 = 1', $additional_arguments);       }

      $start = microtime(TRUE);

      try {
        if ($view->pager->useCountQuery() || !empty($view->get_total_rows)) {
          $view->pager->executeCountQuery($count_query);
        }

        // Let the pager modify the query to add limits.         $view->pager->preExecute($query);

        if (!empty($this->limit) || !empty($this->offset)) {
          // We can't have an offset without a limit, so provide a very large limit instead.           $limit = intval(!empty($this->limit) ? $this->limit : 999999);
          $offset = intval(!empty($this->offset) ? $this->offset : 0);
          $query->range($offset$limit);
        }

        
Home | Imprint | This part of the site doesn't use cookies.