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 81341fd..c0b8907 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 @@ -90,20 +90,7 @@ public function testPreviewWithPagersUI() { } // Test Full Pager. - $this->drupalGet('admin/structure/views/view/test_pager_full/preview/default'); - $result = $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); - - // Has AJAX callback replied with an insert command? If so, we can - // assume that the page content was updated with AJAX returned data. - $result_commands = array(); - foreach ($result as $command) { - $result_commands[$command['command']] = $command; - } - $this->assertTrue(isset($result_commands['insert']), 'AJAX insert command received.'); - - // Are there 5 rows returned? - $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]'); - $this->assertEqual(count($elements), 5, '5 items found on page.'); + $this->getPreviewAJAX('test_pager_full', 'default', 5); // Test that the pager is present and rendered. $elements = $this->xpath('//ul[@class = "pager"]/li'); @@ -141,20 +128,7 @@ public function testPreviewWithPagersUI() { } // Test Mini Pager. - $this->drupalGet('admin/structure/views/view/test_mini_pager/preview/default'); - $result = $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); - - // Has AJAX callback replied with an insert command? If so, we can - // assume that the page content was updated with AJAX returned data. - $result_commands = array(); - foreach ($result as $command) { - $result_commands[$command['command']] = $command; - } - $this->assertTrue(isset($result_commands['insert']), 'AJAX insert command received.'); - - // Are there 3 rows returned? - $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]'); - $this->assertEqual(count($elements), 3, '3 items found on page.'); + $this->getPreviewAJAX('test_mini_pager', 'default', 3); // Test that the pager is present and rendered. $elements = $this->xpath('//ul[@class = "pager"]/li'); @@ -187,17 +161,30 @@ public function testPreviewWithPagersUI() { } /** - * Tests the actual preview response. + * Get the preview form and force an AJAX preview update. + * + * @param string $view_name + * The view to test. + * @param string $panel_id + * The view panel to test. + * @param int $row_count + * The expected number of rows in the preview. */ - public function testPreviewController() { - $result = $this->drupalGetAJAX('admin/structure/views/view/test_preview/preview/default'); + protected function getPreviewAJAX($view_name, $panel_id, $row_count) { + $this->drupalGet('admin/structure/views/view/' . $view_name . '/preview/' .$panel_id); + $result = $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); + // Has AJAX callback replied with an insert command? If so, we can + // assume that the page content was updated with AJAX returned data. $result_commands = array(); - // Build a list of the result commands keyed by the js command. foreach ($result as $command) { $result_commands[$command['command']] = $command; } - $this->assertTrue(isset($result_commands['insert'])); + $this->assertTrue(isset($result_commands['insert']), 'AJAX insert command received.'); + + // Test if preview contains the expected number of rows. + $elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]'); + $this->assertEqual(count($elements), $row_count, 'Expected items found on page.'); } /**