View source
<?php
namespace Drupal\views\Tests\Plugin;
class StyleTableTest extends PluginTestBase {
public static $testViews = array(
'test_table',
);
protected function setUp() {
parent::setUp();
$this
->enableViewsTestModule();
}
public function testAccessibilitySettings() {
$this
->drupalGet('test-table');
$result = $this
->xpath('//caption');
$this
->assertTrue(count($result), 'The caption appears on the table.');
$this
->assertEqual(trim((string) $result[0]), 'caption-text');
$result = $this
->xpath('//summary');
$this
->assertTrue(count($result), 'The summary appears on the table.');
$this
->assertEqual(trim((string) $result[0]), 'summary-text');
$result = $this
->xpath('//caption/details');
$this
->assertTrue(count($result), 'The table description appears on the table.');
$this
->assertEqual(trim((string) $result[0]), 'description-text');
$view = entity_load('view', 'test_table');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['caption'] = '';
$view
->save();
$this
->drupalGet('test-table');
$result = $this
->xpath('//caption');
$this
->assertFalse(trim((string) $result[0]), 'Ensure that the caption disappears.');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['summary'] = '';
$view
->save();
$this
->drupalGet('test-table');
$result = $this
->xpath('//summary');
$this
->assertFalse(count($result), 'Ensure that the summary disappears.');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['description'] = '';
$view
->save();
$this
->drupalGet('test-table');
$result = $this
->xpath('//caption/details');
$this
->assertFalse(count($result), 'Ensure that the description disappears.');
}
public function testFieldInColumns() {
$this
->drupalGet('test-table');
$result = $this
->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job ")]');
$this
->assertTrue(count($result), 'Ensure there is a td with the class views-field-job');
$result = $this
->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job-1 ")]');
$this
->assertTrue(count($result), 'Ensure there is a td with the class views-field-job-1');
$view = entity_load('view', 'test_table');
$display =& $view
->getDisplay('default');
$display['display_options']['style']['options']['columns']['job_1'] = 'job';
$display['display_options']['style']['options']['info']['job']['separator'] = ', ';
$view
->save();
$this
->drupalGet('test-table');
$result = $this
->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job views-field-job-1 ")]');
$this
->assertTrue(count($result), 'Ensure that the job column class names are joined into a single column');
$result = $this
->xpath('//tbody/tr/td[contains(., "Drummer, Drummer")]');
$this
->assertTrue(count($result), 'Ensure the job column values are joined into a single column');
}
public function testNumericFieldVisible() {
$data_set = $this
->dataSet();
$query = db_insert('views_test_data')
->fields(array_keys($data_set[0]));
$query
->values(array(
'name' => 'James McCartney',
'age' => 0,
'job' => 'Baby',
'created' => gmmktime(6, 30, 10, 1, 1, 2000),
'status' => 1,
));
$query
->execute();
$this
->drupalGet('test-table');
$result = $this
->xpath('//tbody/tr/td[contains(., "Baby")]');
$this
->assertTrue(count($result), 'Ensure that the baby is found.');
$result = $this
->xpath('//tbody/tr/td[text()=0]');
$this
->assertTrue(count($result), 'Ensure that the baby\'s age is shown');
}
}