Skip to content

Commit e1eb1b2

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent 304a638 commit e1eb1b2

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

app/code/Magento/Quote/Test/Fixture/CustomerCart.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
use Magento\Quote\Api\CartRepositoryInterface;
1313
use Magento\Quote\Model\QuoteFactory;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
use Magento\TestFramework\Fixture\Api\DataMerger;
1516
use Magento\TestFramework\Fixture\Api\ServiceFactory;
17+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
1618
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
1719

1820
class CustomerCart implements RevertibleDataFixtureInterface
1921
{
2022

23+
private const DEFAULT_DATA = [
24+
'customer_id' => null
25+
];
26+
2127
/**
2228
* @var ServiceFactory
2329
*/
@@ -43,32 +49,49 @@ class CustomerCart implements RevertibleDataFixtureInterface
4349
*/
4450
private $quoteFactory;
4551

52+
/**
53+
* @var ProcessorInterface
54+
*/
55+
private $dataProcessor;
56+
57+
/**
58+
* @var DataMerger
59+
*/
60+
private $dataMerger;
61+
4662
/**
4763
* @param ServiceFactory $serviceFactory
4864
* @param CartRepositoryInterface $cartRepository
4965
* @param CartManagementInterface $cartManagement
5066
* @param QuoteResource $quoteResource
5167
* @param QuoteFactory $quoteFactory
68+
* @param ProcessorInterface $dataProcessor
69+
* @param DataMerger $dataMerger
5270
*/
5371
public function __construct(
5472
ServiceFactory $serviceFactory,
5573
CartRepositoryInterface $cartRepository,
5674
CartManagementInterface $cartManagement,
5775
QuoteResource $quoteResource,
58-
QuoteFactory $quoteFactory
76+
QuoteFactory $quoteFactory,
77+
ProcessorInterface $dataProcessor,
78+
DataMerger $dataMerger,
5979
) {
6080
$this->serviceFactory = $serviceFactory;
6181
$this->cartRepository = $cartRepository;
6282
$this->cartManagement = $cartManagement;
6383
$this->quoteResource = $quoteResource;
6484
$this->quoteFactory = $quoteFactory;
85+
$this->dataProcessor = $dataProcessor;
86+
$this->dataMerger = $dataMerger;
6587
}
6688

6789
/**
6890
* @inheritdoc
6991
*/
7092
public function apply(array $data = []): ?DataObject
7193
{
94+
$data = $this->prepareData($data);
7295
$customerId = $data['customer_id'] ?? null;
7396
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'createEmptyCartForCustomer');
7497
$cartId = $cartService->execute(['customerId' => $customerId]);
@@ -84,4 +107,16 @@ public function revert(DataObject $data): void
84107
$cartRepositoryService = $this->serviceFactory->create(CartRepositoryInterface::class, 'delete');
85108
$cartRepositoryService->execute(['quote' => $data]);
86109
}
110+
111+
/**
112+
* Prepare quote data
113+
*
114+
* @param array $data
115+
* @return array
116+
*/
117+
private function prepareData(array $data): array
118+
{
119+
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data, false);
120+
return $this->dataProcessor->process($this, $data);
121+
}
87122
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/CustomerOrders/GetCustomerOrdersTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
use Magento\Customer\Model\CustomerAuthUpdate;
1414
use Magento\Customer\Model\CustomerRegistry;
1515
use Magento\Customer\Test\Fixture\Customer;
16+
use Magento\Framework\Exception\AuthenticationException;
1617
use Magento\Framework\ObjectManagerInterface;
1718
use Magento\Integration\Api\CustomerTokenServiceInterface;
19+
use Magento\Quote\Test\Fixture\AddProductToCart;
20+
use Magento\Quote\Test\Fixture\CustomerCart;
1821
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
1922
use Magento\Store\Test\Fixture\Store as StoreFixture;
2023
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
@@ -97,7 +100,9 @@ protected function setUp(): void
97100
]
98101
],
99102
as: 'customer'
100-
)
103+
),
104+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote'),
105+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1])
101106
]
102107
public function testGetCustomerOrders()
103108
{
@@ -136,4 +141,16 @@ public function testGetCustomerOrders()
136141
$this->assertEquals('Smith', $response['customer']['lastname']);
137142
$this->assertEquals($currentEmail, $response['customer']['email']);
138143
}
144+
145+
/**
146+
* @param string $email
147+
* @param string $password
148+
* @return array
149+
* @throws AuthenticationException
150+
*/
151+
private function getCustomerAuthHeaders(string $email, string $password): array
152+
{
153+
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password);
154+
return ['Authorization' => 'Bearer ' . $customerToken];
155+
}
139156
}

0 commit comments

Comments
 (0)