function PreviewTest::testPreviewUI

Tests arguments in the preview form.

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php, line 54
Contains \Drupal\views_ui\Tests\PreviewTest.

Class

PreviewTest
Tests the preview form in the UI.

Namespace

Drupal\views_ui\Tests

Code

function testPreviewUI() {
  $this
    ->drupalGet('admin/structure/views/view/test_preview/edit');
  $this
    ->assertResponse(200);
  $this
    ->drupalPost(NULL, $edit = array(), t('Update preview'));
  $elements = $this
    ->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
  $this
    ->assertEqual(count($elements), 5);

  // Filter just the first result.
  $this
    ->drupalPost(NULL, $edit = array(
    'view_args' => '1',
  ), t('Update preview'));
  $elements = $this
    ->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
  $this
    ->assertEqual(count($elements), 1);

  // Filter for no results.
  $this
    ->drupalPost(NULL, $edit = array(
    'view_args' => '100',
  ), t('Update preview'));
  $elements = $this
    ->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
  $this
    ->assertEqual(count($elements), 0);

  // Test that area text and exposed filters are present and rendered.
  $this
    ->assertFieldByName('id', NULL, 'ID exposed filter field found.');
  $this
    ->assertText('Test header text', 'Rendered header text found');
  $this
    ->assertText('Test footer text', 'Rendered footer text found.');
  $this
    ->assertText('Test empty text', 'Rendered empty text found.');
}