public function WebformSubmissionEntityTest::testWebformMethods in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Kernel/Entity/WebformSubmissionEntityTest.php \Drupal\Tests\webform\Kernel\Entity\WebformSubmissionEntityTest::testWebformMethods()
Tests some of the methods.
File
- tests/
src/ Kernel/ Entity/ WebformSubmissionEntityTest.php, line 39
Class
- WebformSubmissionEntityTest
- Tests the webform entity class.
Namespace
Drupal\Tests\webform\Kernel\EntityCode
public function testWebformMethods() {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = Webform::create([
'id' => 'webform_test',
'title' => 'Test',
]);
$elements = [
'name' => [
'#type' => 'textfield',
'#title' => 'name',
],
'other' => [
'#type' => 'textfield',
'#title' => 'other',
],
];
$webform
->setElements($elements);
$webform
->save();
$webform
->save();
// Create webform submission.
$values = [
'id' => 'webform_submission_test',
'webform_id' => $webform
->id(),
'data' => [
'name' => 'John Smith',
],
];
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = WebformSubmission::create($values);
$webform_submission
->save();
$this
->assertEquals($webform
->uuid(), $webform_submission
->getWebform()
->uuid());
// Check get data.
$this
->assertEquals($webform_submission
->getData(), [
'name' => 'John Smith',
]);
// Check get element data.
$this
->assertEquals($webform_submission
->getElementData('name'), 'John Smith');
// Check get element data.
$this
->assertEquals($webform_submission
->getElementData('name'), 'John Smith');
// Check set element data.
$webform_submission
->setElementData('other', 'Other');
$this
->assertEquals($webform_submission
->getElementData('other'), 'Other');
$this
->assertEquals($webform_submission
->getData(), [
'name' => 'John Smith',
'other' => 'Other',
]);
// Check default submission label.
$this
->assertEquals($webform_submission
->label(), 'Test: Submission #1');
// Check customizing admin settings submission label.
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_submission_label', 'Submission #[webform_submission:serial]')
->save();
$this
->assertEquals($webform_submission
->label(), 'Submission #1');
// Check customizing webform specific submission label.
$webform = $webform_submission
->getWebform();
$webform
->setSetting('submission_label', 'Submitted by [webform_submission:values:name]')
->save();
$this
->assertEquals($webform
->getSetting('submission_label'), 'Submitted by [webform_submission:values:name]');
$this
->assertEquals($webform_submission
->label(), 'Submitted by John Smith');
// @todo Add the below assertions.
// Check source entity.
// Check create submission.
// Check save submission.
}