You are here

public function FileValidatorTest::provideMaxSizeExceededTests 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::provideMaxSizeExceededTests()

File

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

Class

FileValidatorTest

Namespace

Symfony\Component\Validator\Tests\Constraints

Code

public function provideMaxSizeExceededTests() {

  // We have various interesting limit - size combinations to test.
  // Assume a limit of 1000 bytes (1 kB). Then the following table
  // lists the violation messages for different file sizes:
  // -----------+--------------------------------------------------------
  // Size       | Violation Message
  // -----------+--------------------------------------------------------
  // 1000 bytes | No violation
  // 1001 bytes | "Size of 1001 bytes exceeded limit of 1000 bytes"
  // 1004 bytes | "Size of 1004 bytes exceeded limit of 1000 bytes"
  //            | NOT: "Size of 1 kB exceeded limit of 1 kB"
  // 1005 bytes | "Size of 1.01 kB exceeded limit of 1 kB"
  // -----------+--------------------------------------------------------
  // As you see, we have two interesting borders:
  // 1000/1001 - The border as of which a violation occurs
  // 1004/1005 - The border as of which the message can be rounded to kB
  // Analogous for kB/MB.
  // Prior to Symfony 2.5, violation messages are always displayed in the
  // same unit used to specify the limit.
  // As of Symfony 2.5, the above logic is implemented.
  return array(
    // limit in bytes
    array(
      1001,
      1000,
      '1001',
      '1000',
      'bytes',
    ),
    array(
      1004,
      1000,
      '1004',
      '1000',
      'bytes',
    ),
    array(
      1005,
      1000,
      '1.01',
      '1',
      'kB',
    ),
    array(
      1000001,
      1000000,
      '1000001',
      '1000000',
      'bytes',
    ),
    array(
      1004999,
      1000000,
      '1005',
      '1000',
      'kB',
    ),
    array(
      1005000,
      1000000,
      '1.01',
      '1',
      'MB',
    ),
    // limit in kB
    array(
      1001,
      '1k',
      '1001',
      '1000',
      'bytes',
    ),
    array(
      1004,
      '1k',
      '1004',
      '1000',
      'bytes',
    ),
    array(
      1005,
      '1k',
      '1.01',
      '1',
      'kB',
    ),
    array(
      1000001,
      '1000k',
      '1000001',
      '1000000',
      'bytes',
    ),
    array(
      1004999,
      '1000k',
      '1005',
      '1000',
      'kB',
    ),
    array(
      1005000,
      '1000k',
      '1.01',
      '1',
      'MB',
    ),
    // limit in MB
    array(
      1000001,
      '1M',
      '1000001',
      '1000000',
      'bytes',
    ),
    array(
      1004999,
      '1M',
      '1005',
      '1000',
      'kB',
    ),
    array(
      1005000,
      '1M',
      '1.01',
      '1',
      'MB',
    ),
    // limit in KiB
    array(
      1025,
      '1Ki',
      '1025',
      '1024',
      'bytes',
    ),
    array(
      1029,
      '1Ki',
      '1029',
      '1024',
      'bytes',
    ),
    array(
      1030,
      '1Ki',
      '1.01',
      '1',
      'KiB',
    ),
    array(
      1048577,
      '1024Ki',
      '1048577',
      '1048576',
      'bytes',
    ),
    array(
      1053818,
      '1024Ki',
      '1029.12',
      '1024',
      'KiB',
    ),
    array(
      1053819,
      '1024Ki',
      '1.01',
      '1',
      'MiB',
    ),
    // limit in MiB
    array(
      1048577,
      '1Mi',
      '1048577',
      '1048576',
      'bytes',
    ),
    array(
      1053818,
      '1Mi',
      '1029.12',
      '1024',
      'KiB',
    ),
    array(
      1053819,
      '1Mi',
      '1.01',
      '1',
      'MiB',
    ),
  );
}