You are here

public function JsCollectionOptimizerTest::test in Flysystem 8

@covers \Drupal\flysystem\Asset\JsCollectionOptimizer @covers \Drupal\flysystem\Asset\CssCollectionOptimizer

File

tests/src/Unit/Asset/JsCollectionOptimizerTest.php, line 54

Class

JsCollectionOptimizerTest
@coversDefaultClass \Drupal\flysystem\Asset\JsCollectionOptimizer @group flysystem

Namespace

Drupal\Tests\flysystem\Unit\Asset

Code

public function test() {
  file_put_contents('vfs://flysystem/test.js', 'asdfasdf');
  touch('vfs://flysystem/test.js', REQUEST_TIME - 1000);
  $container = new ContainerBuilder();
  $container
    ->set('config.factory', $this
    ->getConfigFactoryStub([
    'system.performance' => [
      'stale_file_threshold' => 0,
    ],
  ]));
  \Drupal::setContainer($container);
  $grouper = $this
    ->prophesize(AssetCollectionGrouperInterface::class);
  $dumper = new AssetDumper();
  $state = $this
    ->getMock(StateInterface::class);
  $optimizer = new JsCollectionOptimizer($grouper
    ->reveal(), new JsOptimizer(), $dumper, $state);
  $optimizer
    ->deleteAll();
  $this
    ->assertFalse(file_exists('vfs://flysystem/test.js'));
  file_put_contents('vfs://flysystem/test.js', 'asdfasdf');
  touch('vfs://flysystem/test.js', REQUEST_TIME - 1000);
  $optimizer = new CssCollectionOptimizer($grouper
    ->reveal(), new CssOptimizer(), $dumper, $state);
  $optimizer
    ->deleteAll();
  $this
    ->assertFalse(file_exists('vfs://flysystem/test.js'));
}