getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); $this->assertArrayHasKey('cart', $response); $this->assertArrayHasKey('selected_payment_method', $response['cart']); $this->assertArrayHasKey('code', $response['cart']['selected_payment_method']); $this->assertEquals('checkmo', $response['cart']['selected_payment_method']['code']); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoConfigFixture default_store payment/banktransfer/active 1 * @magentoConfigFixture default_store payment/cashondelivery/active 1 * @magentoConfigFixture default_store payment/checkmo/active 1 * @magentoConfigFixture default_store payment/purchaseorder/active 1 * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php */ public function testGetSelectedPaymentMethodBeforeSet() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); $this->assertArrayHasKey('cart', $response); $this->assertArrayHasKey('selected_payment_method', $response['cart']); $this->assertArrayHasKey('code', $response['cart']['selected_payment_method']); $this->assertEquals('', $response['cart']['selected_payment_method']['code']); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testGetSelectedPaymentMethodFromNonExistentCart() { $this->expectException(\Exception::class); $maskedQuoteId = 'non_existent_masked_id'; $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( 'Could not find a cart with ID "non_existent_masked_id"' ); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** * _security * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoConfigFixture default_store payment/banktransfer/active 1 * @magentoConfigFixture default_store payment/cashondelivery/active 1 * @magentoConfigFixture default_store payment/checkmo/active 1 * @magentoConfigFixture default_store payment/purchaseorder/active 1 * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php */ public function testGetSelectedPaymentMethodFromGuestCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"$maskedQuoteId\"" ); $this->graphQlQuery($query, [], '', $this->getHeaderMap()); } /** * _security * @magentoApiDataFixture Magento/Customer/_files/three_customers.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php */ public function testGetSelectedPaymentMethodFromAnotherCustomerCart() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId); $this->expectExceptionMessage( "The current user cannot perform operations on cart \"{$maskedQuoteId}\"" ); $this->graphQlQuery($query, [], '', $this->getHeaderMap('customer3@search.example.com')); } protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); } /** * @param string $maskedQuoteId * @return string */ private function getQuery(string $maskedQuoteId): string { return <<customerTokenService->createCustomerAccessToken($username, $password); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; return $headerMap; } }