Commit 349b678e authored by catch's avatar catch

Issue #2589703 by dawehner, geertvd: Override number of items to display in...

Issue #2589703 by dawehner, geertvd: Override number of items to display in contextual filter doesn't work
parent f6052ec6
......@@ -210,6 +210,13 @@ public function testArchiveView() {
),
);
$this->assertIdenticalResultset($view, $expected_result, $column_map);
$view->storage->setStatus(TRUE);
$view->save();
\Drupal::service('router.builder')->rebuild();
$this->drupalGet('archive');
$this->assertResponse(200);
}
}
<?php
/**
* @file
* Contains \Drupal\views\Tests\Plugin\StyleSummaryTest.
*/
namespace Drupal\views\Tests\Plugin;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests the summary style plugin.
*
* @group views
*/
class StyleSummaryTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_summary'];
/**
* @var \Drupal\entity_test\Entity\EntityTest[]
*/
protected $entities = [];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create 5 entities per bundle, to allow a summary overview per bundle.
for ($i = 0; $i < 5; $i++) {
for ($j = 0; $j < 5; $j++) {
$this->entities[] = $entity = EntityTest::create([
'name' => 'Entity ' . ($i * 5 + $j),
'type' => 'type' . $i,
]);
$entity->save();
}
}
}
/**
* Tests a summary view.
*/
public function testSummaryView() {
$this->drupalGet('test-summary');
$summary_list = $this->cssSelect('ul.views-summary li');
$this->assertEqual(4, count($summary_list));
foreach ($summary_list as $summary_list_item) {
$this->assertEqual('(5)', trim((string) $summary_list_item));
}
$summary_links = $this->cssSelect('ul.views-summary a');
$this->assertEqual(4, count($summary_links));
foreach ($summary_links as $index => $summary_link) {
$this->assertEqual('type' . $index, trim((string) $summary_link));
}
$this->clickLink('type1');
$entries = $this->cssSelect('div.view-content div.views-row');
$this->assertEqual(2, count($entries));
}
}
......@@ -18,7 +18,7 @@ abstract class StyleTestBase extends ViewKernelTestBase {
/**
* Stores the SimpleXML representation of the output.
*
* @var SimpleXMLElement
* @var \SimpleXMLElement
*/
protected $elements;
......
......@@ -553,7 +553,11 @@ public function getItemsPerPage() {
* The items per page.
*/
public function setItemsPerPage($items_per_page) {
$this->element['#cache']['keys'][] = 'items_per_page:' . $items_per_page;
// Check whether the element is pre rendered. At that point, the cache keys
// cannot longer be manipulated.
if (empty($this->element['#pre_rendered'])) {
$this->element['#cache']['keys'][] = 'items_per_page:' . $items_per_page;
}
$this->items_per_page = $items_per_page;
// If the pager is already initialized, pass it through to the pager.
......@@ -583,9 +587,15 @@ public function getOffset() {
* The pager offset.
*/
public function setOffset($offset) {
$this->element['#cache']['keys'][] = 'offset:' . $offset;
// Check whether the element is pre rendered. At that point, the cache keys
// cannot longer be manipulated.
if (empty($this->element['#pre_rendered'])) {
$this->element['#cache']['keys'][] = 'offset:' . $offset;
}
$this->offset = $offset;
// If the pager is already initialized, pass it through to the pager.
if (!empty($this->pager)) {
$this->pager->setOffset($offset);
......
langcode: en
status: true
id: test_summary
label: Test Summary
module: views
description: ''
tag: default
base_table: entity_test
base_field: id
core: '8'
display:
default:
id: default
display_title: Master
display_plugin: default
position: 0
display_options:
query:
type: views_query
options:
query_comment: ''
disable_sql_rewrite: false
distinct: false
replica: false
query_tags: { }
title: 'Summary test'
access:
type: none
cache:
type: tag
options: { }
pager:
type: mini
options:
items_per_page: 2
offset: 0
id: 0
total_pages: 0
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '1, 2, 3, 4'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ‹‹
next: ››
sorts:
id:
id: id
table: entity_test
field: id
order: ASC
plugin_id: standard
relationship: none
arguments:
type:
id: type
field: type
table: entity_test
default_action: summary
exception:
title_enable: true
title_enable: true
title: '{{ arguments.type }}'
default_argument_type: fixed
summary:
sort_order: asc
format: default_summary
summary_options:
override: true
items_per_page: 4
specify_validation: true
plugin_id: string
entity_type: entity_test
fields:
id:
id: id
field: id
table: entity_test
plugin_id: field
entity_type: entity_test
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
header: { }
footer: { }
empty: { }
relationships: { }
fields: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
max-age: -1
tags: { }
page_1:
id: page_1
display_title: Page
display_plugin: page
position: 2
display_options:
query:
type: views_query
options: { }
path: test-summary
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
max-age: -1
tags: { }
......@@ -469,4 +469,100 @@ protected function setupBaseViewAndDisplay() {
return array($view, $display);
}
/**
* @covers ::setItemsPerPage
* @covers ::getItemsPerPage
*/
public function testSetItemsPerPageBeforePreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$view->setItemsPerPage(12);
$this->assertEquals(12, $view->getItemsPerPage());
$this->assertContains('items_per_page:12', $view->element['#cache']['keys']);
}
/**
* @covers ::setItemsPerPage
* @covers ::getItemsPerPage
*/
public function testSetItemsPerPageDuringPreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$elements = &$view->element;
$elements['#cache'] += ['keys' => []];
$elements['#pre_rendered'] = TRUE;
$view->setItemsPerPage(12);
$this->assertEquals(12, $view->getItemsPerPage());
$this->assertNotContains('items_per_page:12', $view->element['#cache']['keys']);
}
/**
* @covers ::setOffset
* @covers ::getOffset
*/
public function testSetOffsetBeforePreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$view->setOffset(12);
$this->assertEquals(12, $view->getOffset());
$this->assertContains('offset:12', $view->element['#cache']['keys']);
}
/**
* @covers ::setOffset
* @covers ::getOffset
*/
public function testSetOffsetDuringPreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$elements = &$view->element;
$elements['#cache'] += ['keys' => []];
$elements['#pre_rendered'] = TRUE;
$view->setOffset(12);
$this->assertEquals(12, $view->getOffset());
$this->assertNotContains('offset:12', $view->element['#cache']['keys']);
}
/**
* @covers ::setCurrentPage
* @covers ::getCurrentPage
*/
public function testSetCurrentPageBeforePreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$view->setCurrentPage(12);
$this->assertEquals(12, $view->getCurrentPage());
$this->assertContains('page:12', $view->element['#cache']['keys']);
}
/**
* @covers ::setCurrentPage
* @covers ::getCurrentPage
*/
public function testSetCurrentPageDuringPreRender() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
$elements = &$view->element;
$elements['#cache'] += ['keys' => []];
$elements['#pre_rendered'] = TRUE;
$view->setCurrentPage(12);
$this->assertEquals(12, $view->getCurrentPage());
$this->assertNotContains('page:12', $view->element['#cache']['keys']);
}
}
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