View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
class WebformSubmissionListBuilderTest extends WebformBrowserTestBase {
public static $modules = [
'node',
'webform',
'webform_test_submissions',
];
protected static $testWebforms = [
'test_submissions',
];
public function testResults() {
$own_submission_user = $this
->drupalCreateUser([
'view own webform submission',
'edit own webform submission',
'delete own webform submission',
'access webform submission user',
]);
$admin_submission_user = $this
->drupalCreateUser([
'administer webform submission',
]);
$webform = Webform::load('test_submissions');
$submissions = array_values(\Drupal::entityTypeManager()
->getStorage('webform_submission')
->loadByProperties([
'webform_id' => 'test_submissions',
]));
$this
->drupalLogin($own_submission_user);
$submissions[1]
->setSticky(TRUE)
->save();
$submissions[2]
->setLocked(TRUE)
->save();
$this
->drupalLogin($admin_submission_user);
$this
->drupalGet('/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions');
$this
->assertRaw('<select data-drupal-selector="edit-state" id="edit-state" name="state" class="form-select"><option value="" selected="selected">All [4]</option><option value="starred">Starred [1]</option><option value="unstarred">Unstarred [3]</option><option value="locked">Locked [1]</option><option value="unlocked">Unlocked [3]</option></select>');
$this
->assertLinkByHref($submissions[0]
->toUrl()
->toString());
$this
->assertLinkByHref($submissions[1]
->toUrl()
->toString());
$this
->assertLinkByHref($submissions[2]
->toUrl()
->toString());
$this
->assertRaw($submissions[0]
->getElementData('first_name'));
$this
->assertRaw($submissions[1]
->getElementData('first_name'));
$this
->assertRaw($submissions[2]
->getElementData('first_name'));
$this
->assertNoFieldById('edit-reset', 'reset');
$this
->drupalPostForm('/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions', [
'search' => $submissions[0]
->get('uuid')->value,
], 'Filter');
$this
->assertUrl('admin/structure/webform/manage/' . $webform
->id() . '/results/submissions?search=' . $submissions[0]
->get('uuid')->value);
$this
->assertRaw($submissions[0]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[1]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[2]
->getElementData('first_name'));
$this
->drupalPostForm('/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions', [
'search' => $submissions[0]
->getElementData('first_name'),
], 'Filter');
$this
->assertUrl('admin/structure/webform/manage/' . $webform
->id() . '/results/submissions?search=' . $submissions[0]
->getElementData('first_name'));
$this
->assertRaw($submissions[0]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[1]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[2]
->getElementData('first_name'));
$this
->assertFieldById('edit-reset', 'Reset');
$this
->drupalPostForm('/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions', [
'state' => 'starred',
], 'Filter');
$this
->assertUrl('admin/structure/webform/manage/' . $webform
->id() . '/results/submissions?state=starred');
$this
->assertRaw('<option value="starred" selected="selected">Starred [1]</option>');
$this
->assertNoRaw($submissions[0]
->getElementData('first_name'));
$this
->assertRaw($submissions[1]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[2]
->getElementData('first_name'));
$this
->assertFieldById('edit-reset', 'Reset');
$this
->drupalPostForm('/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions', [
'state' => 'locked',
], 'Filter');
$this
->assertUrl('admin/structure/webform/manage/' . $webform
->id() . '/results/submissions?state=locked');
$this
->assertRaw('<option value="locked" selected="selected">Locked [1]</option>');
$this
->assertNoRaw($submissions[0]
->getElementData('first_name'));
$this
->assertNoRaw($submissions[1]
->getElementData('first_name'));
$this
->assertRaw($submissions[2]
->getElementData('first_name'));
$this
->assertFieldById('edit-reset', 'Reset');
}
}