<?php
namespace Drupal\views_ui\Tests;
class PreviewTest extends UITestBase {
public static $testViews = array(
'test_preview',
);
public static function getInfo() {
return array(
'name' => 'Preview functionality',
'description' => 'Tests the UI preview functionality.',
'group' => 'Views UI',
);
}
protected function testPreviewContextual() {
module_enable(array(
'contextual',
));
$this
->drupalGet('admin/structure/views/view/test_preview/edit');
$this
->assertResponse(200);
$this
->drupalPost(NULL, $edit = array(), t('Update preview'));
$elements = $this
->xpath('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li[contains(@class, :li-class)]', array(
':ul-class' => 'contextual-links',
':li-class' => 'filter-add',
));
$this
->assertEqual(count($elements), 1, 'The contextual link to add a new field is shown.');
$this
->drupalPost(NULL, $edit = array(
'view_args' => '100',
), t('Update preview'));
$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.');
}
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);
$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);
$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);
$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.');
}
public function testPreviewController() {
$result = $this
->drupalGetAJAX('admin/structure/views/view/test_preview/preview/default');
$result_commands = array();
foreach ($result as $command) {
$result_commands[$command['command']] = $command;
}
$this
->assertTrue(isset($result_commands['insert']));
}
}