This repository was archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathTwigExtensionTest.php
More file actions
53 lines (46 loc) · 2.01 KB
/
TwigExtensionTest.php
File metadata and controls
53 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @copyright 2017-present Hostnet B.V.
*/
declare(strict_types=1);
namespace Hostnet\Bundle\WebpackBundle\Twig;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Twig\Loader\LoaderInterface;
/**
* @covers \Hostnet\Bundle\WebpackBundle\Twig\TwigExtension
*/
class TwigExtensionTest extends TestCase
{
use ProphecyTrait;
public function testExtension(): void
{
$loader = $this->prophesize(LoaderInterface::class)->reveal();
$extension = new TwigExtension($loader, __DIR__, '/', '/bundles', '/shared.js', '/shared.css');
self::assertEquals('webpack', $extension->getName());
self::assertEquals(['js' => false, 'css' => false], $extension->webpackAsset('@AppBundle/app.js'));
self::assertEquals('/shared.js?0', $extension->webpackCommonJs());
self::assertEquals('/shared.css?0', $extension->webpackCommonCss());
}
/**
* @dataProvider assetProvider
*/
public function testAssets($expected, $asset, $web_dir, $dump_path, $public_path): void
{
$loader = $this->prophesize(LoaderInterface::class)->reveal();
$extension = new TwigExtension($loader, $web_dir, $public_path, $dump_path, '', '');
self::assertEquals($expected, $extension->webpackPublic($asset));
}
public function assetProvider(): iterable
{
return [
['/bundles/img.png', 'img.png', __DIR__ . '/web/', '/bundles/', '/'],
['/img.png', 'img.png', __DIR__ . 'web/', '/', '/'],
['/bundles/app/img.png', '@App/img.png', __DIR__ . '/../web/', '/bundles/', '/'],
['/some/dir/app/img.png', '@App/img.png', __DIR__ . './web/', '/some/dir/', '/'],
['/bundles/some/img.png', '@SomeBundle/img.png', __DIR__ . '/../web/', '/bundles/', '/'],
['/bundles/some/test/img.png', '@SomeBundle/test/img.png', './web/', '/bundles/', '/'],
['/something/else/some/test/img.png', '@SomeBundle/test/img.png', '/web/', '/something/else/', '/'],
];
}
}