示例#1
0
 /**
  * Renders the counter field handler.
  *
  * @param \Drupal\views\Plugin\views\field\Counter $handler
  *   The counter handler.
  * @param \Drupal\views\ResultRow $row
  *   A result row.
  *
  * @return string
  *   The counter rendered markup.
  */
 protected function renderCounter(Counter $handler, ResultRow $row)
 {
     $markup = $handler->render($row);
     $handler->postRender($row, $markup);
     return $handler->last_render;
 }
 /**
  * Tests a counter field on the second page.
  *
  * @param int $i
  *   The row index to test.
  *
  * @dataProvider providerRowIndexes
  */
 public function testCounterSecondPage($i)
 {
     $offset = 3;
     // Setup a pager on the second page.
     $this->pager->setOffset($offset);
     $items_per_page = 5;
     $this->pager->setItemsPerPage($items_per_page);
     $current_page = 1;
     $this->pager->setCurrentPage($current_page);
     $rand_start = rand(5, 10);
     $counter_handler = new Counter(array(), 'counter', $this->definition);
     $options = array('counter_start' => $rand_start);
     $counter_handler->init($this->view, $this->display, $options);
     $this->view->row_index = $i;
     $expected = $items_per_page + $offset + $rand_start + $i;
     $counter = $counter_handler->getValue($this->testData[$i]);
     $this->assertEquals($expected, $counter, String::format('The expected number (@expected) patches with the rendered number (@counter) failed', array('@expected' => $expected, '@counter' => $counter)));
     $counter = $counter_handler->render($this->testData[$i]);
     $this->assertEquals($expected, $counter_handler->render($this->testData[$i]), String::format('The expected number (@expected) patches with the rendered number (@counter) failed', array('@expected' => $expected, '@counter' => $counter)));
 }