diff --git a/tests/webform_entity.test b/tests/webform_entity.test new file mode 100644 index 0000000000000000000000000000000000000000..6b9bea9c1baac690f785ea4426e70f60d2f144cb --- /dev/null +++ b/tests/webform_entity.test @@ -0,0 +1,132 @@ + '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' => '', + '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 d3814a99108b357ae50c16aec6696fad154571e6..51ab1f5eabb850f05ec23d167fda3956e916650b 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 b9d7ea652408c9049b5b9ccf85a19ee2b6e46a3c..877a1156bec96aa6f3f8b353239608e32a1c3f08 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 {