markTestIncomplete('https://github.com/magento/graphql-ce/issues/434'); $objectManager = Bootstrap::getObjectManager(); $this->quoteResource = $objectManager->create(QuoteResource::class); $this->quote = $objectManager->create(Quote::class); $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ public function testGetOwnCartForRegisteredCustomer() { $reservedOrderId = 'test_order_item_with_items'; $this->quoteResource->load( $this->quote, $reservedOrderId, 'reserved_order_id' ); $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); $query = $this->prepareGetCartQuery($maskedQuoteId); $response = $this->sendRequestWithToken($query); self::assertArrayHasKey('cart', $response); self::assertNotEmpty($response['cart']['items']); self::assertNotEmpty($response['cart']['shipping_addresses']); } /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ public function testGetCartFromAnotherCustomer() { $reservedOrderId = 'test_order_item_with_items'; $this->quoteResource->load( $this->quote, $reservedOrderId, 'reserved_order_id' ); $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); $query = $this->prepareGetCartQuery($maskedQuoteId); self::expectExceptionMessage("The current user cannot perform operations on cart \"$maskedQuoteId\""); $this->graphQlQuery($query); } /** * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php */ public function testGetCartForGuest() { $reservedOrderId = 'test_order_1'; $this->quoteResource->load( $this->quote, $reservedOrderId, 'reserved_order_id' ); $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); $query = $this->prepareGetCartQuery($maskedQuoteId); $response = $this->graphQlQuery($query); self::assertArrayHasKey('cart', $response); } public function testGetNonExistentCart() { $maskedQuoteId = 'non_existent_masked_id'; $query = $this->prepareGetCartQuery($maskedQuoteId); self::expectExceptionMessage("Could not find a cart with ID \"$maskedQuoteId\""); $this->graphQlQuery($query); } /** * Generates query for setting the specified shipping method on cart * * @param string $maskedQuoteId * @return string */ private function prepareGetCartQuery( string $maskedQuoteId ) : string { return <<customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; return $this->graphQlQuery($query, [], '', $headerMap); } }