diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/pager/PagerPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/pager/PagerPluginBaseTest.php new file mode 100644 index 0000000..9acf5c8 --- /dev/null +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/pager/PagerPluginBaseTest.php @@ -0,0 +1,156 @@ + 'PagerPluginBase test', + 'description' => 'Tests the \Drupal\views\Plugin\views\pager\PagerPluginBase class.', + 'group' => 'Views Handlers', + ); + } + + public function setUp() { + $this->pager = $this->getMockBuilder('Drupal\views\Plugin\views\pager\PagerPluginBase') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $view = $this->getMockBuilder('Drupal\views\ViewExecutable') + ->disableOriginalConstructor() + ->getMock(); + $display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase') + ->disableOriginalConstructor() + ->getMock(); + + $options = array( + 'items_per_page' => 5, + 'offset' => 1, + ); + + $this->pager->init($view, $display, $options); + + $this->pager->current_page = 1; + } + + /** + * Tests the getItemsPerPage() method. + */ + public function testGetItemsPerPage() { + $this->assertEquals(5, $this->pager->getItemsPerPage()); + } + + /** + * Tests the setItemsPerPage() method. + */ + public function testSetItemsPerPage() { + $this->pager->setItemsPerPage(6); + $this->assertEquals(6, $this->pager->getItemsPerPage()); + } + + /** + * Tests the getOffset() method. + */ + public function testGetOffset() { + $this->assertEquals(1, $this->pager->getOffset()); + } + + /** + * Tests the setOffset() method. + */ + public function testSetOffset() { + $this->pager->setOffset(2); + $this->assertEquals(2, $this->pager->getOffset()); + } + + /** + * Tests the getCurrentPage() method. + */ + public function testGetCurrentPage() { + $this->assertEquals(1, $this->pager->getCurrentPage()); + } + + /** + * Tests the setCurrentPage() method. + */ + public function testSetCurrentPage() { + $this->pager->setCurrentPage(2); + $this->assertEquals(2, $this->pager->getCurrentPage()); + + // A non numeric number or number below 0 should return 0. + $this->pager->setCurrentPage('two'); + $this->assertEquals(0, $this->pager->getCurrentPage()); + + $this->pager->setCurrentPage(-2); + $this->assertEquals(0, $this->pager->getCurrentPage()); + } + + /** + * Tests the getTotalItems() method. + */ + public function testGetTotalItems() { + // Should return 0 by default. + $this->assertEquals(0, $this->pager->getTotalItems()); + + $this->pager->total_items = 10; + $this->assertEquals(10, $this->pager->getTotalItems()); + } + + /** + * Tests the getPagerId() method. + */ + public function testGetPagerId() { + // Should return 0 if 'id' is not set. + $this->assertEquals(0, $this->pager->getPagerId()); + + $this->pager->options['id'] = 1; + + $this->assertEquals(1, $this->pager->getPagerId()); + } + + /** + * Tests the usePager() method. + */ + public function testUsePager() { + $this->assertTrue($this->pager->usePager()); + } + + /** + * Tests the useCountQuery() method. + */ + public function testUseCountQuery() { + $this->assertTrue($this->pager->useCountQuery()); + } + + /** + * Tests the usesExposed() method. + */ + public function testUsesExposed() { + $this->assertFalse($this->pager->usesExposed()); + } + + // @todo Test the executeCountQuery() and hasMoreRecords() methods. + +}