You are here

public function FileUploadSecureValidatorTest::fileUploadScenariosProvider in File Upload Secure Validator 8

Scenario related data are created in this function.

File

tests/src/Unit/FileUploadSecureValidatorTest.php, line 38

Class

FileUploadSecureValidatorTest
A class for unit testing the file_upload_secure_validator service.

Namespace

Drupal\Tests\file_upload_secure_validator\Unit

Code

public function fileUploadScenariosProvider() {
  return [
    [
      'case' => 'True extension',
      'uri' => dirname(__FILE__) . '/resources/original_pdf.pdf',
      'mimetype' => 'application/pdf',
      'expectedError' => NULL,
    ],
    [
      'case' => 'Falsified extension',
      'uri' => dirname(__FILE__) . '/resources/original_pdf.txt',
      'mimetype' => 'text/plain',
      // Setting this up as a new TranslatableMarkup with our mock translation
      // manager; otherwise assertEquals complains about non-identical objects
      // based on the attached TranslationManager service.
      'expectedError' => new TranslatableMarkup('There was a problem with this file. The uploaded file is of type @extension but the real content seems to be @real_extension', [
        '@extension' => 'text/plain',
        '@real_extension' => 'application/pdf',
      ], [], $this
        ->getTranslationManagerMock()),
    ],
    [
      'case' => 'CSV extension',
      'uri' => dirname(__FILE__) . '/resources/original_csv.csv',
      'mimetype' => 'text/csv',
      'expectedError' => NULL,
    ],
    [
      'case' => 'XML extension',
      'uri' => dirname(__FILE__) . '/resources/original_xml.xml',
      'mimetype' => 'text/xml',
      'expectedError' => NULL,
    ],
    [
      'case' => 'SVG extension',
      'uri' => dirname(__FILE__) . '/resources/original_svg_no_headers.svg',
      'mimetype' => 'image/svg+xml',
      'expectedError' => NULL,
    ],
    [
      'case' => 'PO extension',
      'uri' => dirname(__FILE__) . '/resources/original_po.po',
      'mimetype' => 'application/octet-stream',
      'expectedError' => NULL,
    ],
    [
      'case' => 'Certificate extensions',
      'uri' => dirname(__FILE__) . '/resources/original_crt.crt',
      'mimetype' => 'application/x-x509-ca-cert',
      'expectedError' => NULL,
    ],
    [
      'case' => 'OpenOffice docx extension',
      'uri' => dirname(__FILE__) . '/resources/original_docx.docx',
      'mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      'expectedError' => NULL,
    ],
    [
      'case' => 'OpenOffice xlsx extension',
      'uri' => dirname(__FILE__) . '/resources/original_xlsx.xlsx',
      'mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      'expectedError' => NULL,
    ],
  ];
}