YamlFormSubmissionTest.php in YAML Form 8
File
src/Tests/YamlFormSubmissionTest.php
View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\yamlform\Entity\YamlFormSubmission;
class YamlFormSubmissionTest extends YamlFormTestBase {
public function testYamlFormSubmission() {
list($yamlform, $submissions) = $this
->createYamlFormWithSubmissions();
$yamlform_submission = reset($submissions);
$this
->assert($yamlform_submission instanceof YamlFormSubmission, '$yamlform_submission instanceof YamlFormSubmission');
$this
->assertEqual($yamlform_submission
->getYamlForm()
->id(), $yamlform
->id());
$this
->assertNull($yamlform_submission
->getSourceEntity());
$yamlform_submission
->set('uri', NULL)
->save();
$this
->assertEqual($yamlform_submission
->getSourceUrl()
->toString(), $yamlform
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString());
$this
->createUsers();
$yamlform_submission
->set('entity_type', 'user')
->set('entity_id', $this->normalUser
->id())
->save();
$this
->assertEqual($yamlform_submission
->getSourceUrl()
->toString(), $this->normalUser
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString());
try {
YamlFormSubmission::create();
$this
->fail('Form id (yamlform_id) is required to create a form submission.');
} catch (\Exception $exception) {
$this
->pass('Form id (yamlform_id) is required to create a form submission.');
}
$yamlform_submission = YamlFormSubmission::create([
'yamlform_id' => $yamlform
->id(),
'data' => [
'custom' => 'value',
],
]);
$this
->assertEqual($yamlform_submission
->getData(), [
'custom' => 'value',
]);
$yamlform_submission
->save();
$this
->assertEqual($yamlform_submission
->label(), $yamlform
->label() . ': Submission #' . $yamlform_submission
->serial());
}
}