Project: shopware6
Filename: repositories/php/shopware6/src/Storefront/Test/Framework/Routing/StorefrontSubscriberTest.php


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

        $eventDispatcher = $this->getContainer()->get('event_dispatcher');

        $event = new StorefrontRenderEvent(
            'testView',
            [],
            new Request(),
            $this->salesChannelContext
        );

        $eventDispatcher->dispatch($event);

        static::assertArrayHasKey('appShopId', $event->getParameters());
    }

    public function testItDoesNotAddShopIdParamWhenAppIsInactive(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/../../Theme/fixtures/Apps/noThemeNoCss', false);

        
Project: shopware6
Filename: repositories/php/shopware6/src/Core/Framework/Test/Routing/ApiRequestContextResolverTest.php
/** * @dataProvider userRoleProvider * * @param array<string, bool> $expected * @param array<string, list<string>> $roles */
    public function testResolveAdminSourceByOAuthUserId(array $expected, array $roles, bool $isAdmin = false): void
    {
        $user = $this->createUser($roles$isAdmin);

        $request = new Request();
        $request->attributes->set(PlatformRequest::ATTRIBUTE_OAUTH_USER_ID, $user->getUserId());
        $request->attributes->set('_routeScope', ['api']);
        $this->resolver->resolve($request);

        static::assertTrue(
            $request->attributes->has(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT)
        );

        /** @var Context $context */
        $context = $request->attributes->get(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);

        
Project: shopware6
Filename: repositories/php/shopware6/tests/integration/php/Core/Framework/App/Lifecycle/Registration/StoreHandshakeTest.php
public function testThrowsIfSbpRespondsWithUnauthorized(): void
    {
        $storeClient = $this->createMock(StoreClient::class);
        $json = \json_encode(['code' => 'ShopwarePlatformException-1']);

        static::assertNotFalse($json);

        $storeClient->method('signPayloadWithAppSecret')
            ->willThrowException(new ClientException(
                '',
                new Request('POST', 'app_generate_signature'),
                new Response(401, []$json)
            ));

        $handshake = new StoreHandshake(
            'http://shop.url',
            'http://app.url',
            'TestApp',
            'my-shop-id',
            $storeClient,
            Kernel::SHOPWARE_FALLBACK_VERSION
        );

        
Project: shopware6
Filename: repositories/php/shopware6/src/WebInstaller/tests/Controller/FinishControllerTest.php

class FinishControllerTest extends TestCase
{
    public function testRendersTemplate(): void
    {
        $controller = new FinishController();
        $controller->setContainer($this->getContainer());

        $response = $controller->default(new Request(), '');

        static::assertSame('finish.html.twig', $response->getContent());
    }

    private function getContainer(): ContainerInterface
    {
        $container = new Container();

        $router = $this->createMock(Router::class);
        $router->method('generate')->willReturnArgument(0);

        
Project: shopware6
Filename: repositories/php/shopware6/src/Storefront/Test/Framework/Captcha/GoogleReCaptchaV3Test.php

        return [
            'with get method and inactive captcha' => ['GET', false, false],
            'with get method and active captcha' => ['GET', true, false],
            'with post method and inactive captcha' => ['POST', false, false],
            'with post method and active captcha' => ['POST', true, true],
        ];
    }

    private static function getRequest(array $data = []): Request
    {
        return new Request([]$data[][][][][]);
    }
}
Project: shopware6
Filename: repositories/php/shopware6/tests/unit/php/Core/Framework/Api/Controller/CustomSnippetFormatControllerTest.php
'address/title',
            'address/zipcode',
            'symbol/comma',
            'symbol/dash',
            'symbol/tilde',
            'custom-snippet/custom-snippet',
        ]$content['data']);
    }

    public function testRender(): void
    {
        $request = new Request();
        $request->request->set('data', [
            'customer' => [
                'first_name' => 'Vin',
                'last_name' => 'Le',
            ],
        ]);
        $request->request->set('format', [
            [
                'address/first_name',
                'address/last_name',
            ],
        ]);
Project: shopware6
Filename: repositories/php/shopware6/src/Core/Content/Test/Category/SalesChannel/CachedNavigationRouteTest.php
function DIdsCollection $ids, SalesChannelContext $context, ContainerInterface $container): void {
                $container->get('category.repository')->create([
                    ['id' => $ids->get('cat-1.2.4'), 'name' => 'cat 1.2.4', 'active' => true],
                ], Context::createDefaultContext());
            },
            3,
        ];
    }

    private static function request(int $depth): Request
    {
        $request = new Request();
        $request->query->set('depth', $depth);
        $request->query->set('buildTree', false);

        return $request;
    }

    private function initData(IdsCollection $ids): void
    {
        $context = $this->getContainer()
            ->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        
Project: shopware6
Filename: repositories/php/shopware6/src/WebInstaller/tests/Services/RecoveryManagerTest.php
$fs->mkdir($tmpDir);
        $fs->dumpFile($tmpDir . '/symfony.lock', json_encode([], \JSON_THROW_ON_ERROR));

        static::assertTrue($recoveryManager->isFlexProject($tmpDir));
    }

    public function testGetPHPBinary(): void
    {
        $recoveryManager = new RecoveryManager();

        $request = new Request();
        $request->setSession(new Session(new MockArraySessionStorage()));
        $request->getSession()->set('phpBinary', 'php');

        static::assertSame('php', $recoveryManager->getPHPBinary($request));
    }

    private function prepareShopware(Filesystem $fs, string $tmpDir, string $version = '6.4.10.0'): void
    {
        $fs->mkdir($tmpDir);
        $fs->mkdir($tmpDir . '/public');

        
Project: shopware6
Filename: repositories/php/shopware6/src/Storefront/Test/Page/Account/PaymentMethodPageTest.php
/** * @internal */
class PaymentMethodPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    public function testItlLoadsTheRequestedCustomersData(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

        /** @var AccountPaymentMethodPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(AccountPaymentMethodPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(AccountPaymentMethodPage::class$page);
        static::assertSame(StorefrontPageTestConstants::PAYMENT_METHOD_COUNT, $page->getPaymentMethods()->count());
        self::assertPageEvent(AccountPaymentMethodPageLoadedEvent::class$event$context$request$page);
    }
Project: shopware6
Filename: repositories/php/shopware6/src/Storefront/Test/Page/Product/QuickView/MinimalQuickViewPageTest.php
/** * @internal */
class MinimalQuickViewPageTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    public function testItRequiresProductParam(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContext();

        $this->expectParamMissingException('productId');
        $this->getPageLoader()->load($request$context);
    }

    public function testItRequiresAValidProductParam(): void
    {
        $request = new Request([][]['productId' => '99999911ffff4fffafffffff19830531']);
        $context = $this->createSalesChannelContext();

        
Project: shopware6
Filename: repositories/php/shopware6/tests/unit/php/Core/Content/Product/SalesChannel/Suggest/ProductSuggestRouteTest.php

        static::expectException(DecorationPatternException::class);

        $this->getProductSuggestRoute()->getDecorated();
    }

    public function testLoadThrowsExceptionForMissingSearchParameter(): void
    {
        static::expectException(RoutingException::class);

        $this->getProductSuggestRoute()->load(
            new Request(),
            $this->createMock(SalesChannelContext::class),
            new Criteria()
        );
    }

    public function testLoadSuccessfully(): void
    {
        $request = new Request();
        $request->query->set('search', 'test');

        $criteria = new Criteria();

        
Project: shopware6
Filename: repositories/php/shopware6/src/Core/Content/Test/Product/SalesChannel/ProductListingFilterOutOfStockTest.php
$this->insertOptions();

        $this->insertProducts();
    }

    public function testListingWithFilterDisabled(): void
    {
        // disable hideCloseoutProductsWhenOutOfStock filter         $this->getContainer()->get(SystemConfigService::class)
            ->set('core.listing.hideCloseoutProductsWhenOutOfStock', false);

        $request = new Request();

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $listing = $this->getContainer()
            ->get(ProductListingRoute::class)
            ->load($this->categoryId, $request$contextnew Criteria())
            ->getResult();

        static::assertSame(5, $listing->getTotal());
        static::assertFalse($listing->has($this->testData->getId('product1')));