WebformEntityTest.php in Webform 8.5
File
tests/src/Functional/WebformEntityTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
class WebformEntityTest extends WebformBrowserTestBase {
public static $modules = [
'node',
'webform',
'webform_test_submissions',
];
protected static $testWebforms = [
'test_submissions',
];
protected $submissionStorage;
protected function setUp() {
parent::setUp();
$this->submissionStorage = \Drupal::entityTypeManager()
->getStorage('webform_submission');
}
public function testWebform() {
$webform_contact = Webform::load('contact');
$this
->assertEqual($webform_contact
->getElementsDefaultData(), [
'name' => '[current-user:display-name]',
'email' => '[current-user:mail]',
]);
$webform_test_submissions = Webform::load('test_submissions');
$elements = $webform_test_submissions
->getElementsInitialized();
$this
->assert(is_array($elements));
$columns = $webform_test_submissions
->getElementsInitializedFlattenedAndHasValue();
$this
->assertEqual(array_keys($columns), [
'first_name',
'last_name',
'sex',
'dob',
'node',
'colors',
'likert',
'address',
]);
$webform_test_submissions
->set('elements', "not\nvalid\nyaml")
->save();
$this
->assertEqual($webform_test_submissions
->getElementsInitialized(), []);
$this
->assertEqual($webform_test_submissions
->getElementsInitializedFlattenedAndHasValue(), []);
$this
->assertEqual($this->submissionStorage
->getTotal($webform_test_submissions), 4);
$webform_test_submissions
->delete();
$this
->assertEqual($this->submissionStorage
->getTotal($webform_test_submissions), 0);
$this
->assertEqual(\Drupal::state()
->get('webform.webform.' . $webform_test_submissions
->id()), NULL);
}
}