diff --git a/tests/submission.file.test b/tests/submission.file.test index 9e988a6..44508f6 100644 --- a/tests/submission.file.test +++ b/tests/submission.file.test @@ -90,7 +90,7 @@ function testAuthFileRequiredSubmission() { // Create the node with a file component. $node = $this->createTestWebform(); - // Run the submission tests + // Run the submission tests. $this->fileRequiredSubmissionTest($node->nid); // Confirm the submission was successful. @@ -109,7 +109,7 @@ function testAnonFileRequiredSubmission() { // Logout. $this->drupalLogout(); - // Run the submission tests + // Run the submission tests. $this->fileRequiredSubmissionTest($node->nid); // Confirm the submission was successful. @@ -120,29 +120,35 @@ function testAnonFileRequiredSubmission() { /** * Confirm multiple files can be submitted by authenticated visitors. */ - // function testAuthMultipleFileSubmission() { - // // Create the node with a file component. - // $node = $this->createTestWebform(); - // - // // Submit the webform with multiple files. - // $edit = array(); - // $this->drupalPost('node/' . $node->nid, $edit, 'Submit', array(), array(), 'webform-client-form-' . $node->nid); - // } + function testAuthMultipleFileSubmission() { + // Create the node with a file component. + $node = $this->createTestWebform(); + + // Run the submission tests. + $this->fileMultipleSubmissionTest($node->nid); + + // Confirm the submission was successful. + $this->assertSubmission($node->nid); + $this->assertFileSubmission($node->nid); + } /** * Confirm multiple files can be submitted by anonymous visitors. */ - // function testAnonMultipleFileSubmission() { - // // Create the node with a file component. - // $node = $this->createTestWebform(); - // - // // Logout. - // $this->drupalLogout(); - // - // // Submit the webform with multiple files. - // $edit = array(); - // $this->drupalPost('node/' . $node->nid, $edit, 'Submit', array(), array(), 'webform-client-form-' . $node->nid); - // } + function testAnonMultipleFileSubmission() { + // Create the node with a file component. + $node = $this->createTestWebform(); + + // Logout. + $this->drupalLogout(); + + // Run the submission tests. + $this->fileMultipleSubmissionTest($node->nid); + + // Confirm the submission was successful. + $this->assertSubmission($node->nid); + $this->assertFileSubmission($node->nid); + } /** * Creates a webform with a text component and a file component. @@ -261,6 +267,22 @@ function getTestImage() { } /** + * Generate a test text file. + * + * @return object + * A file object. + */ + function getTestText() { + // Get a file to upload. + $file = current($this->drupalGetTestFiles('text')); + + // Add a filesize property to files as would be read by file_load(). + $file->filesize = filesize($file->uri); + + return $file; + } + + /** * Run file tests for a given Webform node. * * @param int $nid @@ -323,6 +345,43 @@ function fileRequiredSubmissionTest($nid) { } /** + * Run multiple-file tests for a given Webform node. + * + * @param int $nid + * The node ID to test against. + */ + function fileMultipleSubmissionTest($nid) { + $node = node_load($nid); + + // Make the text field required. + foreach ($node->webform['components'] as &$component) { + if ($component['type'] == 'file') { + $file_component = $component; + } + } + $file_component['form_key'] = 'file_2'; + $file_component['weight']++; + unset($file_component['cid']); + $node->webform['components'][] = $file_component; + node_save($node); + + // Reload the node. + $node = node_load($nid); + + // Generate example images. + $image = $this->getTestImage(); + $file = $this->getTestText(); + + // Submit the webform with a file. + $edit = array(); + $edit['files[submitted_file_1]'] = drupal_realpath($image->uri); + $edit['files[submitted_file_2]'] = drupal_realpath($file->uri); + $this->drupalPost('node/' . $nid, $edit, 'Submit', array(), array(), 'webform-client-form-' . $nid); + $this->assertResponse(200); + $this->assertText(t('Thanks!')); + } + + /** * Confirm a submission was found. * * @param int $nid