You are here

function PreviewTest::testPreviewUI in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Tests/PreviewTest.php \Drupal\views_ui\Tests\PreviewTest::testPreviewUI()

Tests arguments in the preview form.

File

core/modules/views_ui/src/Tests/PreviewTest.php, line 52
Contains \Drupal\views_ui\Tests\PreviewTest.

Class

PreviewTest
Tests the UI preview functionality.

Namespace

Drupal\views_ui\Tests

Code

function testPreviewUI() {
  $this
    ->drupalGet('admin/structure/views/view/test_preview/edit');
  $this
    ->assertResponse(200);
  $this
    ->drupalPostForm(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
    ->drupalPostForm(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
    ->drupalPostForm(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.');

  // Test feed preview.
  $view = array();
  $view['label'] = $this
    ->randomMachineName(16);
  $view['id'] = strtolower($this
    ->randomMachineName(16));
  $view['page[create]'] = 1;
  $view['page[title]'] = $this
    ->randomMachineName(16);
  $view['page[path]'] = $this
    ->randomMachineName(16);
  $view['page[feed]'] = 1;
  $view['page[feed_properties][path]'] = $this
    ->randomMachineName(16);
  $this
    ->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
  $this
    ->clickLink(t('Feed'));
  $this
    ->drupalPostForm(NULL, array(), t('Update preview'));
  $result = $this
    ->xpath('//div[@id="views-live-preview"]/pre');
  $this
    ->assertTrue(strpos($result[0], '<title>' . $view['page[title]'] . '</title>'), 'The Feed RSS preview was rendered.');
}