diff --git a/core/modules/views/src/Plugin/views/pager/SqlBase.php b/core/modules/views/src/Plugin/views/pager/SqlBase.php index a3f8a0a4c68..c3b1d99920d 100644 --- a/core/modules/views/src/Plugin/views/pager/SqlBase.php +++ b/core/modules/views/src/Plugin/views/pager/SqlBase.php @@ -260,7 +260,7 @@ abstract class SqlBase extends PagerPluginBase implements CacheableDependencyInt if ($this->itemsPerPageExposed()) { $query = $this->view->getRequest()->query; $items_per_page = $query->get('items_per_page'); - if ($items_per_page > 0) { + if ((int) $items_per_page > 0) { $this->options['items_per_page'] = $items_per_page; } elseif ($items_per_page == 'All' && $this->options['expose']['items_per_page_options_all']) { diff --git a/core/modules/views/tests/src/Unit/Plugin/pager/SqlBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/pager/SqlBaseTest.php new file mode 100644 index 00000000000..99b65df3c33 --- /dev/null +++ b/core/modules/views/tests/src/Unit/Plugin/pager/SqlBaseTest.php @@ -0,0 +1,91 @@ +pager = $this->getMockBuilder('Drupal\views\Plugin\views\pager\SqlBase') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + /** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */ + $this->view = $this->getMockBuilder('Drupal\views\ViewExecutable') + ->disableOriginalConstructor() + ->getMock(); + + $query = $this->getMockBuilder(QueryPluginBase::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->view->query = $query; + + $this->display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase') + ->disableOriginalConstructor() + ->getMock(); + + $container = new ContainerBuilder(); + $container->set('string_translation', $this->getStringTranslationStub()); + \Drupal::setContainer($container); + } + + /** + * Tests the query() method. + * + * @see \Drupal\views\Plugin\views\pager\SqlBase::query() + */ + public function testQuery() { + $request = new Request([ + 'items_per_page' => 'All', + ]); + $this->view->expects($this->any()) + ->method('getRequest') + ->will($this->returnValue($request)); + + $options = []; + $this->pager->init($this->view, $this->display, $options); + $this->pager->query(); + $this->assertSame(10, $this->pager->options['items_per_page']); + + $options = [ + 'expose' => [ + 'items_per_page' => TRUE, + 'items_per_page_options_all' => TRUE, + ], + ]; + $this->pager->init($this->view, $this->display, $options); + $this->pager->query(); + $this->assertSame(0, $this->pager->options['items_per_page']); + } + +}