WebformElementSameTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementSameTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
class WebformElementSameTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_same',
];
public function testSame() {
$webform = Webform::load('test_element_same');
$this
->postSubmission($webform);
$this
->assertRaw("textfield_source: '{some value}'\ntextfield_same: 1\ntextfield_destination: '{some value}'\nwebform_name_source:\n title: Mr\n first: John\n middle: Adam\n last: Smith\n suffix: Jr\n degree: Dr\nwebform_name_same: 1\nwebform_name_destination:\n title: Mr\n first: John\n middle: Adam\n last: Smith\n suffix: Jr\n degree: Dr\ntextfield_multiple_source:\n - '{one value}'\n - '{two value}'\ntextfield_multiple_same: 1\ntextfield_multiple_destination:\n - '{one value}'\n - '{two value}'");
$edit = [
'textfield_same' => FALSE,
'webform_name_same' => FALSE,
'textfield_multiple_same' => FALSE,
];
$this
->postSubmission($webform, $edit);
$this
->assertRaw('textfield_destination field is required.');
$this
->assertRaw('webform_name_destination field is required.');
$this
->assertRaw('textfield_multiple_destination field is required.');
$edit = [
'textfield_same' => FALSE,
'textfield_destination' => '{some other value}',
'webform_name_same' => FALSE,
'webform_name_destination[title][select]' => 'Mrs',
'webform_name_destination[first]' => '{first}',
'webform_name_destination[middle]' => '{middle}',
'webform_name_destination[last]' => '{last}',
'webform_name_destination[suffix]' => '{suffix}',
'webform_name_destination[degree]' => '{degree}',
'textfield_multiple_same' => FALSE,
'textfield_multiple_destination[items][0][_item_]' => '{three value}',
];
$sid = $this
->postSubmission($webform, $edit);
$this
->assertRaw("textfield_source: '{some value}'\ntextfield_same: 0\ntextfield_destination: '{some other value}'\nwebform_name_source:\n title: Mr\n first: John\n middle: Adam\n last: Smith\n suffix: Jr\n degree: Dr\nwebform_name_same: 0\nwebform_name_destination:\n title: Mrs\n first: '{first}'\n middle: '{middle}'\n last: '{last}'\n suffix: '{suffix}'\n degree: '{degree}'\ntextfield_multiple_source:\n - '{one value}'\n - '{two value}'\ntextfield_multiple_same: 0\ntextfield_multiple_destination:\n - '{three value}'");
$webform_submission = WebformSubmission::load($sid);
$this
->assertNotEqual($webform_submission
->getElementData('textfield_source'), $webform_submission
->getElementData('textfield_destination'));
$webform_submission
->setElementData('textfield_same', TRUE);
$webform_submission
->save();
$this
->assertEqual($webform_submission
->getElementData('textfield_source'), $webform_submission
->getElementData('textfield_destination'));
}
}