loadAppsFromDir example

/** * @internal */
class StorefrontPluginRegistryTest extends TestCase
{
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testConfigIsAddedIfItsATheme(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/fixtures/Apps/theme');

        $registry = $this->getContainer()
            ->get(StorefrontPluginRegistry::class);

        static::assertInstanceOf(
            StorefrontPluginConfiguration::class,
            $registry->getConfigurations()->getByTechnicalName('SwagTheme')
        );
    }

    public function testConfigIsNotAddedIfAppIsNotActive(): void
    {
static::assertFalse($schema->getTable('product')->hasColumn('ce_blog_comment_products_reverse_id'));
        static::assertFalse($schema->getTable('product')->hasColumn('custom_entity_to_remove_products_reverse_id'));

        static::assertFalse($schema->hasTable('custom_entity_blog_product'));
        static::assertFalse($schema->hasTable('custom_entity_to_remove'));

        self::cleanUp($this->getContainer());
    }

    public function testAllowDisableIsTrueIfNoRestrictDeleteIsUsed(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/without-restrict-delete');

        $container = KernelLifecycleManager::bootKernel()->getContainer();

        $this->testAllowDisable(true);

        self::cleanUp($container);
    }

    public function testDoesNotRegisterCustomEntitiesIfAppIsInactive(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/without-restrict-delete', false);

        
/** * @internal */
class ScriptLoaderTest extends TestCase
{
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testGetScripts(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures');

        $loader = $this->getContainer()->get(ScriptLoader::class);

        static::assertCount(
            1,
            $loader->get('include-case')
        );
        static::assertCount(
            2,
            $loader->get('multi-script-case')
        );
        
$this->executor = $this->getContainer()->get(ScriptExecutor::class);
    }

    /** * @param array<string> $hooks * @param array<string, mixed> $expected * * @dataProvider executeProvider */
    public function testExecute(array $hooks, array $expected): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures');

        $object = new ArrayStruct();

        $context = Context::createDefaultContext();
        foreach ($hooks as $hook) {
            $this->executor->execute(new TestHook($hook$context['object' => $object]));
        }

        static::assertNotEmpty($expected);

        foreach ($expected as $key => $value) {
            
class AppActionLoaderTest extends TestCase
{
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testCreateAppActionReturnCorrectData(): void
    {
        $actionLoader = $this->getContainer()->get(AppActionLoader::class);

        /** @var EntityRepository $actionRepo */
        $actionRepo = $this->getContainer()->get('app_action_button.repository');
        $this->loadAppsFromDir(__DIR__ . '/../Manifest/_fixtures/test');

        $criteria = (new Criteria())
            ->setLimit(1)
            ->addAssociation('app')
            ->addAssociation('app.integration');

        $actionCollection = $actionRepo->search($criteria, Context::createDefaultContext());
        /** @var ActionButtonEntity $action */
        $action = $actionCollection->first();

        $shopIdProvider = $this->getContainer()->get(ShopIdProvider::class);

        
use IntegrationTestBehaviour;

    private EntityRepository $appRepository;

    protected function setUp(): void
    {
        $this->appRepository = $this->getContainer()->get('app.repository');
    }

    public function testDeactivateApp(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/withoutPermissions');
        $appName = 'withoutPermissions';
        $commandTester = new CommandTester($this->getContainer()->get(DeactivateAppCommand::class));

        $commandTester->execute(['name' => $appName]);

        static::assertEquals(0, $commandTester->getStatusCode());

        static::assertStringContainsString('[OK] App deactivated successfully.', $commandTester->getDisplay());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', $appName));

        
->price(300);

        $this->getContainer()->get('product.repository')->create([
            $product1->build(),
            $product2->build(),
            $product3->build(),
        ]$this->context->getContext());
    }

    private function installApp(string $appDir): string
    {
        $this->loadAppsFromDir($appDir);

        $appId = $this->getContainer()->get('app.repository')->searchIds(new Criteria(), Context::createDefaultContext())->firstId();
        static::assertIsString($appId);

        return $appId;
    }

    private function getExistingTaxId(): string
    {
        /** @var EntityRepository<TaxCollection> $taxRepository */
        $taxRepository = $this->getContainer()->get('tax.repository');

        
/** * @internal */
class ScriptApiRouteTest extends TestCase
{
    use AdminApiTestBehaviour;
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testApiEndpoint(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures');

        $this->kernelBrowser = null;
        $browser = $this->getBrowser();
        $browser->request('POST', '/api/script/simple-script');

        static::assertNotFalse($browser->getResponse()->getContent());
        $response = \json_decode($browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(Response::HTTP_OK, $browser->getResponse()->getStatusCode()print_r($response, true));

        $traces = $this->getScriptTraces();
        static::assertArrayHasKey('api-simple-script', $traces);
        
$result = $this->appCookieProvider->getCookieGroups();

        static::assertEquals(['test']$result);
    }

    public function testItAddsSingleCookieFromApp(): void
    {
        $this->baseProvider->expects(static::once())
            ->method('getCookieGroups')
            ->willReturn([]);

        $this->loadAppsFromDir(__DIR__ . '/_fixtures/singleCookie');

        $result = $this->appCookieProvider->getCookieGroups();
        static::assertCount(1, $result);
        static::assertEquals([
            'snippet_name' => 'Swoogle Analytics',
            'cookie' => 'swag.analytics',
            'value' => '',
            'expiration' => '30',
        ]$result[0]);
    }

    
$response = $kernel->handle($request);
        static::assertEquals('GET /: fresh', $response->headers->get('x-symfony-cache'));

        $request->cookies->set(CacheResponseSubscriber::CONTEXT_CACHE_COOKIE, 'b');

        $response = $kernel->handle($request);
        static::assertEquals('GET /: miss, store', $response->headers->get('x-symfony-cache'));
    }

    public function testCacheForAppScriptEndpointIsEnabledByDefault(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/http-cache-cases');

        $kernel = $this->getCacheKernel();

        $route = '/storefront/script/cache-default';
        $request = $this->createRequest(EnvironmentHelper::getVariable('APP_URL') . $route);

        $response = $kernel->handle($request);
        static::assertEquals(sprintf('GET %s: miss, store', $route)$response->headers->get('x-symfony-cache'));
        static::assertFalse($response->headers->has(CacheStore::TAG_HEADER));

        $response = $kernel->handle($request);
        
/** * @internal */
class ScriptControllerTest extends TestCase
{
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;
    use StorefrontControllerTestBehaviour;

    public function testGetApiEndpoint(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/fixtures/Apps');

        $response = $this->request('GET', '/storefront/script/json-response', []);
        static::assertNotFalse($response->getContent());

        $body = \json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(Response::HTTP_OK, $response->getStatusCode()print_r($body, true));

        $traces = $this->getScriptTraces();
        static::assertArrayHasKey('storefront-json-response', $traces);
        static::assertCount(1, $traces['storefront-json-response']);
        static::assertSame('some debug information', $traces['storefront-json-response'][0]['output'][0]);

        
static::assertEquals(
            MoveShopPermanentlyStrategy::STRATEGY_NAME,
            $moveShopPermanentlyResolver->getName()
        );
        static::assertIsString($moveShopPermanentlyResolver->getDescription());
    }

    public function testItReRegistersInstalledApps(): void
    {
        $appDir = __DIR__ . '/../Manifest/_fixtures/test';
        $this->loadAppsFromDir($appDir);

        $app = $this->getInstalledApp($this->context);

        $shopId = $this->changeAppUrl();

        $registrationsService = $this->createMock(AppRegistrationService::class);
        $registrationsService->expects(static::once())
            ->method('registerApp')
            ->with(
                static::callback(static fn (Manifest $manifest): bool => $manifest->getPath() === $appDir),
                $app->getId(),
                
static::fail('ThemeCompiler->compile() should be executable without a database connection. But following Excpetion was thrown: ' . $throwable->getMessage());
        } finally {
            $this->resetEnvVars();
            KernelLifecycleManager::bootKernel(true);
            $this->startTransactionBefore();
            rmdir($testFolder);
        }
    }

    public function testOutputsPluginCss(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/fixtures/Apps/noThemeCustomCss');
        $themeCompilerReflection = new \ReflectionClass(ThemeCompiler::class);
        $compileStyles = $themeCompilerReflection->getMethod('compileStyles');
        $compileStyles->setAccessible(true);

        $testScss = <<<PHP_EOL .test-selector-plugin { background: \$simple-plugin-backgroundcolor; color: \$simple-plugin-fontcolor; border: \$simple-plugin-bordercolor; } .test-selector-app { background: \$no-theme-custom-css-backgroundcolor; color: \$no-theme-custom-css-fontcolor; border: \$no-theme-custom-css-bordercolor; }
/** * @internal */
class AppCmsControllerTest extends TestCase
{
    use AdminApiTestBehaviour;
    use AppSystemTestBehaviour;
    use GuzzleTestClientBehaviour;

    public function testGetBlocks(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/../Manifest/_fixtures/test');
        $this->getBrowser()->request('GET', '/api/app-system/cms/blocks');

        $response = $this->getBrowser()->getResponse();
        static::assertNotFalse($response->getContent());
        static::assertEquals(200, $response->getStatusCode());

        $json = \file_get_contents(__DIR__ . '/_fixtures/expectedCmsBlocks.json');
        static::assertNotFalse($json);
        static::assertJson($json);

        $expected = \json_decode($json, true, 512, \JSON_THROW_ON_ERROR);
        

        $this->snippetFileLoader = new SnippetFileLoader(
            new MockedKernel([]),
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get(AppSnippetFileLoader::class),
            $this->getContainer()->get(ActiveAppsLoader::class)
        );
    }

    public function testLoadSnippetFilesIntoCollectionWithoutSnippetFiles(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/Apps/AppWithoutSnippets');

        $collection = new SnippetFileCollection();

        $this->snippetFileLoader->loadSnippetFilesIntoCollection($collection);

        static::assertCount(0, $collection);
    }

    public function testLoadSnippetFilesIntoCollection(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/Apps/AppWithSnippets');

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