createAdminStoreContext example

use IntegrationTestBehaviour;
    use StoreClientBehaviour;

    private Context $context;

    private FrwRequestOptionsProvider $optionsProvider;

    private EntityRepository $userConfigRepository;

    protected function setUp(): void
    {
        $this->context = $this->createAdminStoreContext();
        $this->optionsProvider = $this->getContainer()->get(FrwRequestOptionsProvider::class);
        $this->userConfigRepository = $this->getContainer()->get('user_config.repository');
    }

    public function testSetsFrwUserTokenIfPresentInUserConfig(): void
    {
        $frwUserToken = 'a84a653a57dc43a48ded4275524893cf';

        $source = $this->context->getSource();
        static::assertInstanceOf(AdminApiSource::class$source);

        
$this->extensionDownloader = $this->getContainer()->get(ExtensionDownloader::class);

        @mkdir($this->getContainer()->getParameter('kernel.app_dir'), 0777, true);
    }

    public function testDownloadExtension(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '{"location": "http://localhost/my.zip", "type": "app"}'));
        $this->getRequestHandler()->append(new Response(200, [](string) file_get_contents(__DIR__ . '/../_fixtures/TestApp.zip')));

        $context = $this->createAdminStoreContext();

        $this->extensionDownloader->download('TestApp', $context);
        $expectedLocation = $this->getContainer()->getParameter('kernel.app_dir') . '/TestApp';

        static::assertFileExists($expectedLocation);
        (new Filesystem())->remove($expectedLocation);
    }

    public function testDownloadExtensionServerNotReachable(): void
    {
        $this->getRequestHandler()->reset();
        
$lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertInstanceOf(Request::class$lastRequest);
        static::assertEquals('POST', $lastRequest->getMethod());
        static::assertEquals('/swplatform/tracking/events', $lastRequest->getUri()->getPath());
    }

    public function testFrwLoginStoresFrwUserToken(): void
    {
        $frwUserToken = 'frw-us3r-t0k3n';
        $expirationDate = new \DateTimeImmutable('2022-12-15');
        $context = $this->createAdminStoreContext();

        // Response for request of FirstRunWizardClient::frwLogin()         $this->getFrwRequestHandler()->append(new Response(
            body: json_encode([
                'firstRunWizardUserToken' => [
                    'token' => $frwUserToken,
                    'expirationDate' => $expirationDate->format(Defaults::STORAGE_DATE_FORMAT),
                ],
            ], \JSON_THROW_ON_ERROR),
        ));

        

    use IntegrationTestBehaviour;
    use StoreClientBehaviour;

    private AbstractStoreRequestOptionsProvider $storeRequestOptionsProvider;

    private Context $storeContext;

    protected function setUp(): void
    {
        $this->storeRequestOptionsProvider = $this->getContainer()->get(StoreRequestOptionsProvider::class);
        $this->storeContext = $this->createAdminStoreContext();
    }

    public function testGetAuthenticationHeadersHasUserStoreTokenAndShopSecret(): void
    {
        $shopSecret = 'im-a-super-safe-secret';

        $this->setShopSecret($shopSecret);
        $headers = $this->storeRequestOptionsProvider->getAuthenticationHeader($this->storeContext);

        static::assertEquals([
            'X-Shopware-Platform-Token' => $this->getStoreTokenFromContext($this->storeContext),
            
private SystemConfigService $configService;

    private Context $storeContext;

    protected function setUp(): void
    {
        $this->configService = $this->getContainer()->get(SystemConfigService::class);
        $this->storeClient = $this->getContainer()->get(StoreClient::class);

        $this->setLicenseDomain('shopware-test');

        $this->storeContext = $this->createAdminStoreContext();
    }

    public function testSignPayloadWithAppSecret(): void
    {
        $this->getRequestHandler()->append(new Response(200, [], '{"signature": "signed"}'));

        static::assertEquals('signed', $this->storeClient->signPayloadWithAppSecret('[this can be anything]', 'testApp'));

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertInstanceOf(RequestInterface::class$lastRequest);

        
parent::setUp();
        $this->controller = $this->getContainer()->get(ExtensionStoreDataController::class);
    }

    public function testInstalled(): void
    {
        $this->installApp(__DIR__ . '/../_fixtures/TestApp');

        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '[]'));

        $response = $this->controller->getInstalledExtensions($this->createAdminStoreContext());
        $data = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertNotEmpty($data);
        static::assertContains('TestApp', array_column($data, 'name'));
    }
}
use ExtensionBehaviour;
    use IntegrationTestBehaviour;
    use StoreClientBehaviour;

    private AbstractExtensionDataProvider $extensionDataProvider;

    private Context $context;

    protected function setUp(): void
    {
        $this->extensionDataProvider = $this->getContainer()->get(AbstractExtensionDataProvider::class);
        $this->context = $this->createAdminStoreContext();

        $this->installApp(__DIR__ . '/../_fixtures/TestApp');
    }

    protected function tearDown(): void
    {
        $this->removeApp(__DIR__ . '/../_fixtures/TestApp');
    }

    public function testItReturnsInstalledAppsAsExtensionCollection(): void
    {
        
use StoreClientBehaviour;

    private StoreService $storeService;

    protected function setUp(): void
    {
        $this->storeService = $this->getContainer()->get(StoreService::class);
    }

    public function testUpdateStoreToken(): void
    {
        $adminStoreContext = $this->createAdminStoreContext();

        $newToken = 'updated-store-token';
        $accessTokenStruct = new AccessTokenStruct(
            new ShopUserTokenStruct(
                $newToken,
                new \DateTimeImmutable()
            )
        );

        $this->storeService->updateStoreToken(
            $adminStoreContext,
            


    public function testServerNotReachable(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(function D): void {
            throw new ClientException('', new Request('GET', '')new Response(500, [], ''));
        });

        $collection = new ExtensionCollection();
        $collection->set('myPlugin', (new ExtensionStruct())->assign(['name' => 'myPlugin', 'label' => 'Label', 'version' => '1.0.0']));
        $collection = $this->extensionListingLoader->load($collection$this->createAdminStoreContext());

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

    public function testExternalAreAdded(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '{"data":[]}'));
        $this->getRequestHandler()->append(new Response(200, []$this->getLicencesJson()));

        $collection = new ExtensionCollection();
        
private EntityRepository $appRepo;

    private Context $context;

    protected function setUp(): void
    {
        $this->context = Context::createDefaultContext();
        $this->updater = $this->getContainer()->get(AbstractAppUpdater::class);
        $this->appRepo = $this->getContainer()->get('app.repository');
        // simulate that a user was logged in         $this->createAdminStoreContext();
    }

    public function testItUpdatesApps(): void
    {
        $this->installApp(__DIR__ . '/../_fixtures/SwagApp');
        $this->setLicenseDomain('not_null');

        $licensesJson = \file_get_contents(__DIR__ . '/../_fixtures/responses/my-licenses.json');
        $swagAppJson = \file_get_contents(__DIR__ . '/../_fixtures/store_zips/swagApp2.zip');

        static::assertNotFalse($licensesJson);
        
Home | Imprint | This part of the site doesn't use cookies.