WebformHandlerActionTest.php in Webform 8.5
File
tests/src/Functional/Handler/WebformHandlerActionTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Handler;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformHandlerActionTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_handler_action',
];
public function testActionHandler() {
$this
->drupalLogin($this->rootUser);
$webform = Webform::load('test_handler_action');
$sid = $this
->postSubmission($webform);
$webform_submission = WebformSubmission::load($sid);
$this
->assertFalse($webform_submission
->isSticky());
$this
->assertFalse($webform_submission
->isLocked());
$this
->assertEmpty($webform_submission
->getNotes());
$this
->assertEmpty($webform_submission
->getElementData('notes_add'));
$edit = [
'sticky' => 'flag',
'notes_add' => 'This is the first note',
];
$this
->drupalPostForm("admin/structure/webform/manage/test_handler_action/submission/{$sid}/edit", $edit, 'Save');
$this
->assertRaw('Submission has been flagged.');
$this
->assertRaw('Submission notes have been updated.');
\Drupal::entityTypeManager()
->getStorage('webform_submission')
->resetCache();
$webform_submission = WebformSubmission::load($sid);
$this
->assertTrue($webform_submission
->isSticky());
$this
->assertEmpty($webform_submission
->getElementData('notes_add'));
$this
->assertEqual($webform_submission
->getElementData('notes_last'), 'This is the first note');
$edit = [
'sticky' => 'unflag',
'notes_add' => 'This is the second note',
];
$this
->drupalPostForm("admin/structure/webform/manage/test_handler_action/submission/{$sid}/edit", $edit, 'Save');
$this
->assertRaw('Submission has been unflagged.');
$this
->assertRaw('Submission notes have been updated.');
\Drupal::entityTypeManager()
->getStorage('webform_submission')
->resetCache();
$webform_submission = WebformSubmission::load($sid);
$this
->assertFalse($webform_submission
->isSticky());
$this
->assertEmpty($webform_submission
->getElementData('notes_add'));
$this
->assertEqual($webform_submission
->getNotes(), 'This is the first note' . PHP_EOL . PHP_EOL . 'This is the second note');
$this
->assertEqual($webform_submission
->getElementData('notes_last'), 'This is the second note');
$edit = [
'lock' => 'locked',
];
$this
->drupalPostForm("admin/structure/webform/manage/test_handler_action/submission/{$sid}/edit", $edit, 'Save');
$this
->assertRaw('Submission has been locked.');
\Drupal::entityTypeManager()
->getStorage('webform_submission')
->resetCache();
$webform_submission = WebformSubmission::load($sid);
$this
->assertTrue($webform_submission
->isLocked());
$this
->assertEqual(WebformSubmissionInterface::STATE_LOCKED, $webform_submission
->getState());
$this
->drupalGet("admin/structure/webform/manage/test_handler_action/submission/{$sid}/edit");
$this
->assertRaw('This is submission was automatically locked.');
$webform_submission
->setElementData('lock', 'unlocked');
$webform_submission
->save();
$this
->assertFalse($webform_submission
->isLocked());
$this
->assertNotEqual(WebformSubmissionInterface::STATE_LOCKED, $webform_submission
->getState());
}
}