public function FileValidatorTest::uploadedFileErrorProvider

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php, line 308

Class

FileValidatorTest

Namespace

Symfony\Component\Validator\Tests\Constraints

Code

public function uploadedFileErrorProvider() {
  $tests = array(
    array(
      UPLOAD_ERR_FORM_SIZE,
      'uploadFormSizeErrorMessage',
    ),
    array(
      UPLOAD_ERR_PARTIAL,
      'uploadPartialErrorMessage',
    ),
    array(
      UPLOAD_ERR_NO_FILE,
      'uploadNoFileErrorMessage',
    ),
    array(
      UPLOAD_ERR_NO_TMP_DIR,
      'uploadNoTmpDirErrorMessage',
    ),
    array(
      UPLOAD_ERR_CANT_WRITE,
      'uploadCantWriteErrorMessage',
    ),
    array(
      UPLOAD_ERR_EXTENSION,
      'uploadExtensionErrorMessage',
    ),
  );
  if (class_exists('Symfony\\Component\\HttpFoundation\\File\\UploadedFile')) {

    // when no maxSize is specified on constraint, it should use the ini value
    $tests[] = array(
      UPLOAD_ERR_INI_SIZE,
      'uploadIniSizeErrorMessage',
      array(
        '{{ limit }}' => UploadedFile::getMaxFilesize(),
        '{{ suffix }}' => 'bytes',
      ),
    );

    // it should use the smaller limitation (maxSize option in this case)
    $tests[] = array(
      UPLOAD_ERR_INI_SIZE,
      'uploadIniSizeErrorMessage',
      array(
        '{{ limit }}' => 1,
        '{{ suffix }}' => 'bytes',
      ),
      '1',
    );

    // it correctly parses the maxSize option and not only uses simple string comparison
    // 1000M should be bigger than the ini value
    $tests[] = array(
      UPLOAD_ERR_INI_SIZE,
      'uploadIniSizeErrorMessage',
      array(
        '{{ limit }}' => UploadedFile::getMaxFilesize(),
        '{{ suffix }}' => 'bytes',
      ),
      '1000M',
    );
  }
  return $tests;
}