You are here

class ArchiveValidatorTest in Mini site 8

Class ArchiveValidatorTest.

Tests archive validator.

@group minisite

@package Drupal\testmode\Tests

Hierarchy

Expanded class hierarchy of ArchiveValidatorTest

File

tests/src/Unit/ArchiveValidatorTest.php, line 19

Namespace

Drupal\Tests\minisite\Unit
View source
class ArchiveValidatorTest extends UnitTestCase {

  /**
   * Test validateFiles() method.
   *
   * @dataProvider dataProviderValidate
   * @covers \Drupal\minisite\ArchiveValidator::validate
   */
  public function testValidate($files, $extensions, $message) {
    $this
      ->expectException(InvalidContentArchiveException::class);
    $this
      ->expectExceptionMessage($message);
    ArchiveValidator::validate($files, $extensions);
  }

  /**
   * Data provider for testValidateFiles.
   */
  public function dataProviderValidate() {
    return [
      [
        [
          'file.txt',
        ],
        [
          'ext',
        ],
        'A single top level directory is expected.',
      ],
      [
        [
          'file.txt',
          'dir1/file.txt',
        ],
        [
          'ext',
        ],
        'A single top level directory is expected.',
      ],
      [
        [
          'dir1/',
          'dir2/',
          'dir1/file.txt',
        ],
        [
          'ext',
        ],
        'A single top level directory is expected.',
      ],
      [
        [
          'dir1/file.txt',
        ],
        [
          'ext',
        ],
        sprintf('Missing required %s file.', AssetInterface::INDEX_FILE),
      ],
      [
        [
          'dir1/',
          'dir1/file.txt',
        ],
        [
          'ext',
        ],
        sprintf('Missing required %s file.', AssetInterface::INDEX_FILE),
      ],
      [
        [
          'dir1/' . AssetInterface::INDEX_FILE,
          'dir1/file.txt',
        ],
        [
          'html',
          'ext',
        ],
        'Archive has invalid content: File dir1/file.txt has invalid extension.',
      ],
      [
        [
          'dir1/' . AssetInterface::INDEX_FILE,
          'dir1/file.txt',
          'dir1/file2.txt',
        ],
        [
          'html',
          'ext',
        ],
        'Archive has invalid content: File dir1/file.txt has invalid extension.' . PHP_EOL . 'File dir1/file2.txt has invalid extension.',
      ],
      [
        [
          'dir1/' . AssetInterface::INDEX_FILE,
          'dir1/file.html',
          'dir1/' . str_repeat('a', 2048) . '/file2.html',
        ],
        [
          'html',
        ],
        'Archive has invalid content: File "dir1/' . str_repeat('a', 2048) . '/file2.html" path within the archive should be under 1986 characters in length.',
      ],
      // Special case testing for allowed root-level directories.
      // If the allowed root-level directory not correctly excluded - a
      // different exception will be thrown.
      [
        [
          '__MACOSX/',
          'dir1/' . AssetInterface::INDEX_FILE,
          'dir1/file.txt',
        ],
        [
          'html',
          'ext',
        ],
        'Archive has invalid content: File dir1/file.txt has invalid extension.',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArchiveValidatorTest::dataProviderValidate public function Data provider for testValidateFiles.
ArchiveValidatorTest::testValidate public function Test validateFiles() method.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340