useCountQuery example

'options' => [
        'offset' => 3,
      ],
    ];
    $view->display_handler->setOption('pager', $pager);
    $this->executeView($view);

    $this->assertCount(8, $view->result, 'Make sure that every item beside the first three is returned in the result');

    // Check some public functions.     $this->assertFalse($view->pager->usePager());
    $this->assertFalse($view->pager->useCountQuery());
    $this->assertEquals(0, $view->pager->getItemsPerPage());
  }

  public function testViewTotalRowsWithoutPager() {
    $this->drupalCreateContentType(['type' => 'page']);
    for ($i = 0; $i < 23; $i++) {
      $this->drupalCreateNode();
    }

    $view = Views::getView('test_pager_none');
    $view->get_total_rows = TRUE;
    

  public function testUsePager() {
    $this->assertTrue($this->pager->usePager());
  }

  /** * Tests the useCountQuery() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::useCountQuery() */
  public function testUseCountQuery() {
    $this->assertTrue($this->pager->useCountQuery());
  }

  /** * Tests the usesExposed() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::usedExposed() */
  public function testUsesExposed() {
    $this->assertFalse($this->pager->usesExposed());
  }

  
// Add additional arguments as a fake condition.       // 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.