public function ViewsLazyLoadTest::testLazyLoading in Views Lazy Load 7
Same name and namespace in other branches
- 8 views_lazy_load.test \ViewsLazyLoadTest::testLazyLoading()
Tests the basics of lazy loading.
File
- ./
views_lazy_load.test, line 34 - Contains ViewsLazyLoadTest
Class
- ViewsLazyLoadTest
- Test the basic lazy loading of views.
Code
public function testLazyLoading() {
// Create a views using a page.
$view = $this
->getTestView();
// Render the view, everything should be normal, no lazy loading.
$output = $view
->preview();
$this
->assertNotContains('Loading...', $output, 'The view output does not have the lazy loading text.');
// Update the view to be lazy, re-render and expect the exact loading
// indicator, using theme_views_lazy_load_throbber to ensure no incorrectly
// escaped HTML.
$view = $this
->getTestView(TRUE);
$output = $view
->preview('page');
$this
->assertContains(theme('views_lazy_load_throbber'), $output, 'The view output has the lazy loading text.');
// Assert the view display to make sure we're getting the right display.
$this
->assertContains('view-display-id-page', $output, 'Correct display title');
// Make sure AJAX is forced on with lazy loading.
$view = $this
->getTestView(TRUE);
$view
->preview();
$this
->assertTrue($view->use_ajax, 'View uses AJAX whenever Views Lazy Load is enabled.');
// We can use a GET parameter to disable the lazy loading which is used on
// the second pass.
$_GET['views_lazy_load_disabled'] = TRUE;
$view = $this
->getTestView(TRUE);
$output = $view
->preview();
$this
->assertNotContains('Loading...', $output, 'The view output does not have the lazy loading text.');
// Make sure that our view won't be lazy under a crawler robot visit
// Set our agent to some robot's agent:
unset($_GET['views_lazy_load_disabled']);
$_SERVER['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
$view = $this
->getTestView(TRUE);
$output = $view
->preview();
$this
->assertNotContains('Loading...', $output, 'The view output does not have the lazy loading text because of the webcrawler\'s agent.');
}