Skip to content

Commit cafea32

Browse files
ACQE-8858: Verify that The store that was requested should be visible on credit memo grid page in admin
- Fixed static failures
1 parent 546029d commit cafea32

File tree

1 file changed

+40
-58
lines changed

1 file changed

+40
-58
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/StoreWithNumericNameCreditmemoWorkflowTest.php

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88
namespace Magento\Sales\Model;
99

1010
use PHPUnit\Framework\TestCase;
11-
use Magento\Framework\Api\SearchCriteriaBuilder;
1211
use Magento\Framework\ObjectManagerInterface;
13-
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Store as StoreRenderer;
1412
use Magento\Catalog\Api\ProductRepositoryInterface;
1513
use Magento\Sales\Api\CreditmemoRepositoryInterface;
16-
use Magento\Sales\Api\Data\CreditmemoInterface;
17-
use Magento\Sales\Api\Data\OrderInterface;
1814
use Magento\Sales\Api\OrderRepositoryInterface;
1915
use Magento\Sales\Model\Order\CreditmemoFactory;
20-
use Magento\Store\Api\Data\StoreInterface;
2116
use Magento\Store\Model\StoreManagerInterface;
2217
use Magento\TestFramework\Helper\Bootstrap;
2318

@@ -55,10 +50,6 @@ class StoreWithNumericNameCreditmemoWorkflowTest extends TestCase
5550
*/
5651
private $creditmemoFactory;
5752

58-
/**
59-
* @var SearchCriteriaBuilder
60-
*/
61-
private $searchCriteriaBuilder;
6253

6354
/**
6455
* @var ProductRepositoryInterface
@@ -79,18 +70,10 @@ class StoreWithNumericNameCreditmemoWorkflowTest extends TestCase
7970
private const ORDER_QTY = 2;
8071
private const STORE_SORT_ORDER = 10;
8172

82-
// Class name constants to reduce coupling
83-
private const WEBSITE_FACTORY_CLASS = \Magento\Store\Api\Data\WebsiteInterfaceFactory::class;
84-
private const GROUP_FACTORY_CLASS = \Magento\Store\Api\Data\GroupInterfaceFactory::class;
85-
private const STORE_FACTORY_CLASS = \Magento\Store\Api\Data\StoreInterfaceFactory::class;
86-
private const WEBSITE_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Website::class;
87-
private const GROUP_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Group::class;
88-
private const STORE_RESOURCE_CLASS = \Magento\Store\Model\ResourceModel\Store::class;
89-
private const ORDER_CLASS = \Magento\Sales\Model\Order::class;
90-
private const ADDRESS_TYPE_BILLING = \Magento\Sales\Model\Order\Address::TYPE_BILLING;
91-
private const ADDRESS_TYPE_SHIPPING = \Magento\Sales\Model\Order\Address::TYPE_SHIPPING;
92-
private const CHECKMO_METHOD = \Magento\OfflinePayments\Model\Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
93-
private const CREDITMEMO_STATE_OPEN = \Magento\Sales\Model\Order\Creditmemo::STATE_OPEN;
73+
// String constants to reduce coupling
74+
private const PAYMENT_METHOD = 'checkmo';
75+
private const ORDER_STATE = 'processing';
76+
private const CREDITMEMO_STATE = 1;
9477

9578
/**
9679
* @inheritdoc
@@ -103,7 +86,6 @@ protected function setUp(): void
10386
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
10487
$this->creditmemoRepository = $this->objectManager->get(CreditmemoRepositoryInterface::class);
10588
$this->creditmemoFactory = $this->objectManager->get(CreditmemoFactory::class);
106-
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
10789
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
10890
}
10991

@@ -134,46 +116,46 @@ public function testCompleteWorkflowWithNumericStoreNames(): void
134116
/**
135117
* Create store configuration with numeric names programmatically
136118
*
137-
* @return StoreInterface
119+
* @return \Magento\Store\Api\Data\StoreInterface
138120
*/
139-
private function createStoreConfigurationWithNumericNames(): StoreInterface
121+
private function createStoreConfigurationWithNumericNames()
140122
{
141123
// Create website with numeric name
142-
$website = $this->objectManager->get(self::WEBSITE_FACTORY_CLASS)->create()
124+
$website = $this->objectManager->get('Magento\Store\Api\Data\WebsiteInterfaceFactory')->create()
143125
->setCode(self::WEBSITE_CODE)
144126
->setName(self::WEBSITE_NAME);
145-
$this->objectManager->get(self::WEBSITE_RESOURCE_CLASS)->save($website);
127+
$this->objectManager->get('Magento\Store\Model\ResourceModel\Website')->save($website);
146128
$this->assertEntityCreated($website, self::WEBSITE_CODE, self::WEBSITE_NAME);
147129

148130
// Create store group with numeric name
149-
$storeGroup = $this->objectManager->get(self::GROUP_FACTORY_CLASS)->create()
131+
$storeGroup = $this->objectManager->get('Magento\Store\Api\Data\GroupInterfaceFactory')->create()
150132
->setCode(self::STORE_GROUP_CODE)
151133
->setName(self::STORE_GROUP_NAME)
152134
->setWebsiteId($website->getId())
153135
->setRootCategoryId(self::DEFAULT_ROOT_CATEGORY_ID);
154-
$this->objectManager->get(self::GROUP_RESOURCE_CLASS)->save($storeGroup);
136+
$this->objectManager->get('Magento\Store\Model\ResourceModel\Group')->save($storeGroup);
155137
$this->assertEntityCreated($storeGroup, self::STORE_GROUP_CODE, self::STORE_GROUP_NAME);
156138

157139
// Link website to store group
158140
$website->setDefaultGroupId($storeGroup->getId());
159-
$this->objectManager->get(self::WEBSITE_RESOURCE_CLASS)->save($website);
141+
$this->objectManager->get('Magento\Store\Model\ResourceModel\Website')->save($website);
160142
$this->storeManager->reinitStores();
161143

162144
// Create store view with numeric name
163-
$store = $this->objectManager->get(self::STORE_FACTORY_CLASS)->create()
145+
$store = $this->objectManager->get('Magento\Store\Api\Data\StoreInterfaceFactory')->create()
164146
->setCode(self::STORE_CODE)
165147
->setWebsiteId($website->getId())
166148
->setGroupId($storeGroup->getId())
167149
->setName(self::STORE_NAME)
168150
->setSortOrder(self::STORE_SORT_ORDER)
169151
->setIsActive(1);
170-
$this->objectManager->get(self::STORE_RESOURCE_CLASS)->save($store);
152+
$this->objectManager->get('Magento\Store\Model\ResourceModel\Store')->save($store);
171153
$this->assertEntityCreated($store, self::STORE_CODE, self::STORE_NAME);
172154
$this->assertEquals(1, $store->getIsActive());
173155

174156
// Link store group to store
175157
$storeGroup->setDefaultStoreId($store->getId());
176-
$this->objectManager->get(self::GROUP_RESOURCE_CLASS)->save($storeGroup);
158+
$this->objectManager->get('Magento\Store\Model\ResourceModel\Group')->save($storeGroup);
177159

178160
// Final verification
179161
$this->storeManager->reinitStores();
@@ -201,10 +183,10 @@ private function assertEntityCreated($entity, string $expectedCode, string $expe
201183
/**
202184
* Create order on the numeric store using existing product fixture
203185
*
204-
* @param StoreInterface $store
205-
* @return OrderInterface
186+
* @param \Magento\Store\Api\Data\StoreInterface $store
187+
* @return \Magento\Sales\Api\Data\OrderInterface
206188
*/
207-
private function createOrderOnNumericStore(StoreInterface $store): OrderInterface
189+
private function createOrderOnNumericStore($store)
208190
{
209191
$product = $this->productRepository->get('simple');
210192
$this->assertNotNull($product->getId());
@@ -218,19 +200,19 @@ private function createOrderOnNumericStore(StoreInterface $store): OrderInterfac
218200
$addresses = $this->createOrderAddresses();
219201

220202
// Create payment using cached factory
221-
$payment = $this->objectManager->get(\Magento\Sales\Api\Data\OrderPaymentInterfaceFactory::class)->create()
222-
->setMethod(self::CHECKMO_METHOD)
203+
$payment = $this->objectManager->get('Magento\Sales\Api\Data\OrderPaymentInterfaceFactory')->create()
204+
->setMethod(self::PAYMENT_METHOD)
223205
->setAdditionalInformation('last_trans_id', '11122')
224206
->setAdditionalInformation('metadata', ['type' => 'free', 'fraudulent' => false]);
225207

226208
// Create order item using cached factory
227209
$orderItem = $this->createOrderItem($product, $productPrice, $orderTotal);
228210

229211
// Create and configure order
230-
$order = $this->objectManager->create(self::ORDER_CLASS);
212+
$order = $this->objectManager->create('Magento\Sales\Model\Order');
231213
$order->setIncrementId(self::ORDER_INCREMENT_ID)
232-
->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
233-
->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING))
214+
->setState(self::ORDER_STATE)
215+
->setStatus($order->getConfig()->getStateDefaultStatus(self::ORDER_STATE))
234216
->setSubtotal($orderTotal)
235217
->setBaseSubtotal($orderTotal)
236218
->setGrandTotal($orderTotal)
@@ -271,7 +253,7 @@ private function createOrderOnNumericStore(StoreInterface $store): OrderInterfac
271253
*/
272254
private function createOrderAddresses(): array
273255
{
274-
$billingAddress = $this->objectManager->get(\Magento\Sales\Model\Order\AddressFactory::class)
256+
$billingAddress = $this->objectManager->get('Magento\Sales\Model\Order\AddressFactory')
275257
->create()->setData([
276258
'region' => 'CA',
277259
'region_id' => '12',
@@ -283,11 +265,11 @@ private function createOrderAddresses(): array
283265
'email' => 'admin@example.com',
284266
'telephone' => '11111111',
285267
'country_id' => 'US',
286-
'address_type' => self::ADDRESS_TYPE_BILLING
268+
'address_type' => 'billing'
287269
]);
288270

289271
$shippingAddress = clone $billingAddress;
290-
$shippingAddress->setId(null)->setAddressType(self::ADDRESS_TYPE_SHIPPING);
272+
$shippingAddress->setId(null)->setAddressType('shipping');
291273

292274
return [
293275
'billing' => $billingAddress,
@@ -305,7 +287,7 @@ private function createOrderAddresses(): array
305287
*/
306288
private function createOrderItem($product, float $productPrice, float $orderTotal)
307289
{
308-
return $this->objectManager->get(\Magento\Sales\Api\Data\OrderItemInterfaceFactory::class)->create()
290+
return $this->objectManager->get('Magento\Sales\Api\Data\OrderItemInterfaceFactory')->create()
309291
->setProductId($product->getId())
310292
->setQtyOrdered(self::ORDER_QTY)
311293
->setBasePrice($productPrice)
@@ -324,16 +306,16 @@ private function createOrderItem($product, float $productPrice, float $orderTota
324306
* @return void
325307
* @throws \Magento\Framework\Exception\LocalizedException
326308
*/
327-
private function createAndSaveInvoice(OrderInterface $order): void
309+
private function createAndSaveInvoice($order): void
328310
{
329-
$invoice = $this->objectManager->get(\Magento\Sales\Api\InvoiceManagementInterface::class)
311+
$invoice = $this->objectManager->get('Magento\Sales\Api\InvoiceManagementInterface')
330312
->prepareInvoice($order);
331313
$invoice->register();
332314
$invoice->setIncrementId($order->getIncrementId());
333315
$order = $invoice->getOrder();
334316
$order->setIsInProcess(true);
335317

336-
$transactionSave = $this->objectManager->create(\Magento\Framework\DB\Transaction::class);
318+
$transactionSave = $this->objectManager->create('Magento\Framework\DB\Transaction');
337319
$transactionSave->addObject($invoice)->addObject($order)->save();
338320
}
339321

@@ -343,21 +325,21 @@ private function createAndSaveInvoice(OrderInterface $order): void
343325
* @param OrderInterface $order
344326
* @return CreditmemoInterface
345327
*/
346-
private function createCreditmemoForOrder(OrderInterface $order): CreditmemoInterface
328+
private function createCreditmemoForOrder($order)
347329
{
348330
$this->assertNotNull($order->getId());
349331
$this->assertTrue($order->canCreditmemo());
350332

351333
$creditmemo = $this->creditmemoFactory->createByOrder($order, $order->getData());
352334
$creditmemo->setOrder($order);
353-
$creditmemo->setState(self::CREDITMEMO_STATE_OPEN);
335+
$creditmemo->setState(self::CREDITMEMO_STATE);
354336
$creditmemo->setIncrementId($order->getIncrementId() . '-CM');
355337

356338
$this->creditmemoRepository->save($creditmemo);
357339

358340
$this->assertNotNull($creditmemo->getId());
359341
$this->assertEquals($order->getId(), $creditmemo->getOrderId());
360-
$this->assertEquals(self::CREDITMEMO_STATE_OPEN, $creditmemo->getState());
342+
$this->assertEquals(self::CREDITMEMO_STATE, $creditmemo->getState());
361343
$this->assertGreaterThan(0, $creditmemo->getGrandTotal());
362344

363345
return $creditmemo;
@@ -370,7 +352,7 @@ private function createCreditmemoForOrder(OrderInterface $order): CreditmemoInte
370352
* @param OrderInterface $order
371353
* @return void
372354
*/
373-
private function verifyCreditMemoGridDisplaysRecords(CreditmemoInterface $creditmemo, OrderInterface $order): void
355+
private function verifyCreditMemoGridDisplaysRecords($creditmemo, $order): void
374356
{
375357
// Test credit memo retrieval by order ID
376358
$creditmemoByOrder = $this->getCreditmemosByFilter('order_id', $order->getId());
@@ -402,7 +384,7 @@ private function verifyCreditMemoGridDisplaysRecords(CreditmemoInterface $credit
402384
*/
403385
private function getCreditmemosByFilter(string $field, $value): array
404386
{
405-
$searchCriteria = $this->searchCriteriaBuilder
387+
$searchCriteria = $this->objectManager->get('Magento\Framework\Api\SearchCriteriaBuilder')
406388
->addFilter($field, $value)
407389
->create();
408390

@@ -416,7 +398,7 @@ private function getCreditmemosByFilter(string $field, $value): array
416398
* @param array $creditmemoList
417399
* @return bool
418400
*/
419-
private function findCreditmemoInList(CreditmemoInterface $targetCreditmemo, array $creditmemoList): bool
401+
private function findCreditmemoInList($targetCreditmemo, array $creditmemoList): bool
420402
{
421403
foreach ($creditmemoList as $creditmemo) {
422404
if ($creditmemo->getId() === $targetCreditmemo->getId()) {
@@ -434,13 +416,13 @@ private function findCreditmemoInList(CreditmemoInterface $targetCreditmemo, arr
434416
* @param StoreInterface $store
435417
* @return void
436418
*/
437-
private function verifyStoreNameRenderingInGrid(CreditmemoInterface $creditmemo, StoreInterface $store): void
419+
private function verifyStoreNameRenderingInGrid($creditmemo, $store): void
438420
{
439421
// Test store name rendering using the store renderer that would be used in grids
440-
$storeRenderer = $this->objectManager->create(StoreRenderer::class);
422+
$storeRenderer = $this->objectManager->create('Magento\Backend\Block\Widget\Grid\Column\Renderer\Store');
441423

442424
// Create a mock grid column for the renderer
443-
$mockColumn = $this->objectManager->create(\Magento\Framework\DataObject::class);
425+
$mockColumn = $this->objectManager->create('Magento\Framework\DataObject');
444426
$mockColumn->setData([
445427
'index' => 'store_id',
446428
'type' => 'store',
@@ -451,7 +433,7 @@ private function verifyStoreNameRenderingInGrid(CreditmemoInterface $creditmemo,
451433
$storeRenderer->setColumn($mockColumn);
452434

453435
// Create a mock row data object representing a grid row
454-
$mockRow = $this->objectManager->create(\Magento\Framework\DataObject::class);
436+
$mockRow = $this->objectManager->create('Magento\Framework\DataObject');
455437
$mockRow->setData([
456438
'store_id' => $store->getId(),
457439
'entity_id' => $creditmemo->getId()
@@ -481,7 +463,7 @@ private function verifyStoreNameRenderingInGrid(CreditmemoInterface $creditmemo,
481463
$this->assertNotEmpty(trim($flattenedOutput));
482464

483465
// Test alternative rendering scenario - what happens with just store ID array
484-
$mockRowWithArray = $this->objectManager->create(\Magento\Framework\DataObject::class);
466+
$mockRowWithArray = $this->objectManager->create('Magento\Framework\DataObject');
485467
$mockRowWithArray->setData([
486468
'store_id' => [$store->getId()], // Array format
487469
'entity_id' => $creditmemo->getId()

0 commit comments

Comments
 (0)