class AdvDefTest in Image Optimize Binaries 8
Tests AdvDef image optimize plugin.
@group imageapi_optimize
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\imageapi_optimize_binaries\Unit\BinaryTestCase
- class \Drupal\Tests\imageapi_optimize_binaries\Unit\AdvDefTest
- class \Drupal\Tests\imageapi_optimize_binaries\Unit\BinaryTestCase
Expanded class hierarchy of AdvDefTest
File
- tests/
src/ Unit/ AdvDefTest.php, line 12
Namespace
Drupal\Tests\imageapi_optimize_binaries\UnitView source
class AdvDefTest extends BinaryTestCase {
/**
* Test that the default config of the plugin is set.
*/
public function testDefaultConfig() {
$config = [];
$loggerMock = $this
->getLoggerMock();
$imageFactoryMock = $this
->getImageFactoryMock();
$fileSystemMock = $this
->getFileSystemMock();
$shellOperationsMock = $this
->getShellOperationsMock();
$advdef = new AdvDef($config, 'advdef', [], $loggerMock, $imageFactoryMock, $fileSystemMock, $shellOperationsMock);
$this
->assertArrayHasKey('recompress', $advdef
->defaultConfiguration());
$this
->assertArrayHasKey('mode', $advdef
->defaultConfiguration());
}
/**
* Test that the AdvDef plugin does not run on JPGs
*/
public function testOnlyApplyToPNG() {
$config = [];
$loggerMock = $this
->getLoggerMock();
$imageFactoryMock = $this
->getImageFactoryMock();
$fileSystemMock = $this
->getFileSystemMock();
$shellOperationsMock = $this
->getShellOperationsMock();
$advdef = new AdvDef($config, 'advdef', [], $loggerMock, $imageFactoryMock, $fileSystemMock, $shellOperationsMock);
$imagePNGMock = $this
->createMock('\\Drupal\\Core\\Image\\ImageInterface');
$imagePNGMock
->method('getMimeType')
->willReturn('image/jpeg');
$imageFactoryMock
->method('get')
->willReturn($imagePNGMock);
// Assert no call is made through to the shell commands.
$shellOperationsMock
->expects($this
->never())
->method('execShellCommand');
// And assert that a 'jpg' isn't processed.
$this
->assertFalse($advdef
->applyToImage('public://test_image.jpg'));
}
/**
* @dataProvider advdefProvider
*/
public function testPNGOptimized($config, $options) {
$loggerMock = $this
->getLoggerMock();
$imageFactoryMock = $this
->getImageFactoryMock();
$fileSystemMock = $this
->getFileSystemMock();
$shellOperationsMock = $this
->getShellOperationsMock();
$advdef = new AdvDef([
'data' => $config,
], 'advdef', [], $loggerMock, $imageFactoryMock, $fileSystemMock, $shellOperationsMock);
$imagePNGMock = $this
->createMock('\\Drupal\\Core\\Image\\ImageInterface');
$imagePNGMock
->method('getMimeType')
->willReturn('image/png');
$imageFactoryMock
->method('get')
->willReturn($imagePNGMock);
$shellOperationsMock
->expects($this
->once())
->method('execShellCommand')
->with($this
->equalTo('advdef'), $this
->identicalTo($options), $this
->identicalTo([
'public://test_image.png',
]));
$advdef
->applyToImage('public://test_image.png');
}
/**
* Provides config and the associated options that should be sent to advdef for thos options.
*
* @return array
*/
public function advdefProvider() {
$cases = [];
$cases[] = [
[],
[
'--quiet',
'--recompress',
'-3',
],
];
$cases[] = [
[
'recompress' => FALSE,
],
[
'--quiet',
'-3',
],
];
$cases[] = [
[
'recompress' => FALSE,
'mode' => 1,
],
[
'--quiet',
'-1',
],
];
$cases[] = [
[
'mode' => 1,
],
[
'--quiet',
'--recompress',
'-1',
],
];
$cases[] = [
[
'mode' => 9,
],
[
'--quiet',
'--recompress',
'-9',
],
];
return $cases;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdvDefTest:: |
public | function | Provides config and the associated options that should be sent to advdef for thos options. | |
AdvDefTest:: |
public | function | Test that the default config of the plugin is set. | |
AdvDefTest:: |
public | function | Test that the AdvDef plugin does not run on JPGs | |
AdvDefTest:: |
public | function | @dataProvider advdefProvider | |
BinaryTestCase:: |
protected | function | ||
BinaryTestCase:: |
protected | function | ||
BinaryTestCase:: |
protected | function | ||
BinaryTestCase:: |
protected | function | ||
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 |