createSalesChannelBrowser example


class SalesChannelAuthenticationListenerTest extends TestCase
{
    use IntegrationTestBehaviour;
    use SalesChannelApiTestBehaviour;

    private const MAINTENANCE_ALLOWED_IPS = ['192.168.0.2', '192.168.0.1', '192.168.0.3'];

    public function testInactiveSalesChannel(): void
    {
        $browser = $this->createSalesChannelBrowser(salesChannelOverrides: ['active' => false]);
        $browser->request(Request::METHOD_GET, '/store-api/test/sales-channel-authentication-listener/default');

        $this->assertExceptionResponse(
            $browser,
            Response::HTTP_PRECONDITION_FAILED,
            ApiException::salesChannelNotFound()->getErrorCode()
        );
    }

    public function testActiveSalesChannel(): void
    {
        
use Shopware\Core\Framework\Test\TestCaseBase\SalesChannelFunctionalTestBehaviour;

/** * @internal */
class XmlHttpRequestableInterfaceTest extends TestCase
{
    use SalesChannelFunctionalTestBehaviour;

    public function testPageLoads(): void
    {
        $client = $this->createSalesChannelBrowser(null, true);
        $client->request('GET', 'http://localhost/');

        static::assertEquals(200, $client->getResponse()->getStatusCode());
    }

    public function testAccessDeniedForXmlHttpRequest(): void
    {
        $client = $this->createSalesChannelBrowser(null, true);

        $client->xmlHttpRequest('GET', 'http://localhost/');

        
$response = $this->getSalesChannelBrowser()->getResponse();
        $content = json_decode($response->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR);

        static::assertSame(Response::HTTP_OK, $response->getStatusCode()print_r($content, true));
    }

    public function testSwitchToValidLanguageWithoutDomain(): void
    {
        $id = Uuid::randomHex();

        $browser = $this->createSalesChannelBrowser(null, false, [
            'languageId' => $id,
            'languages' => [
                ['id' => $id],
                ['id' => Defaults::LANGUAGE_SYSTEM],
            ],
            'domains' => [
                [
                    'language' => [
                        'id' => $id,
                        'name' => 'Testlanguage',
                        'localeId' => $this->getLocaleIdOfSystemLanguage(),
                        
private Context $context;

    protected function setUp(): void
    {
        $this->repository = $this->getContainer()->get('product_export.repository');
        $this->context = Context::createDefaultContext();
    }

    public function testInvalidData(): void
    {
        $client = $this->createSalesChannelBrowser(null, true);
        $client->request('GET', getenv('APP_URL') . '/store-api/product-export/foo/bar');

        static::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
    }

    public function testUtf8CsvExport(): void
    {
        $salesChannelId = Uuid::randomHex();
        $salesChannelDomainId = Uuid::randomHex();

        $client = $this->createSalesChannelBrowser(null, false, [
            
return $customerId;
    }

    abstract protected static function getKernel(): KernelInterface;

    protected function getSalesChannelBrowser(): KernelBrowser
    {
        if ($this->salesChannelApiBrowser) {
            return $this->salesChannelApiBrowser;
        }

        return $this->salesChannelApiBrowser = $this->createSalesChannelBrowser();
    }

    /** * @param array<mixed> $salesChannelOverrides */
    protected function createSalesChannelBrowser(
        ?KernelInterface $kernel = null,
        bool $enableReboot = false,
        array $salesChannelOverrides = []
    ): KernelBrowser {
        if (!$kernel) {
            
Home | Imprint | This part of the site doesn't use cookies.