objectManager = Bootstrap::getObjectManager(); $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage(); } /** * Test graphql customer orders * * @throws LocalizedException */ #[ Config(Data::XML_PATH_PRICE_SCOPE, Data::PRICE_SCOPE_WEBSITE), DataFixture(WebsiteFixture::class, as: 'website2'), DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'), DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store2'), DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store3'), DataFixture(ProductFixture::class, ['website_ids' => [1, '$website2.id$' ]], as: 'product'), DataFixture( Customer::class, [ 'store_id' => '$store2.id$', 'website_id' => '$website2.id$', 'addresses' => [[]] ], as: 'customer' ), DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote1', scope: 'store2'), DataFixture(AddProductToCart::class, ['cart_id' => '$quote1.id$', 'product_id' => '$product.id$', 'qty' => 1]), DataFixture(SetBillingAddress::class, ['cart_id' => '$quote1.id$']), DataFixture(SetShippingAddress::class, ['cart_id' => '$quote1.id$']), DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote1.id$']), DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote1.id$']), DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote1.id$'], 'order1'), DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote2', scope: 'store3'), DataFixture(AddProductToCart::class, ['cart_id' => '$quote2.id$', 'product_id' => '$product.id$', 'qty' => 1]), DataFixture(SetBillingAddress::class, ['cart_id' => '$quote2.id$']), DataFixture(SetShippingAddress::class, ['cart_id' => '$quote2.id$']), DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote2.id$']), DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote2.id$']), DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote2.id$'], 'order2') ] public function testGetCustomerOrders() { $store2 = $this->fixtures->get('store2'); $store3 = $this->fixtures->get('store3'); $customer = $this->fixtures->get('customer'); $currentEmail = $customer->getEmail(); $currentPassword = 'password'; $generateToken = $this->generateCustomerToken($currentEmail, $currentPassword); $tokenResponse = $this->graphQlMutationWithResponseHeaders( $generateToken, [], '', ['Store' => $store2->getCode()] ); $customerToken = $tokenResponse['body']['generateCustomerToken']['token']; $query = $this->getCustomerOrdersQuery('STORE'); $response = $this->graphQlQuery( $query, [], '', $this->getCustomerHeaders($customerToken, $store2->getCode()) ); $this->assertEquals(2, count($response['customer']['orders']['items'])); $response = $this->graphQlQuery( $query, [], '', $this->getCustomerHeaders($customerToken, $store3->getCode()) ); $this->assertEquals(2, count($response['customer']['orders']['items'])); $query = $this->getCustomerOrdersQuery('WEBSITE'); $response = $this->graphQlQuery( $query, [], '', $this->getCustomerHeaders($customerToken, $store2->getCode()) ); $this->assertEquals(2, count($response['customer']['orders']['items'])); $query = $this->getCustomerOrdersQuery('GLOBAL'); $response = $this->graphQlQuery( $query, [], '', $this->getCustomerHeaders($customerToken, null) ); $this->assertEquals(2, count($response['customer']['orders']['items'])); $query = $this->getCustomerOrdersQuery(); $response = $this->graphQlQuery( $query, [], '', $this->getCustomerHeaders($customerToken, null) ); $this->assertEquals(0, count($response['customer']['orders']['items'])); } /** * Generate graphql query headers for customer orders * * @param string $token * @param string|null $storeCode * * @return array */ private function getCustomerHeaders(string $token, ?string $storeCode): array { return ['Authorization' => 'Bearer ' . $token, 'Store' => $storeCode ?? 'default']; } /** * Generate graphql query body for customer orders * * @param string|null $scope * * @return array|string */ private function getCustomerOrdersQuery(?string $scope = null): array|string { $query = <<