diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Full.php b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Full.php index 508673a..3fbc747 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Full.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Full.php @@ -78,10 +78,9 @@ public function summaryTitle() { } /** - * Overrides \Drupal\views\Plugin\views\pager\PagerPluginBase::render(). + * {@inheritdoc} */ function render($input) { - $pager_theme = $this->view->buildThemeFunctions('pager'); // The 0, 1, 3, 4 indexes are correct. See the template_preprocess_pager() // documentation. $tags = array( @@ -90,14 +89,13 @@ function render($input) { 3 => $this->options['tags']['next'], 4 => $this->options['tags']['last'], ); - $output = array( - '#theme' => $pager_theme, + return array( + '#theme' => $this->view->buildThemeFunctions('pager'), '#tags' => $tags, '#element' => $this->options['id'], '#parameters' => $input, '#quantity' => $this->options['quantity'], ); - return $output; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php index 9d2d3cc..3607dae 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php @@ -93,7 +93,7 @@ public function postExecute(&$result) { } /** - * Overrides \Drupal\views\Plugin\views\pager\PagerPluginBase::render(). + * {@inheritdoc} */ function render($input) { // The 1, 3 indexes are correct, see template_preprocess_pager(). @@ -101,13 +101,12 @@ function render($input) { 1 => $this->options['tags']['previous'], 3 => $this->options['tags']['next'], ); - $output = array( + return array( '#theme' => $this->themeFunctions(), - '#parameters' => $input, - '#element' => $this->options['id'], '#tags' => $tags, + '#element' => $this->options['id'], + '#parameters' => $input, ); - return $output; } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/pager/PagerPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/pager/PagerPluginBase.php index 9994cf5..47ed1ec 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/pager/PagerPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/pager/PagerPluginBase.php @@ -218,10 +218,9 @@ public function postExecute(&$result) { } public function preRender(&$result) { } /** - * Render the pager. + * Return the renderable array of the pager. * - * Called during the view render process, this will render the - * pager. + * Called during the view render process. * * @param $input * Any extra GET parameters that should be retained, such as exposed diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php index 6a6ecae..db75d7d 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php @@ -7,6 +7,8 @@ namespace Drupal\views_ui\Tests; +use SimpleXMLElement; + /** * Tests the preview form in the UI. */ @@ -17,7 +19,7 @@ class PreviewTest extends UITestBase { * * @var array */ - public static $testViews = array('test_preview'); + public static $testViews = array('test_preview', 'test_pager_full', 'test_mini_pager'); public static function getInfo() { return array( @@ -80,6 +82,105 @@ function testPreviewUI() { } /** + * Tests pagers in the preview form. + */ + function testPreviewWithPagersUI() { + + // Disable automatic preview. + $edit = array( + 'ui_always_live_preview' => FALSE, + ); + $this->drupalPost('admin/structure/views/settings', $edit, t('Save configuration')); + + // Create 11 nodes and make sure that everyone is returned. + for ($i = 0; $i < 11; $i++) { + $this->drupalCreateNode(); + } + + // Test Full Pager. + $this->drupalGet('admin/structure/views/view/test_pager_full/edit'); + $this->assertResponse(200); + $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); + + // Are there 5 rows returned? + $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]'); + $this->assertEqual(count($elements), 5); + + // Test that the pager is present and rendered. + $elements = $this->xpath('//ul[@class=:class]/li', array(':class' => 'pager')); + $this->assertTrue(!empty($elements), 'Full pager found.'); + + // Verify elements and links to pages. + foreach ($elements as $page => $element) { + // Make element/page index 1-based. + $page++; + // We expect to find 5 elements: current page == 1, links to pages 2 and + // and 3, links to 'next >' and 'last >>' pages. + switch ($page) { + case 1: + $this->assertClass($element, 'pager-current', 'Element for current page has .pager-current class.'); + $this->assertFalse(isset($element->a), 'Element for current page has no link.'); + break; + + case 2: + case 3: + $this->assertClass($element, 'pager-item', "Element for page $page has .pager-item class."); + $this->assertTrue($element->a, "Link to page $page found."); + break; + + case 4: + $this->assertClass($element, 'pager-next', "Element for next page has .pager-next class."); + $this->assertTrue($element->a, "Link to next page found."); + break; + + case 5: + $this->assertClass($element, 'pager-last', "Element for last page has .pager-last class."); + $this->assertTrue($element->a, "Link to last page found."); + break; + + } + } + + // Test Mini Pager. + $this->drupalGet('admin/structure/views/view/test_mini_pager/edit'); + $this->assertResponse(200); + $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); + + // Are there 3 rows returned? + $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]'); + $this->assertEqual(count($elements), 3); + + // Test that the pager is present and rendered. + $elements = $this->xpath('//ul[@class=:class]/li', array(':class' => 'pager')); + $this->assertTrue(!empty($elements), 'Mini pager found.'); + + // Verify elements and links to pages. + foreach ($elements as $page => $element) { + // Make element/page index 1-based. + $page++; + // We expect to find 3 elements: previous page (with no link), current page == 1, + // and link to 'next >' page. + switch ($page) { + case 1: + $this->assertClass($element, 'pager-previous', 'Element for previous page has .pager-previous class.'); + $this->assertFalse(isset($element->a), 'Element for previous page has no link.'); + break; + + case 2: + $this->assertClass($element, 'pager-current', 'Element for current page has .pager-current class.'); + $this->assertFalse(isset($element->a), 'Element for current page has no link.'); + break; + + case 3: + $this->assertClass($element, 'pager-next', "Element for next page has .pager-next class."); + $this->assertTrue($element->a, "Link to next page found."); + break; + + } + } + } + + /** * Tests the actual preview response. */ public function testPreviewController() { @@ -93,4 +194,21 @@ public function testPreviewController() { $this->assertTrue(isset($result_commands['insert'])); } + /** + * Asserts that an element has a given class. + * + * @param SimpleXMLElement $element + * The element to test. + * @param string $class + * The class to assert. + * @param string $message + * (optional) A verbose message to output. + */ + protected function assertClass(SimpleXMLElement $element, $class, $message = NULL) { + if (!isset($message)) { + $message = "Class .$class found."; + } + $this->assertTrue(strpos($element['class'], $class) !== FALSE, $message); + } + }