|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\Quote\Customer; |
| 9 | + |
| 10 | +use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; |
| 11 | +use Magento\Integration\Api\CustomerTokenServiceInterface; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test for getting is_virtual from cart |
| 17 | + */ |
| 18 | +class GetCartIsVirtualTest extends GraphQlAbstract |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var GetMaskedQuoteIdByReservedOrderId |
| 22 | + */ |
| 23 | + private $getMaskedQuoteIdByReservedOrderId; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var CustomerTokenServiceInterface |
| 27 | + */ |
| 28 | + private $customerTokenService; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $objectManager = Bootstrap::getObjectManager(); |
| 33 | + $this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); |
| 34 | + $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 39 | + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php |
| 40 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php |
| 41 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php |
| 42 | + */ |
| 43 | + public function testGetCartIsNotVirtual() |
| 44 | + { |
| 45 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 46 | + |
| 47 | + $query = $this->getQuery($maskedQuoteId); |
| 48 | + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); |
| 49 | + |
| 50 | + $this->assertArrayHasKey('cart', $response); |
| 51 | + $this->assertArrayHasKey('is_virtual', $response['cart']); |
| 52 | + $this->assertFalse($response['cart']['is_virtual']); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 57 | + * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php |
| 58 | + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php |
| 59 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php |
| 60 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php |
| 61 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php |
| 62 | + */ |
| 63 | + public function testGetMixedCartIsNotVirtual() |
| 64 | + { |
| 65 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 66 | + |
| 67 | + $query = $this->getQuery($maskedQuoteId); |
| 68 | + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); |
| 69 | + |
| 70 | + $this->assertArrayHasKey('cart', $response); |
| 71 | + $this->assertArrayHasKey('is_virtual', $response['cart']); |
| 72 | + $this->assertFalse($response['cart']['is_virtual']); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @magentoApiDataFixture Magento/Customer/_files/customer.php |
| 77 | + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php |
| 78 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php |
| 79 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php |
| 80 | + */ |
| 81 | + public function testGetCartIsVirtual() |
| 82 | + { |
| 83 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 84 | + |
| 85 | + $query = $this->getQuery($maskedQuoteId); |
| 86 | + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); |
| 87 | + |
| 88 | + $this->assertArrayHasKey('cart', $response); |
| 89 | + $this->assertArrayHasKey('is_virtual', $response['cart']); |
| 90 | + $this->assertTrue($response['cart']['is_virtual']); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @param string $maskedQuoteId |
| 95 | + * @return string |
| 96 | + */ |
| 97 | + private function getQuery(string $maskedQuoteId): string |
| 98 | + { |
| 99 | + return <<<QUERY |
| 100 | +{ |
| 101 | + cart(cart_id:"$maskedQuoteId") { |
| 102 | + is_virtual |
| 103 | + } |
| 104 | +} |
| 105 | +QUERY; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * @param string $username |
| 110 | + * @param string $password |
| 111 | + * @return array |
| 112 | + */ |
| 113 | + private function getHeaderMap( string $username = '[email protected]', string $password = 'password'): array |
| 114 | + { |
| 115 | + $customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); |
| 116 | + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; |
| 117 | + return $headerMap; |
| 118 | + } |
| 119 | +} |
0 commit comments