You are here

class AssetCollectorTest in Entity Print 8.2

Test the asset collector service.

@group entity_print

Hierarchy

Expanded class hierarchy of AssetCollectorTest

File

tests/src/Unit/AssetCollectorTest.php, line 18

Namespace

Drupal\Tests\entity_print\Unit
View 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

Namesort descending Modifiers Type Description Overrides
AssetCollectorTest::getInfoParserMock protected function Gets an Info parser mock.
AssetCollectorTest::getThemeHandlerMock protected function Gets the theme handler mock.
AssetCollectorTest::testAlterCss public function Test that we can alter the CSS using the event.
AssetCollectorTest::testEventAlwaysFires public function CSS Alter event should always fire, even when no entries in the theme file.
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