Script example

$context = [...['scope' => $scope], ...$this->values];
        $lastModified = $this->lastModified ?? $scope->getCurrentTime();
        $name = $this->identifier ?? $this->getName();

        $options = ['auto_reload' => true];
        if (!$this->debug) {
            $options['cache'] = new FilesystemCache($this->cacheDir . '/' . $name);
        } else {
            $options['debug'] = true;
        }

        $script = new Script(
            $name,
            sprintf(' {%% apply spaceless %%} {%% macro evaluate(%1$s) %%} %2$s {%% endmacro %%} {%% set var = _self.evaluate(%1$s) %%} {{ var }} {%% endapply %%} ', implode(', ', array_keys($context))$this->script),
            

        $request = new Request();
        $request->server->set('REQUEST_URI', '/foo/bar');
        $request->attributes->set('sw-original-request-uri', 'https://example.com/foo/bar');
        $stack = new RequestStack();
        $stack->push($request);

        $factory = new RequestFacadeFactory($stack);

        static::assertSame('request', $factory->getName());

        $script = new Script('foo', 'bar', new \DateTimeImmutable());

        $facade = $factory->factory($this->createMock(Hook::class)$script);

        static::assertSame('https://example.com/foo/bar', $facade->uri());
    }
}

    public function testFacade(array $criteria, string $method, IdsCollection $ids, callable $expectation): void
    {
        $this->ids = $ids;
        $this->createProducts();

        $facade = $this->factory->factory(
            new SalesChannelTestHook('test', $this->context),
            new Script('test', '', new \DateTimeImmutable())
        );

        $result = $facade->$method('product', $criteria); /* @phpstan-ignore-line */

        $expectation($result);
    }

    /** * @return array<string, array<int, mixed>> */
    public static function testCases(): array
    {
$dates = [...[$script['lastModified']], ...array_column($includes, 'lastModified')];

            /** @var \DateTimeInterface $lastModified */
            $lastModified = new \DateTimeImmutable(max($dates));

            /** @var string $cachePrefix */
            $cachePrefix = $script['appName'] ? md5($script['appName'] . $script['appVersion']) : EnvironmentHelper::getVariable('INSTANCE_ID', '');

            $includes = array_map(function Darray $script) use ($appId) {
                $script['app_id'] = $appId;

                return new Script(
                    $script['name'],
                    $script['script'],
                    new \DateTimeImmutable($script['lastModified']),
                    $this->getAppInfo($script)
                );
            }$includes);

            $options = [];
            if (!$this->debug) {
                $options['cache'] = new FilesystemCache($this->cacheDir . '/' . $cachePrefix);
            } else {
                
/** * @internal */
class ScriptTwigLoaderTest extends TestCase
{
    private Script $script;

    private ScriptTwigLoader $scriptLoader;

    protected function setUp(): void
    {
        $this->script = new Script(
            'simple-function-case.twig',
            file_get_contents(__DIR__ . '/_fixtures/simple-function-case/Resources/scripts/simple-function-case/simple-function-case.twig'),
            new \DateTimeImmutable()
        );

        $this->scriptLoader = new ScriptTwigLoader($this->script);
    }

    public function testGetSourceContext(): void
    {
        $source = $this->scriptLoader->getSourceContext($this->script->getName());

        

    public function testFacade(array $payload, string $method, IdsCollection $ids, callable $expectation): void
    {
        $this->ids = $ids;
        $this->createProducts();

        $facade = $this->factory->factory(
            new TestHook('test', $this->context),
            new Script('test', '', new \DateTimeImmutable())
        );

        $facade->$method('product', $payload); /* @phpstan-ignore-line */

        $expectation($this->context, $this->getContainer());
    }

    /** * @return array<string, array<int, mixed>> */
    public static function testCases(): array
    {
$ids->get('p3.1') => new ProductProxy($p3$salesChannelContext$stubs),
        ];

        $salesChannelContext->considerInheritance();
        $hook = new ProductPricingHookExtension($proxies$salesChannelContext$ids);

        // allows easy debugging         $traces = new ScriptTraces();

        $loader = $this->createMock(ScriptLoader::class);
        $loader->method('get')->willReturn([
            new Script('foo', (string) \file_get_contents(__DIR__ . '/_fixtures/pricing-cases/product-pricing.twig')new \DateTimeImmutable()),
        ]);

        $executor = new ScriptExecutor($loadernew NullLogger()$traces$this->getContainer()$this->getContainer()->get('twig.extension.trans'), 'v6.5.0.0');

        $executor->execute($hook);

        static::assertNotEmpty($traces->getTraces());
        static::assertArrayHasKey('product-pricing', $traces->getTraces());
        static::assertEquals(
            [
                'original' => 100.0,
                

    public function testWithoutApp(array $criteria, string $method, IdsCollection $ids, callable $expectation): void
    {
        $this->ids = $ids;
        $this->createProducts();

        $facade = $this->factory->factory(
            new TestHook('test', Context::createDefaultContext()),
            new Script('test', '', new \DateTimeImmutable())
        );

        $result = $facade->$method('product', $criteria); /* @phpstan-ignore-line */

        $expectation($result);
    }

    /** * @return array<string, array<int, mixed>> */
    public static function withoutAppTestCases(): array
    {
/** * @dataProvider getWithoutAppCases */
    public function testGetForScriptWithoutApp(Hook $hook, ?string $salesChannelId, string $result): void
    {
        $this->systemConfigService->set('test.value', 'generic');
        $this->systemConfigService->set('test.value', 'specific', TestDefaults::SALES_CHANNEL);

        $facade = $this->factory->factory(
            $hook,
            new Script('test', '', new \DateTimeImmutable())
        );

        static::assertEquals($result$facade->get('test.value', $salesChannelId));
    }

    /** * @return array<string, array<int, mixed>> */
    public static function getWithoutAppCases(): array
    {
        $salesChannelContext = Generator::createSalesChannelContext();
        
use IntegrationTestBehaviour;

    private IdsCollection $ids;

    private Script $script;

    protected function setUp(): void
    {
        parent::setUp();

        $this->init();
        $this->script = new Script('test', '', new \DateTimeImmutable());
    }

    /** * @dataProvider addProductProvider */
    public function testAddProduct(string $input, ?string $expected): void
    {
        $context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL, []);

        $hook = new CartHook($this->createCart()$context);

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