View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
class WebformSubmissionListBuilderBulkOperationsTest extends WebformBrowserTestBase {
public static $modules = [
'node',
'webform',
'webform_test_submissions',
];
protected static $testWebforms = [
'test_submissions',
];
public function testResults() {
$admin_submission_user = $this
->drupalCreateUser([
'administer webform submission',
]);
$update_submission_user = $this
->drupalCreateUser([
'view any webform submission',
'edit any webform submission',
]);
$webform = Webform::load('test_submissions');
$submissions = array_values(\Drupal::entityTypeManager()
->getStorage('webform_submission')
->loadByProperties([
'webform_id' => 'test_submissions',
]));
$path = '/admin/structure/webform/manage/' . $webform
->id() . '/results/submissions';
$this
->drupalLogin($admin_submission_user);
$this
->drupalGet($path);
$this
->assertCssSelect('#webform-submission-bulk-form');
$this
->assertCssSelect('#edit-items-' . $submissions[0]
->id());
$this
->assertCssSelect('#edit-items-' . $submissions[1]
->id());
$this
->assertCssSelect('#edit-items-' . $submissions[2]
->id());
$this
->drupalGet($path);
$this
->assertCssSelect('option[value="webform_submission_make_sticky_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_unsticky_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_lock_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_unlock_action"]');
$this
->assertCssSelect('option[value="webform_submission_delete_action"]');
$this
->drupalLogin($update_submission_user);
$this
->drupalGet($path);
$this
->assertCssSelect('option[value="webform_submission_make_sticky_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_unsticky_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_lock_action"]');
$this
->assertCssSelect('option[value="webform_submission_make_unlock_action"]');
$this
->assertNoCssSelect('option[value="webform_submission_delete_action"]');
$this
->drupalLogin($admin_submission_user);
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.webform_submission_bulk_form', FALSE)
->save();
$this
->drupalGet($path);
$this
->assertNoCssSelect('#webform-submission-bulk-form');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.webform_submission_bulk_form', TRUE)
->save();
$this
->assertFalse($submissions[0]
->isSticky());
$edit = [
'action' => 'webform_submission_make_sticky_action',
'items[' . $submissions[0]
->id() . ']' => TRUE,
];
$this
->drupalPostForm($path, $edit, 'Apply to selected items', [], 'webform-submission-bulk-form');
$this
->assertRaw('<em class="placeholder">Star/flag submission</em> was applied to 1 item.');
$submissions[0] = $this
->reloadSubmission($submissions[0]
->id());
$this
->assertTrue($submissions[0]
->isSticky());
$edit = [
'action' => 'webform_submission_make_unsticky_action',
'items[' . $submissions[0]
->id() . ']' => TRUE,
];
$this
->drupalPostForm($path, $edit, 'Apply to selected items', [], 'webform-submission-bulk-form');
$this
->assertRaw('<em class="placeholder">Unstar/unflag submission</em> was applied to 1 item.');
$submissions[0] = $this
->reloadSubmission($submissions[0]
->id());
$this
->assertFalse($submissions[0]
->isSticky());
$this
->assertFalse($submissions[0]
->isLocked());
$edit = [
'action' => 'webform_submission_make_lock_action',
'items[' . $submissions[0]
->id() . ']' => TRUE,
];
$this
->drupalPostForm($path, $edit, 'Apply to selected items', [], 'webform-submission-bulk-form');
$this
->assertRaw('<em class="placeholder">Lock submission</em> was applied to 1 item.');
$submissions[0] = $this
->reloadSubmission($submissions[0]
->id());
$this
->assertTrue($submissions[0]
->isLocked());
$edit = [
'action' => 'webform_submission_make_unlock_action',
'items[' . $submissions[0]
->id() . ']' => TRUE,
];
$this
->drupalPostForm($path, $edit, 'Apply to selected items', [], 'webform-submission-bulk-form');
$this
->assertRaw('<em class="placeholder">Unlock submission</em> was applied to 1 item.');
$submissions[0] = $this
->reloadSubmission($submissions[0]
->id());
$this
->assertFalse($submissions[0]
->isLocked());
$edit = [
'action' => 'webform_submission_delete_action',
'items[' . $submissions[0]
->id() . ']' => TRUE,
];
$this
->drupalPostForm($path, $edit, 'Apply to selected items', [], 'webform-submission-bulk-form');
$edit = [
'confirm_input' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Delete');
$this
->assertRaw('Deleted 1 item.');
$submissions[0] = $this
->reloadSubmission($submissions[0]
->id());
$this
->assertNull($submissions[0]);
}
}