class ArchiveValidatorTest in Mini site 8
Class ArchiveValidatorTest.
Tests archive validator.
@group minisite
@package Drupal\testmode\Tests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\minisite\Unit\ArchiveValidatorTest
Expanded class hierarchy of ArchiveValidatorTest
File
- tests/
src/ Unit/ ArchiveValidatorTest.php, line 19
Namespace
Drupal\Tests\minisite\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArchiveValidatorTest:: |
public | function | Data provider for testValidateFiles. | |
ArchiveValidatorTest:: |
public | function | Test validateFiles() method. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |