class AssetCollectorTest in Entity Print 8.2
Test the asset collector service.
@group entity_print
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\entity_print\Unit\AssetCollectorTest
Expanded class hierarchy of AssetCollectorTest
File
- tests/
src/ Unit/ AssetCollectorTest.php, line 18
Namespace
Drupal\Tests\entity_print\UnitView source
class AssetCollectorTest extends UnitTestCase {
/**
* CSS Alter event should always fire, even when no entries in the theme file.
*/
public function testEventAlwaysFires() {
$event_dispatcher = $this
->prophesize(EventDispatcherInterface::class);
$event_dispatcher
->dispatch(Argument::cetera())
->shouldBeCalled();
$asset_collector = new AssetCollector($this
->getThemeHandlerMock()
->reveal(), $this
->getInfoParserMock()
->reveal(), $event_dispatcher
->reveal());
$this
->assertEquals([], $asset_collector
->getCssLibraries([]));
}
/**
* Test that we can alter the CSS using the event.
*/
public function testAlterCss() {
$event_dispatcher = $this
->prophesize(EventDispatcherInterface::class);
$event_dispatcher
->dispatch(Argument::cetera())
->will(function ($args) {
// Argument 1 is the PrintCssAlterEvent.
$args[1]
->getBuild()[] = 'my_theme/my_css';
});
$asset_collector = new AssetCollector($this
->getThemeHandlerMock()
->reveal(), $this
->getInfoParserMock()
->reveal(), $event_dispatcher
->reveal());
$this
->assertEquals([
'my_theme/my_css',
], $asset_collector
->getCssLibraries([]));
}
/**
* Gets the theme handler mock.
*/
protected function getThemeHandlerMock() {
$theme = $this
->prophesize(Extension::class);
$theme
->getPathname()
->willReturn('info_file_path');
$theme_handler = $this
->prophesize(ThemeHandlerInterface::class);
$theme_handler
->getDefault()
->willReturn('default_theme');
$theme_handler
->getTheme('default_theme')
->willReturn($theme);
return $theme_handler;
}
/**
* Gets an Info parser mock.
*/
protected function getInfoParserMock() {
$info_parser = $this
->prophesize(InfoParserInterface::class);
$info_parser
->parse('info_file_path')
->willReturn([]);
return $info_parser;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssetCollectorTest:: |
protected | function | Gets an Info parser mock. | |
AssetCollectorTest:: |
protected | function | Gets the theme handler mock. | |
AssetCollectorTest:: |
public | function | Test that we can alter the CSS using the event. | |
AssetCollectorTest:: |
public | function | CSS Alter event should always fire, even when no entries in the theme file. | |
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 |