getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); $this->orderCollectionFactory = $objectManager->get(CollectionFactory::class); $this->orderRepository = $objectManager->get(OrderRepositoryInterface::class); $this->registry = Bootstrap::getObjectManager()->get(Registry::class); $this->guestCartRepository = $objectManager->get(GuestCartRepositoryInterface::class); } /** * @magentoConfigFixture default_store checkout/options/guest_checkout 0 */ public function testCreateEmptyCartIfGuestCheckoutIsDisabled() { $query = <<graphQlMutation($query); self::assertArrayHasKey('createEmptyCart', $response); self::assertNotEmpty($response['createEmptyCart']); $guestCart = $this->guestCartRepository->get($response['createEmptyCart']); self::assertNotNull($guestCart->getId()); self::assertNull($guestCart->getCustomer()->getId()); self::assertEquals('default', $guestCart->getStore()->getCode()); } /** * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testSetBillingAddressToGuestCustomerCart() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<graphQlMutation($query); } /** * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testSetGuestEmailOnCartWithGuestCheckoutDisabled() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $email = 'some@user.com'; $query = <<graphQlMutation($query); } /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testSetPaymentOnCartWithGuestCheckoutDisabled() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<graphQlMutation($query); self::assertArrayHasKey('setPaymentMethodOnCart', $response); self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); } /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testSetNewShippingAddressOnCartWithGuestCheckoutDisabled() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = <<graphQlMutation($query); } /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testSetShippingMethodOnCartWithGuestCheckoutDisabled() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $carrierCode = 'flatrate'; $methodCode = 'flatrate'; $query = <<graphQlMutation($query); } /** * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoConfigFixture default_store carriers/flatrate/active 1 * @magentoConfigFixture default_store carriers/tablerate/active 1 * @magentoConfigFixture default_store carriers/freeshipping/active 1 * @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/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php * @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_new_billing_address.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php * @magentoConfigFixture default_store checkout/options/guest_checkout 0 * */ public function testPlaceOrderWithGuestCheckoutDisabled() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.'); $reservedOrderId = 'test_quote'; $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); $query = $this->getQuery($maskedQuoteId); $this->graphQlMutation($query); } /** * @param string $maskedQuoteId * @return string */ private function getQuery(string $maskedQuoteId): string { return <<registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', true); $orderCollection = $this->orderCollectionFactory->create(); foreach ($orderCollection as $order) { $this->orderRepository->delete($order); } $this->registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', false); parent::tearDown(); } }