View source
<?php
namespace Drupal\yamlform\Tests;
class YamlFormSubmissionListBuilderTest extends YamlFormTestBase {
public function testResults() {
global $base_path;
list($yamlform, $submissions) = $this
->createYamlFormWithSubmissions();
$submissions[1]
->setSticky(TRUE)
->save();
$this
->drupalLogin($this->adminSubmissionUser);
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertRaw('<select data-drupal-selector="edit-state" id="edit-state" name="state" class="form-select"><option value="" selected="selected">All [3]</option><option value="starred">Starred [1]</option><option value="unstarred">Unstarred [2]</option></select>');
$this
->assertLinkByHref($submissions[0]
->toUrl()
->toString());
$this
->assertLinkByHref($submissions[1]
->toUrl()
->toString());
$this
->assertLinkByHref($submissions[2]
->toUrl()
->toString());
$this
->assertRaw($submissions[0]
->getData('first_name'));
$this
->assertRaw($submissions[1]
->getData('first_name'));
$this
->assertRaw($submissions[2]
->getData('first_name'));
$this
->assertNoFieldById('edit-reset', 'reset');
$this
->drupalPostForm('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table', [
'search' => $submissions[0]
->getData('first_name'),
], t('Filter'));
$this
->assertUrl('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?search=' . $submissions[0]
->getData('first_name') . '&state=');
$this
->assertRaw($submissions[0]
->getData('first_name'));
$this
->assertNoRaw($submissions[1]
->getData('first_name'));
$this
->assertNoRaw($submissions[2]
->getData('first_name'));
$this
->assertFieldById('edit-reset', 'Reset');
$this
->drupalPostForm('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table', [
'state' => 'starred',
], t('Filter'));
$this
->assertUrl('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?search=&state=starred');
$this
->assertRaw('<option value="starred" selected="selected">Starred [1]</option>');
$this
->assertNoRaw($submissions[0]
->getData('first_name'));
$this
->assertRaw($submissions[1]
->getData('first_name'));
$this
->assertNoRaw($submissions[2]
->getData('first_name'));
$this
->assertFieldById('edit-reset', 'Reset');
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertRaw('sort by Created');
$this
->assertNoRaw('sort by Changed');
$this
->assertPattern('#First name.+Last name#s');
$this
->assertNoRaw('<nav class="pager" role="navigation" aria-labelledby="pagination-heading">');
$this
->assertRaw('<th specifier="serial" aria-sort="descending" class="is-active">');
$this
->assertPattern('#Hillary.+Abraham.+George#ms');
$edit = [
'columns[created][checkbox]' => FALSE,
'columns[changed][checkbox]' => TRUE,
'columns[element__first_name][weight]' => '8',
'columns[element__last_name][weight]' => '7',
'sort' => 'element__first_name',
'direction' => 'desc',
'limit' => 20,
];
$this
->drupalPostForm('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table/custom', $edit, t('Save'));
$this
->assertRaw('The customized table has been saved.');
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertNoRaw('sort by Created');
$this
->assertRaw('sort by Changed');
$this
->assertPattern('#Last name.+First name#ms');
$this
->assertPattern('#Hillary.+George.+Abraham#ms');
$yamlform
->setState('results.custom.limit', 1);
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertNoRaw($submissions[0]
->getData('first_name'));
$this
->assertNoRaw($submissions[1]
->getData('first_name'));
$this
->assertRaw($submissions[2]
->getData('first_name'));
$this
->assertRaw('<nav class="pager" role="navigation" aria-labelledby="pagination-heading">');
$yamlform
->setState('results.custom.limit', 20);
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?sort=asc&order=User" title="sort by User">User</a>');
$this
->assertRaw('<td class="priority-medium">' . $this->normalUser
->getAccountName() . '</td>');
$this
->assertRaw('<th specifier="element__dob"><a href="' . $base_path . 'admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?sort=asc&order=Date%20of%20birth" title="sort by Date of birth">Date of birth</a></th>');
$this
->assertRaw('<td>Sunday, October 26, 1947</td>');
$yamlform
->setState('results.custom.format', [
'header_format' => 'key',
'element_format' => 'raw',
]);
$this
->drupalGet('admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?sort=asc&order=uid" title="sort by uid">uid</a>');
$this
->assertRaw('<td class="priority-medium">' . $this->normalUser
->id() . '</td>');
$this
->assertRaw('<th specifier="element__dob"><a href="' . $base_path . 'admin/structure/yamlform/manage/' . $yamlform
->id() . '/results/table?sort=asc&order=dob" title="sort by dob">dob</a></th>');
$this
->assertRaw('<td>Sun, 26 Oct 1947 00:00:00 +1000am0</td>');
}
}