Commit 10964714 authored by catch's avatar catch

Issue #2598436 by dawehner, krknth, kostyashupenko: Rewrite the Result class...

Issue #2598436 by dawehner, krknth, kostyashupenko: Rewrite the Result class to no longer accidentally be removed by people
parent 4c643ffc
......@@ -104,11 +104,15 @@ public function render($empty = FALSE) {
}
$current_record_count = ($end - $start) + 1;
// Get the search information.
$items = array('start', 'end', 'total', 'label', 'per_page', 'current_page', 'current_record_count', 'page_count');
$replacements = array();
foreach ($items as $item) {
$replacements["@$item"] = ${$item};
}
$replacements = [];
$replacements['@start'] = $start;
$replacements['@end'] = $end;
$replacements['@total'] = $total;
$replacements['@label'] = $label;
$replacements['@per_page'] = $per_page;
$replacements['@current_page'] = $current_page;
$replacements['@current_record_count'] = $current_record_count;
$replacements['@page_count'] = $page_count;
// Send the output.
if (!empty($total)) {
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $format));
......
......@@ -7,9 +7,15 @@
namespace Drupal\Tests\views\Unit\Plugin\area;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\area\Result;
use Drupal\views\ViewsData;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\views\Plugin\views\area\Result
......@@ -34,22 +40,16 @@ class ResultTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$storage = $this->getMockBuilder('Drupal\views\Entity\View')
->disableOriginalConstructor()
->setMethods(array('label'))
->getMock();
$storage->expects($this->any())
->method('label')
->will($this->returnValue('ResultTest'));
$user = $this->getMock('Drupal\Core\Session\AccountInterface');
$views_data = $this->getMockBuilder('Drupal\views\ViewsData')
->disableOriginalConstructor()
->getMock();
$route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
$this->view = new ViewExecutable($storage, $user, $views_data, $route_provider);
$this->resultHandler = new Result(array(), 'result', array());
$storage = $this->prophesize(View::class);
$storage->label()->willReturn('ResultTest');
$storage->set(Argument::cetera())->willReturn(NULL);
$user = $this->prophesize(AccountInterface::class)->reveal();
$views_data = $this->prophesize(ViewsData::class)->reveal();
$route_provider = $this->prophesize(RouteProviderInterface::class)->reveal();
$this->view = new ViewExecutable($storage->reveal(), $user, $views_data, $route_provider);
$this->resultHandler = new Result([], 'result', []);
$this->resultHandler->view = $this->view;
}
......@@ -121,18 +121,15 @@ public function providerTestResultArea() {
* The value to return from getItemsPerPage().
*/
protected function setupViewPager($items_per_page = 0) {
$pager = $this->getMockBuilder('Drupal\views\Plugin\views\pager\PagerPluginBase')
->disableOriginalConstructor()
->setMethods(array('getItemsPerPage', 'getCurrentPage'))
->getMock();
$pager->expects($this->once())
->method('getItemsPerPage')
->will($this->returnValue($items_per_page));
$pager->expects($this->once())
->method('getCurrentPage')
->will($this->returnValue(0));
$this->view->pager = $pager;
$pager = $this->prophesize(PagerPluginBase::class);
$pager->getItemsPerPage()
->willReturn($items_per_page)
->shouldBeCalledTimes(1);
$pager->getCurrentPage()
->willReturn(0)
->shouldBeCalledTimes(1);
$this->view->pager = $pager->reveal();
$this->view->style_plugin = new \stdClass();
$this->view->total_rows = 100;
$this->view->result = array(1, 2, 3, 4, 5);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment