Projet

Général

Profil

Révision c9e51f47

Ajouté par Julien Enselme il y a environ 7 ans

Udpate to 7.54

Voir les différences:

drupal7/modules/file/tests/file.test
596 596
    $this->doTestTemporaryFileRemovalExploit($victim_uid, $attacker_uid);
597 597
  }
598 598

  
599
  /**
600
   * Tests validation with the Upload button.
601
   */
602
  function testWidgetValidation() {
603
    $type_name = 'article';
604
    $field_name = strtolower($this->randomName());
605
    $this->createFileField($field_name, $type_name);
606
    $this->updateFileField($field_name, $type_name, array('file_extensions' => 'txt'));
607

  
608
    foreach (array('nojs', 'js') as $type) {
609
      // Create node and prepare files for upload.
610
      $node = $this->drupalCreateNode(array('type' => 'article'));
611
      $nid = $node->nid;
612
      $this->drupalGet("node/$nid/edit");
613
      $test_file_text = $this->getTestFile('text');
614
      $test_file_image = $this->getTestFile('image');
615
      $field = field_info_field($field_name);
616
      $name = 'files[' . $field_name . '_' . LANGUAGE_NONE . '_0]';
617

  
618
      // Upload file with incorrect extension, check for validation error.
619
      $edit[$name] = drupal_realpath($test_file_image->uri);
620
      switch ($type) {
621
        case 'nojs':
622
          $this->drupalPost(NULL, $edit, t('Upload'));
623
          break;
624

  
625
        case 'js':
626
          $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]');
627
          $this->drupalPostAJAX(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value']));
628
          break;
629
      }
630
      $error_message = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => 'txt'));
631
      $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', array('%type' => $type)));
632

  
633
      // Upload file with correct extension, check that error message is removed.
634
      $edit[$name] = drupal_realpath($test_file_text->uri);
635
      switch ($type) {
636
        case 'nojs':
637
          $this->drupalPost(NULL, $edit, t('Upload'));
638
          break;
639

  
640
        case 'js':
641
          $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]');
642
          $this->drupalPostAJAX(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value']));
643
          break;
644
      }
645
      $this->assertNoRaw($error_message, t('Validation error removed when file with correct extension uploaded (JSMode=%type).', array('%type' => $type)));
646
    }
647
  }
648

  
599 649
  /**
600 650
   * Helper for testing exploiting the temporary file removal using fid.
601 651
   *

Formats disponibles : Unified diff