Skip to content

Commit 625dced

Browse files
committed
LYNX-259: New copywrite header for new files and parametrized fixtures for new tests
1 parent fbc20cf commit 625dced

File tree

4 files changed

+71
-42
lines changed

4 files changed

+71
-42
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CreateGuestCart.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
516
*/
617
declare(strict_types=1);
718

@@ -53,7 +64,7 @@ public function __construct(
5364
}
5465

5566
/**
56-
* @inheritdoc
67+
* Creates a guest cart and returns the cart object
5768
*/
5869
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5970
{
@@ -65,7 +76,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6576
$this->validateMaskedId($predefinedMaskedQuoteId);
6677
}
6778

68-
if (0 === $customerId || null === $customerId) {
79+
if ($customerId === 0 || $customerId === null) {
6980
$maskedQuoteId = $this->createEmptyCartForGuest->execute($predefinedMaskedQuoteId);
7081
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedQuoteId);
7182
$cart = $this->cartRepository->get($cartId);

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type Query {
88
}
99

1010
type Mutation {
11-
createEmptyCart(input: createEmptyCartInput): String @deprecated(reason: "Use `Mutation.createGuestCart` for guest and `Query.cart` or `Query.customerCart` for logged in customer")
1211
createGuestCart(input: CreateGuestCartInput): CreateGuestCartOutput @doc(description: "Create a new shopping cart") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CreateGuestCart")
12+
createEmptyCart(input: createEmptyCartInput): String @deprecated(reason: "Use `Mutation.createGuestCart` for guest and `Query.cart` or `Query.customerCart` for logged in customer") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CreateEmptyCart") @doc(description:"Create an empty shopping cart for a guest or logged in user")
1313
addSimpleProductsToCart(input: AddSimpleProductsToCartInput @doc(description: "An input object that defines which simple products to add to the cart.")): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") @doc(description:"Add one or more simple products to the specified cart. We recommend using `addProductsToCart` instead.")
1414
addVirtualProductsToCart(input: AddVirtualProductsToCartInput @doc(description: "An input object that defines which virtual products to add to the cart.")): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") @doc(description:"Add one or more virtual products to the specified cart. We recommend using `addProductsToCart` instead.")
1515
applyCouponToCart(input: ApplyCouponToCartInput @doc(description: "An input object that defines the coupon code to apply to the cart.")): ApplyCouponToCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ApplyCouponToCart") @doc(description:"Apply a pre-defined coupon code to the specified cart.")
@@ -34,10 +34,6 @@ input CreateGuestCartInput {
3434
cart_uid: ID @doc(description: "Optional client-generated ID")
3535
}
3636

37-
type CreateGuestCartOutput {
38-
cart: Cart
39-
}
40-
4137
input createEmptyCartInput @doc(description: "Assigns a specific `cart_id` to the empty cart.") {
4238
cart_id: String @doc(description: "The ID to assign to the cart.")
4339
}
@@ -195,6 +191,10 @@ type CartDiscount @doc(description: "Contains information about discounts applie
195191
label: [String!]! @doc(description: "The description of the discount.")
196192
}
197193

194+
type CreateGuestCartOutput {
195+
cart: Cart @doc(description: "The newly created cart.")
196+
}
197+
198198
type SetPaymentMethodOnCartOutput @doc(description: "Contains details about the cart after setting the payment method.") {
199199
cart: Cart! @doc(description: "The cart after setting the payment method.")
200200
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CreateGuestCartTest.php

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
516
*/
617
declare(strict_types=1);
718

819
namespace Magento\GraphQl\Quote\Customer;
920

10-
use Magento\Integration\Api\CustomerTokenServiceInterface;
21+
use Magento\Customer\Test\Fixture\Customer;
22+
use Magento\GraphQl\GetCustomerAuthenticationHeader;
1123
use Magento\Quote\Model\QuoteIdMaskFactory;
1224
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
1325
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
26+
use Magento\TestFramework\Fixture\DataFixture;
27+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1428
use Magento\TestFramework\Helper\Bootstrap;
29+
use Magento\TestFramework\ObjectManager;
1530
use Magento\TestFramework\TestCase\GraphQlAbstract;
1631

1732
/**
@@ -20,9 +35,9 @@
2035
class CreateGuestCartTest extends GraphQlAbstract
2136
{
2237
/**
23-
* @var CustomerTokenServiceInterface
38+
* @var ObjectManager
2439
*/
25-
private $customerTokenService;
40+
private $objectManager;
2641

2742
/**
2843
* @var QuoteCollectionFactory
@@ -41,23 +56,29 @@ class CreateGuestCartTest extends GraphQlAbstract
4156

4257
protected function setUp(): void
4358
{
44-
$objectManager = Bootstrap::getObjectManager();
45-
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
46-
$this->quoteCollectionFactory = $objectManager->get(QuoteCollectionFactory::class);
47-
$this->quoteResource = $objectManager->get(QuoteResource::class);
48-
$this->quoteIdMaskFactory = $objectManager->get(QuoteIdMaskFactory::class);
59+
$this->objectManager = Bootstrap::getObjectManager();
60+
$this->quoteCollectionFactory = $this->objectManager->get(QuoteCollectionFactory::class);
61+
$this->quoteResource = $this->objectManager->get(QuoteResource::class);
62+
$this->quoteIdMaskFactory = $this->objectManager->get(QuoteIdMaskFactory::class);
4963
}
5064

51-
/**
52-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
53-
*/
65+
#[
66+
DataFixture(Customer::class, as: 'customer')
67+
]
5468
public function testFailForLoggedInUser()
5569
{
5670
$this->expectException(\Exception::class);
5771
$this->expectExceptionMessage("Use `Query.cart` or `Query.customerCart` for logged in customer.");
5872

73+
$customer = DataFixtureStorageManager::getStorage()->get('customer');
74+
5975
$query = $this->getQuery();
60-
$this->graphQlMutation($query, [], '', $this->getHeaderMapWithCustomerToken());
76+
$this->graphQlMutation(
77+
$query,
78+
[],
79+
'',
80+
$this->objectManager->get(GetCustomerAuthenticationHeader::class)->execute($customer->getEmail())
81+
);
6182
}
6283

6384
/**
@@ -76,20 +97,6 @@ private function getQuery(): string
7697
QUERY;
7798
}
7899

79-
/**
80-
* @param string $username
81-
* @param string $password
82-
* @return array
83-
*/
84-
private function getHeaderMapWithCustomerToken(
85-
string $username = '[email protected]',
86-
string $password = 'password'
87-
): array {
88-
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
89-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
90-
return $headerMap;
91-
}
92-
93100
protected function tearDown(): void
94101
{
95102
$quoteCollection = $this->quoteCollectionFactory->create();

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateGuestCartTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
516
*/
617
declare(strict_types=1);
718

0 commit comments

Comments
 (0)