You are here

function ContactAttachContactFormsTestCase::submitAttachmentWhenNoSettingsSet in Contact Attach 7

Submits contact forms with attachments when no settings are set.

Parameters

object $user: (optional) A fully-loaded $user object of the user to log in. Defaults to NULL.

1 call to ContactAttachContactFormsTestCase::submitAttachmentWhenNoSettingsSet()
ContactAttachContactFormsTestCase::testContactAttachContactForms in ./contact_attach.test
Tests the attachment functionality on the site-wide and user contact forms.

File

./contact_attach.test, line 431
Tests for the Contact Attach module.

Class

ContactAttachContactFormsTestCase
Tests the Contact Attach functionality for site-wide and user contact forms.

Code

function submitAttachmentWhenNoSettingsSet($user = NULL) {
  if ($user) {
    $this
      ->drupalLoginWithUserGlobalRolesUpdate($user);
  }
  foreach ($this->contact_forms as $contact_form => $permission) {

    // Ensure that the user can not send messages with attachments when no
    // settings have been set for the user's roles.
    $file = current($this
      ->drupalGetTestFiles('image', 1831));
    $this->message['files[contact_attach_1]'] = drupal_realpath($file->uri);
    $this
      ->drupalPost($contact_form, $this->message, t('Send message'));
    $this
      ->assertNoText(t('Your message has been sent.'));
    $this
      ->assertUniqueText(t('The specified file @filename could not be uploaded.', array(
      '@filename' => $file->filename,
    )));
    $this
      ->assertUniqueText(t('Only files with the following extensions are allowed: .'));
    $this
      ->assertUniqueText(t('The file is @filesize exceeding the maximum file size of 1 KB.', array(
      '@filesize' => format_size(filesize($file->uri)),
    )));

    // Ensure that a 1 byte file can be attached, but will still be refused
    // because no allowed extensions have been set for the user's roles.
    $tinyfile_name = 'tinyfile.txt';
    file_put_contents('public://' . $tinyfile_name, '1');
    $this->message['files[contact_attach_1]'] = drupal_realpath('public://' . $tinyfile_name);
    $this
      ->drupalPost($contact_form, $this->message, t('Send message'));
    $this
      ->assertNoText(t('Your message has been sent.'));
    $this
      ->assertUniqueText(t('The specified file @filename could not be uploaded. Only files with the following extensions are allowed: .', array(
      '@filename' => $tinyfile_name,
    )));
  }
  if ($user) {
    $this
      ->drupalLogoutWithUserGlobalRolesUpdate();
  }
}