summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwodenx2015-11-02 15:49:41 (GMT)
committerAaron Bauman2015-11-02 15:49:41 (GMT)
commit5b7d0e28aa3901f230c9a977e388de6a3fa2dd1c (patch)
treec6d59472bb3d63a2aa8ca207872d4bfedfe3b7ae
parentae96410418dc433ac0d1fd796f015f713e33cb51 (diff)
Issue #2079813 by wodenx: webform submission entity not saved properly
-rw-r--r--tests/webform_entity.test132
-rw-r--r--webform_entity.info1
-rw-r--r--webform_entity.module4
3 files changed, 137 insertions, 0 deletions
diff --git a/tests/webform_entity.test b/tests/webform_entity.test
new file mode 100644
index 0000000..6b9bea9
--- /dev/null
+++ b/tests/webform_entity.test
@@ -0,0 +1,132 @@
+<?php
+class WebformEntityTestCase extends DrupalWebTestCase {
+ /**
+ * Returns information about this test case.
+ *
+ * @return
+ * An array of information about this test case
+ */
+ public static function getInfo() {
+ return array(
+ 'name' => 'Webform Entity',
+ 'description' => 'Ensure that Webform Entity functions correctly.',
+ 'group' => 'Webform',
+ );
+ }
+
+ /**
+ * @see ServicesWebTestCase::setUp()
+ */
+ /* Restore this commenting-out to test using local db (a bit faster that way).
+ public function setUp() {
+ parent::setUp('webform_entity');
+ }
+ // */ public function setUp() { $this->setup = TRUE; } public function tearDown() {}
+
+ public function testSubmissionCRUD() {
+ $node = $this->createWebform();
+ $data = array(
+ 'nid' => $node->nid,
+ 'bundle' => 'webform',
+ 'data' => array(
+ 1 => array($this->randomName(8)),
+ 2 => array($this->randomName(8)),
+ ),
+ );
+ $submission = entity_create('webform_submission_entity', $data);
+ entity_save('webform_submission_entity', $submission);
+ $this->assertTrue($submission->sid, 'The saved submission has a submission id');
+ // @todo - more tests. This is merely meant to illustrate a specific bug.
+ }
+
+ /**
+ * Creates a webform node for testing.
+ *
+ * @return array
+ * A webform.
+ *
+ * @author chriso
+ */
+ protected function createWebform() {
+ $values = array(
+ 'title' => $this->randomName(8),
+ 'status' => '1',
+ 'type' => 'webform',
+ 'webform' => array(
+ 'confirmation' => '',
+ 'confirmation_format' => NULL,
+ 'redirect_url' => '<confirmation>',
+ 'status' => '1',
+ 'block' => '0',
+ 'teaser' => '0',
+ 'allow_draft' => '0',
+ 'auto_save' => '0',
+ 'submit_notice' => '1',
+ 'submit_text' => '',
+ 'submit_limit' => '-1',
+ 'submit_interval' => '-1',
+ 'total_submit_limit' => '-1',
+ 'total_submit_interval' => '-1',
+ 'record_exists' => TRUE,
+ 'roles' => array(
+ DRUPAL_AUTHENTICATED_RID,
+ ),
+ 'emails' => array(),
+ 'components' => array(
+ 1 => array(
+ 'cid' => '1',
+ 'pid' => '0',
+ 'form_key' => $this->randomName(8),
+ 'name' => $this->randomName(32),
+ 'type' => 'textfield',
+ 'value' => '',
+ 'extra' => array(
+ 'title_display' => 'before',
+ 'private' => 0,
+ 'width' => '',
+ 'maxlength' => '',
+ 'field_prefix' => '',
+ 'field_suffix' => '',
+ 'disabled' => 0,
+ 'unique' => 0,
+ 'description' => '',
+ 'placeholder' => '',
+ 'attributes' => array(),
+ ),
+ 'required' => '0',
+ 'weight' => '1',
+ 'page_num' => 1,
+ ),
+ 2 => array(
+ 'cid' => '2',
+ 'pid' => '0',
+ 'form_key' => $this->randomName(8),
+ 'name' => $this->randomName(32),
+ 'type' => 'textfield',
+ 'value' => '',
+ 'extra' => array(
+ 'title_display' => 'before',
+ 'private' => 0,
+ 'width' => '',
+ 'maxlength' => '',
+ 'field_prefix' => '',
+ 'field_suffix' => '',
+ 'disabled' => 0,
+ 'unique' => 0,
+ 'description' => '',
+ 'placeholder' => '',
+ 'attributes' => array(),
+ ),
+ 'required' => '0',
+ 'weight' => '2',
+ 'page_num' => 1,
+ ),
+ ),
+ 'conditionals' => array(),
+ ),
+ );
+ $node = $this->drupalCreateNode($values);
+ return $node;
+ }
+
+} \ No newline at end of file
diff --git a/webform_entity.info b/webform_entity.info
index d3814a9..51ab1f5 100644
--- a/webform_entity.info
+++ b/webform_entity.info
@@ -7,3 +7,4 @@ dependencies[] = entity
files[] = webform_entity.module
files[] = webform_entity.migrate.inc
+files[] = tests/webform_entity.test
diff --git a/webform_entity.module b/webform_entity.module
index b9d7ea6..877a115 100644
--- a/webform_entity.module
+++ b/webform_entity.module
@@ -574,6 +574,10 @@ class WebformSubmissionsController extends DrupalDefaultEntityController {
$node = node_load($submission->nid);
if (!isset($submission->sid)) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
+ if (!empty($submission->is_new)) {
+ // Necessary because webform won't save the submission if is_new is set to TRUE.
+ unset($submission->is_new);
+ }
webform_submission_insert($node, $submission);
}
else {