You are here

function ContactAttachContactFormsTestCase::testContactAttachContactForms in Contact Attach 7

Tests the attachment functionality on the site-wide and user contact forms.

File

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

Class

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

Code

function testContactAttachContactForms() {
  $this->contact_forms = array(
    'contact' => 'attach files on site-wide contact form',
    'user/' . $this->admin_user->uid . '/contact' => 'attach files on personal contact forms',
  );
  $this->contact_forms_short = array(
    'site' => 'contact',
    'user' => 'user/' . $this->admin_user->uid . '/contact',
  );
  $this->message = array(
    'name' => 'Kalle Klovn',
    'mail' => 'kalle.klovn@example.com',
    'subject' => 'Test message',
    'message' => "This is a test message with 1 attachment.",
  );
  $this->file_field_types = array(
    'simple_file_field',
    'managed_file_field',
  );

  // We need to test everything with and without the file module enabled.
  foreach ($this->file_field_types as $this->file_field_type) {
    if ($this->file_field_type === 'managed_file_field') {
      module_enable(array(
        'file',
      ), FALSE);
    }

    // Check the existence of attachment fields on the site-wide and personal
    // contact forms with and without permissions granted.
    $this
      ->checkExistenceOfAttachmentFields(DRUPAL_ANONYMOUS_RID);
    $this
      ->checkExistenceOfAttachmentFields(DRUPAL_AUTHENTICATED_RID, $this->auth_user);

    // Check to see that the right field type is used for attachments.
    $this
      ->checkAttachmentFieldType();

    // Verify that the user can not send messages with attachments when the user
    // has permission to attach files, but no settings have been set.
    $this
      ->submitAttachmentWhenNoSettingsSet();
    $this
      ->submitAttachmentWhenNoSettingsSet($this->auth_user);

    // Verify that the correct number of attachments appear on the contact forms
    // after this setting has been set.
    $this->attachment_numbers = array();
    $this
      ->checkNumberOfAttachmentFields(DRUPAL_ANONYMOUS_RID, '2');
    $this
      ->checkNumberOfAttachmentFields(DRUPAL_AUTHENTICATED_RID, '5', $this->auth_user);

    // Ensure that the number of attachments for the specific role overrides the
    // number of attachments defined for the authenticated user role.
    $this
      ->checkNumberOfAttachmentFields($this->created_role_rid, '4', $this->specific_role_user);

    // Ensure that the number of attachments for the user's second role is
    // accounted for, but that the number of attachments of the first created
    // role is used, as it's higher.
    $this
      ->checkNumberOfAttachmentFields($this->created_role_2_rid, '3', $this->specific_role_user);

    // Verify that the correct allowed extensions and maximum file size is taken
    // into account after these settings have been set.
    $this->extensions = array();
    $this->uploadsizes = array();
    $this
      ->submitWithAttachments(DRUPAL_ANONYMOUS_RID, 'html', '0.00107421875');
    $this
      ->submitWithAttachments(DRUPAL_AUTHENTICATED_RID, 'sql', '0.00131835938', $this->auth_user);

    // Ensure that the maximum allowed file size for the specific role overrides
    // the maximum allowed file size defined for the authenticated user role.
    $this
      ->submitWithAttachments($this->created_role_rid, 'patch', '0.00126953125', $this->specific_role_user);

    // Ensure that the settings for the user's second role is accounted for, but
    // that the maximum upload size of the first created role is used, as it's
    // higher.
    $this
      ->submitWithAttachments($this->created_role_2_rid, 'tgv', '0.001171875', $this->specific_role_user);

    // Reset all of the module's persistent variables and users' permissions
    // for the next run.
    $this
      ->resetPersistentVariablesAndPermissions();
  }
}