Skip to content

Commit 2d57fae

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent 172b220 commit 2d57fae

File tree

4 files changed

+100
-47
lines changed

4 files changed

+100
-47
lines changed

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
use Magento\Quote\Api\Data\PaymentInterface;
3333
use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter;
3434
use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter;
35-
use Magento\Quote\Model\Quote as QuoteEntity;
3635
use Magento\Quote\Model\Quote\AddressFactory;
36+
use Magento\Quote\Model\Quote as QuoteEntity;
3737
use Magento\Quote\Model\Quote\Item\ToOrderItem as ToOrderItemConverter;
3838
use Magento\Quote\Model\Quote\Payment\ToOrderPayment as ToOrderPaymentConverter;
3939
use Magento\Quote\Model\ResourceModel\Quote\Item;
@@ -324,7 +324,7 @@ public function assignCustomer($cartId, $customerId, $storeId)
324324
$customerActiveQuote->setIsActive(0);
325325
$this->quoteRepository->save($customerActiveQuote);
326326

327-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
327+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
328328
} catch (NoSuchEntityException $e) {
329329
}
330330

@@ -645,7 +645,7 @@ protected function _prepareCustomerQuote($quote)
645645
if ($defaultShipping) {
646646
try {
647647
$shippingAddress = $this->addressRepository->getById($defaultShipping);
648-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
648+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
649649
} catch (LocalizedException $e) {
650650
// no address
651651
}
@@ -679,7 +679,7 @@ protected function _prepareCustomerQuote($quote)
679679
if ($defaultBilling) {
680680
try {
681681
$billingAddress = $this->addressRepository->getById($defaultBilling);
682-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
682+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
683683
} catch (LocalizedException $e) {
684684
// no address
685685
}

app/code/Magento/SalesGraphQl/Model/Resolver/CustomerOrders.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ private function getStoresByScope(string $scope, StoreInterface $store): array
158158
{
159159
$storeIds = [];
160160
switch ($scope) {
161-
case 'global':
161+
case 'GLOBAL':
162162
$storeIds = $this->getStoresByFilter(null, null);
163163
break;
164-
case 'website':
164+
case 'WEBSITE':
165165
$websiteId = $store->getWebsiteId();
166166
$storeIds = $this->getStoresByFilter((int)$websiteId, null);
167167
break;
168-
case 'store':
168+
case 'STORE':
169169
$storeGroupId = $store->getStoreGroupId();
170170
$storeIds = $this->getStoresByFilter(null, (int)$storeGroupId);
171171
break;
@@ -182,7 +182,7 @@ private function getStoresByScope(string $scope, StoreInterface $store): array
182182
* @param int|null $storeGroupId
183183
* @return array
184184
*/
185-
private function getStoresByFilter(?int $websiteId, ?int $storeGroupId)
185+
private function getStoresByFilter(?int $websiteId, ?int $storeGroupId): array
186186
{
187187
$stores = $this->storeManager->getStores(true, true);
188188
$storeIds = [];

app/code/Magento/Store/Test/Fixture/Store.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
use Magento\Framework\DataObject;
1111
use Magento\Store\Api\Data\StoreInterface;
12+
use Magento\Store\Api\Data\StoreInterfaceFactory;
13+
use Magento\Store\Model\ResourceModel\Store as StoreResource;
1214
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\TestFramework\Db\Sequence;
1316
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
1417
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
15-
use Magento\Store\Api\Data\StoreInterfaceFactory;
16-
use Magento\Store\Model\ResourceModel\Store as StoreResource;
1718

1819
class Store implements RevertibleDataFixtureInterface
1920
{
@@ -44,23 +45,30 @@ class Store implements RevertibleDataFixtureInterface
4445
*/
4546
private $dataProcessor;
4647

48+
/**
49+
* @var Sequence
50+
*/
51+
private $sequence;
52+
4753
/**
4854
* @param StoreInterfaceFactory $storeFactory
4955
* @param StoreResource $storeResource
5056
* @param StoreManagerInterface $storeManager
5157
* @param ProcessorInterface $dataProcessor
52-
* @param ManagerInterface $eventManager
58+
* @param Sequence $sequence
5359
*/
5460
public function __construct(
5561
StoreInterfaceFactory $storeFactory,
5662
StoreResource $storeResource,
5763
StoreManagerInterface $storeManager,
58-
ProcessorInterface $dataProcessor
64+
ProcessorInterface $dataProcessor,
65+
Sequence $sequence
5966
) {
6067
$this->storeFactory = $storeFactory;
6168
$this->storeResource = $storeResource;
6269
$this->storeManager = $storeManager;
6370
$this->dataProcessor = $dataProcessor;
71+
$this->sequence = $sequence;
6472
}
6573

6674
/**
@@ -85,11 +93,7 @@ public function apply(array $data = []): ?DataObject
8593
$store->setData($this->prepareData($data));
8694
$this->storeResource->save($store);
8795
$this->storeManager->reinitStores();
88-
89-
$sequence = \Magento\Framework\App\ObjectManager::getInstance()->create(\Magento\TestFramework\Db\Sequence::class);
90-
$n = $store->getId() + 1;
91-
$sequence->generateSequences($n);
92-
96+
$this->regenerateSequenceTables($store->getId());
9397
return $store;
9498
}
9599

@@ -130,4 +134,17 @@ private function prepareData(array $data): array
130134

131135
return $this->dataProcessor->process($this, $data);
132136
}
137+
138+
/**
139+
* @param int $storeId
140+
*
141+
* @return void
142+
*/
143+
private function regenerateSequenceTables(int $storeId): void
144+
{
145+
if ($storeId >= 10) {
146+
$n = $storeId + 1;
147+
$this->sequence->generateSequences($n);
148+
}
149+
}
133150
}

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

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,26 @@ protected function setUp(): void
105105
],
106106
as: 'customer'
107107
),
108-
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$', 'store_id' => '$store2.id$'], as: 'quote'),
109-
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1]),
110-
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote.id$']),
111-
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']),
112-
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
113-
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
114-
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order')
108+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$', 'store_id' => '$store2.id$'], as: 'quote1'),
109+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote1.id$', 'product_id' => '$product.id$', 'qty' => 1]),
110+
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote1.id$']),
111+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote1.id$']),
112+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote1.id$']),
113+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote1.id$']),
114+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote1.id$'], 'order1'),
115+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$', 'store_id' => '$store3.id$'], as: 'quote2'),
116+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote2.id$', 'product_id' => '$product.id$', 'qty' => 1]),
117+
DataFixture(SetBillingAddress::class, ['cart_id' => '$quote2.id$']),
118+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote2.id$']),
119+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote2.id$']),
120+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote2.id$']),
121+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote2.id$'], 'order2')
115122
]
116123
public function testGetCustomerOrders()
117124
{
118125
$fixtures = DataFixtureStorageManager::getStorage();
119126
$store2 = $fixtures->get('store2');
127+
$store3 = $fixtures->get('store3');
120128
$customer = $fixtures->get('customer');
121129
$currentEmail = $customer->getEmail();
122130
$currentPassword = 'password';
@@ -130,12 +138,60 @@ public function testGetCustomerOrders()
130138
);
131139
$customerToken = $tokenResponse['body']['generateCustomerToken']['token'];
132140

141+
$query = $this->getCustomerOrdersQuery('STORE');
142+
$response = $this->graphQlQuery(
143+
$query,
144+
[],
145+
'',
146+
$this->getCustomerHeaders($customerToken, $store2->getCode())
147+
);
148+
149+
$this->assertNotNull($response['customer']['orders']);
150+
151+
$response = $this->graphQlQuery(
152+
$query,
153+
[],
154+
'',
155+
$this->getCustomerHeaders($customerToken, $store3->getCode())
156+
);
157+
158+
$this->assertNotNull($response['customer']['orders']);
159+
160+
$query = $this->getCustomerOrdersQuery();
161+
$response = $this->graphQlQuery(
162+
$query,
163+
[],
164+
'',
165+
$this->getCustomerHeaders($customerToken, null)
166+
);
167+
168+
$this->assertNotNull($response['customer']['orders']);
169+
}
170+
171+
/**
172+
* @param string $token
173+
* @param string|null $storeCode
174+
*
175+
* @return array
176+
*/
177+
private function getCustomerHeaders(string $token, ?string $storeCode): array
178+
{
179+
return ['Authorization' => 'Bearer ' . $token, 'Store' => $storeCode ?? 'default'];
180+
}
181+
182+
/**
183+
* @param string|null $scope
184+
*
185+
* @return array|string
186+
*/
187+
private function getCustomerOrdersQuery(?string $scope = null): array|string
188+
{
133189
$query = <<<QUERY
134190
query {
135191
customer {
136192
orders(
137193
pageSize: 20,
138-
scope: STORE
194+
{{scope}}
139195
) {
140196
items {
141197
id
@@ -150,28 +206,8 @@ public function testGetCustomerOrders()
150206
}
151207
}
152208
QUERY;
153-
$response = $this->graphQlQuery(
154-
$query,
155-
[],
156-
'',
157-
$this->getCustomerHeaders($customerToken, $store2->getCode())
158-
);
159-
160-
$this->assertNotNull($response['customer']['orders']);
161-
$this->assertEquals('John', $response['customer']['firstname']);
162-
$this->assertEquals('Smith', $response['customer']['lastname']);
163-
$this->assertEquals($currentEmail, $response['customer']['email']);
164-
}
165-
166-
/**
167-
* @param string $token
168-
* @param string $storeCode
169-
*
170-
* @return array
171-
*/
172-
private function getCustomerHeaders(string $token, string $storeCode): array
173-
{
174-
return ['Authorization' => 'Bearer ' . $token, 'Store' => $storeCode];
209+
$query = str_replace("{{scope}}", isset($scope) ? "scope: $scope" : '', $query);
210+
return $query;
175211
}
176212

177213
/**

0 commit comments

Comments
 (0)