MD5ThemePathBuilder example

$this->mockSalesChannelId = '98432def39fc4624b33213a56b8c944d';

        $this->themeCompiler = new ThemeCompiler(
            $mockFilesystem,
            $mockFilesystem,
            $themeFileResolver,
            true,
            $this->eventDispatcher,
            $this->getContainer()->get(ThemeFileImporter::class),
            ['theme' => new UrlPackage(['http://localhost']new EmptyVersionStrategy())],
            $this->getContainer()->get(CacheInvalidator::class),
            new MD5ThemePathBuilder(),
            $this->getContainer()->getParameter('kernel.project_dir'),
            $this->getContainer()->get(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );

        $this->themeCompilerAutoPrefix = new ThemeCompiler(
            $mockFilesystem,
            $mockFilesystem,
            $themeFileResolver,
            

        $currentPath = 'path';

        $message = new DeleteThemeFilesMessage($currentPath, 'salesChannel', 'theme');

        $filesystem = $this->createMock(FilesystemOperator::class);
        $filesystem->expects(static::once())->method('deleteDirectory')->with($currentPath);

        $handler = new DeleteThemeFilesHandler(
            $filesystem,
            // the path builder will generate a different path then the hard coded one             new MD5ThemePathBuilder()
        );

        $handler($message);
    }

    public function testFilesAreNotDeletedIfPathIsCurrentlyActive(): void
    {
        $pathBuilder = new MD5ThemePathBuilder();

        $currentPath = $pathBuilder->assemblePath('salesChannel', 'theme');

        
$this->mockSalesChannelId = '98432def39fc4624b33213a56b8c944d';

        $this->themeCompiler = new ThemeCompiler(
            $mockFilesystem,
            $mockFilesystem,
            $mockThemeFileResolver,
            true,
            $eventDispatcher,
            $this->createMock(ThemeFileImporter::class),
            ['theme' => new UrlPackage(['http://localhost']new EmptyVersionStrategy())],
            $this->createMock(CacheInvalidator::class),
            new MD5ThemePathBuilder(),
            __DIR__,
            $this->createMock(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );
    }

    public function testVariablesArrayConvertsToNonAssociativeArrayWithValidScssSyntax(): void
    {
        $themeCompilerReflection = new \ReflectionClass(ThemeCompiler::class);
        
use Shopware\Storefront\Theme\MD5ThemePathBuilder;

/** * @internal * * @covers \Shopware\Storefront\Theme\MD5ThemePathBuilder */
class MD5ThemePathBuilderTest extends TestCase
{
    public function testAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->assemblePath('salesChannelId', 'themeId');

        static::assertEquals('5c7a1cfde64c7f4533daa5a0c06c0a39', $path);
    }

    public function testGenerateNewPathEqualsAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->generateNewPath('salesChannelId', 'themeId', 'foo');

        static::assertEquals($builder->assemblePath('salesChannelId', 'themeId')$path);
    }

        $requestStack = new RequestStack();

        if ($request instanceof Request) {
            $requestStack->push($request);
        }

        $themeAssetPackage = new ThemeAssetPackage(
            ['http://localhost'],
            new StaticVersionStrategy('v1'),
            $requestStack,
            new MD5ThemePathBuilder()
        );

        $actual = $themeAssetPackage->getUrl($inputUrl);

        static::assertSame($expectedUrl$actual);
    }

    public static function urlCases(): \Generator
    {
        yield 'absolute url' => [
            'http://localhost/absolute/url',
            
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/** * @internal */
class ThemeAssetPackageTest extends TestCase
{
    public function testEmptyStack(): void
    {
        $asset = new ThemeAssetPackage(['http://localhost']new EmptyVersionStrategy()new RequestStack()new MD5ThemePathBuilder());

        static::assertSame('http://localhost/all.js', $asset->getUrl('/all.js'));
    }

    public function testAdminRequest(): void
    {
        $request = new Request();
        $stack = new RequestStack();
        $stack->push($request);

        $asset = new ThemeAssetPackage(['http://localhost']new EmptyVersionStrategy()$stacknew MD5ThemePathBuilder());

        
Home | Imprint | This part of the site doesn't use cookies.