You are here

public function FileValidatorTest::uploadedFileErrorProvider in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Tests/Constraints/FileValidatorTest.php \Symfony\Component\Validator\Tests\Constraints\FileValidatorTest::uploadedFileErrorProvider()

File

vendor/symfony/validator/Tests/Constraints/FileValidatorTest.php, line 434

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() / 1048576,
        '{{ suffix }}' => 'MiB',
      ),
    );

    // 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() / 1048576,
        '{{ suffix }}' => 'MiB',
      ),
      '1000M',
    );

    // 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 }}' => '0.1',
        '{{ suffix }}' => 'MB',
      ),
      '100K',
    );
  }
  return $tests;
}