Skip to content

Commit 8545267

Browse files
committed
ACP2E-3108: fixes for random webapi tests failures
1 parent 4745100 commit 8545267

File tree

3 files changed

+137
-88
lines changed

3 files changed

+137
-88
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@
1111
use Magento\Cms\Api\Data\BlockInterface;
1212
use Magento\Cms\Model\Block;
1313
use Magento\CmsGraphQl\Model\Resolver\Blocks;
14+
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\ProviderInterface;
1516
use Magento\GraphQlResolverCache\Model\Resolver\Result\Type as GraphQlResolverCache;
1617
use Magento\Store\Model\StoreManagerInterface;
18+
use Magento\Store\Test\Fixture\Store;
19+
use Magento\Cms\Test\Fixture\Block as BlockFixture;
20+
use Magento\TestFramework\Fixture\Config;
21+
use Magento\TestFramework\Fixture\DataFixture;
22+
use Magento\TestFramework\Fixture\DataFixtureStorage;
23+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1724
use Magento\TestFramework\ObjectManager;
1825
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
1926
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
2027
use Magento\Widget\Model\Template\FilterEmulate;
2128

2229
/**
2330
* Test for cms block resolver cache
31+
*
32+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2433
*/
2534
class BlockTest extends ResolverCacheAbstract
2635
{
@@ -44,24 +53,29 @@ class BlockTest extends ResolverCacheAbstract
4453
*/
4554
private $storeManager;
4655

56+
/**
57+
* @var DataFixtureStorage
58+
*/
59+
private $fixtures;
60+
4761
protected function setUp(): void
4862
{
4963
$objectManager = ObjectManager::getInstance();
5064
$this->blockRepository = $objectManager->get(BlockRepositoryInterface::class);
5165
$this->graphQlResolverCache = $objectManager->get(GraphQlResolverCache::class);
5266
$this->widgetFilter = $objectManager->get(FilterEmulate::class);
5367
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
68+
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
5469

5570
parent::setUp();
5671
}
5772

58-
/**
59-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
60-
* @magentoDataFixture Magento/Cms/_files/blocks.php
61-
*/
73+
#[
74+
DataFixture(BlockFixture::class, as: 'guest_block')
75+
]
6276
public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
6377
{
64-
$block = $this->blockRepository->getById('enabled_block');
78+
$block = $this->fixtures->get('guest_block');
6579

6680
$query = $this->getQuery([
6781
$block->getIdentifier(),
@@ -94,15 +108,14 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest()
94108
);
95109
}
96110

97-
/**
98-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
99-
* @magentoDataFixture Magento/Cms/_files/block.php
100-
* @magentoDataFixture Magento/Cms/_files/blocks.php
101-
*/
111+
#[
112+
DataFixture(BlockFixture::class, as: 'block1'),
113+
DataFixture(BlockFixture::class, as: 'block2')
114+
]
102115
public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
103116
{
104-
$block1 = $this->blockRepository->getById('enabled_block');
105-
$block2 = $this->blockRepository->getById('fixture_block');
117+
$block1 = $this->fixtures->get('block1');
118+
$block2 = $this->fixtures->get('block2');
106119

107120
$query = $this->getQuery([
108121
$block1->getIdentifier(),
@@ -139,13 +152,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139152
);
140153
}
141154

142-
/**
143-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
144-
* @magentoDataFixture Magento/Cms/_files/block.php
145-
*/
155+
#[
156+
DataFixture(BlockFixture::class, as: 'deleted_block')
157+
]
146158
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
147159
{
148-
$block = $this->blockRepository->getById('fixture_block');
160+
$block = $this->fixtures->get('deleted_block');
149161

150162
$query = $this->getQuery([
151163
$block->getIdentifier(),
@@ -177,13 +189,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177189
);
178190
}
179191

180-
/**
181-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
182-
* @magentoDataFixture Magento/Cms/_files/blocks.php
183-
*/
192+
#[
193+
DataFixture(BlockFixture::class, as: 'disabled_block')
194+
]
184195
public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
185196
{
186-
$block = $this->blockRepository->getById('enabled_block');
197+
$block = $this->fixtures->get('disabled_block');
187198

188199
$query = $this->getQuery([
189200
$block->getIdentifier(),
@@ -217,14 +228,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217228
}
218229

219230
/**
220-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
221-
* @magentoDataFixture Magento/Cms/_files/block.php
222-
* @magentoDataFixture Magento/Store/_files/second_store.php
231+
* @throws LocalizedException
232+
* @throws \Zend_Cache_Exception
223233
*/
234+
#[
235+
DataFixture(BlockFixture::class, as: 'block'),
236+
DataFixture(Store::class, as: 'second_store'),
237+
]
224238
public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView()
225239
{
226240
/** @var Block $block */
227-
$block = $this->blockRepository->getById('fixture_block');
241+
$block = $this->fixtures->get('block');
242+
243+
/** @var \Magento\Store\Model\Store $store */
244+
$store = $this->fixtures->get('second_store');
228245

229246
$query = $this->getQuery([
230247
$block->getIdentifier(),
@@ -238,17 +255,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238255
$cacheEntryDecoded = json_decode($cacheEntry, true);
239256

240257
$this->assertEqualsCanonicalizing(
241-
$this->generateExpectedDataFromBlocks([$block]),
242-
$cacheEntryDecoded
258+
$cacheEntryDecoded,
259+
$this->generateExpectedDataFromBlocks([$block])
243260
);
244261

245262
$this->assertTagsByCacheIdentityAndBlocks(
246-
$cacheKey,
263+
(string)$cacheKey,
247264
[$block]
248265
);
249266

250267
// assert that cache is invalidated after changing block's store view
251-
$secondStoreViewId = $this->storeManager->getStore('fixture_second_store')->getId();
268+
$secondStoreViewId = $store->getId();
252269
$block->setStoreId($secondStoreViewId);
253270
$this->blockRepository->save($block);
254271

@@ -283,15 +300,15 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283300
);
284301
}
285302

286-
/**
287-
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
288-
* @magentoDataFixture Magento/Cms/_files/block.php
289-
* @magentoDataFixture Magento/Cms/_files/blocks.php
290-
*/
303+
#[
304+
Config('system/full_page_cache/caching_application', '2', 'store', 'default'),
305+
DataFixture(BlockFixture::class, as: 'block1'),
306+
DataFixture(BlockFixture::class, as: 'block2')
307+
]
291308
public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
292309
{
293310
// query block1
294-
$block1 = $this->blockRepository->getById('fixture_block');
311+
$block1 = $this->fixtures->get('block1');
295312

296313
$queryBlock1 = $this->getQuery([
297314
$block1->getIdentifier(),
@@ -302,7 +319,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302319
$cacheKeyBlock1 = $this->getResolverCacheKeyFromBlocks([$block1]);
303320

304321
// query block2
305-
$block2 = $this->blockRepository->getById('enabled_block');
322+
$block2 = $this->fixtures->get('block2');
306323

307324
$queryBlock2 = $this->getQuery([
308325
$block2->getIdentifier(),

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

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\Catalog\Test\Fixture\Product;
1011
use Magento\Customer\Api\AddressRepositoryInterface;
1112
use Magento\Customer\Api\CustomerRepositoryInterface;
13+
use Magento\Customer\Test\Fixture\Customer;
1214
use Magento\Framework\Api\SearchCriteriaBuilder;
1315
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1416
use Magento\Integration\Api\CustomerTokenServiceInterface;
17+
use Magento\Quote\Model\Quote;
1518
use Magento\Quote\Model\QuoteFactory;
1619
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1720
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
21+
use Magento\Quote\Test\Fixture\AddProductToCart;
22+
use Magento\Quote\Test\Fixture\GuestCart;
23+
use Magento\Quote\Test\Fixture\QuoteIdMask;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorage;
26+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1827
use Magento\TestFramework\Helper\Bootstrap;
1928
use Magento\TestFramework\TestCase\GraphQlAbstract;
2029

@@ -61,6 +70,11 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract
6170
*/
6271
private $customerRepository;
6372

73+
/**
74+
* @var DataFixtureStorage
75+
*/
76+
private $fixtures;
77+
6478
protected function setUp(): void
6579
{
6680
$objectManager = Bootstrap::getObjectManager();
@@ -72,6 +86,7 @@ protected function setUp(): void
7286
$this->customerAddressRepository = $objectManager->get(AddressRepositoryInterface::class);
7387
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
7488
$this->customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
89+
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
7590
}
7691

7792
/**
@@ -715,25 +730,49 @@ public function testSetBillingAddressToAnotherCustomerCart()
715730
* Tests that a logged-in customer cannot use a saved customer address that is not their own.
716731
*
717732
* _security
718-
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
719-
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
720-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
721-
*
722733
*/
734+
#[
735+
DataFixture(Customer::class, ['addresses' => [['postcode' => '12345']]], as: 'customer1'),
736+
DataFixture(Customer::class, ['addresses' => [['postcode' => '12345']]], as: 'customer2'),
737+
DataFixture(Product::class, as: 'product'),
738+
DataFixture(GuestCart::class, ['customer_id' => '$customer2.id$'], as: 'cart'),
739+
DataFixture(QuoteIdMask::class, [
740+
'cart_id' => '$cart.id$'
741+
], 'quoteIdMask'),
742+
DataFixture(AddProductToCart::class, [
743+
'cart_id' => '$cart.id$',
744+
'product_id' => '$product.id$',
745+
'qty' => 1
746+
])
747+
]
723748
public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
724749
{
725-
$this->expectException(\Exception::class);
726-
$this->expectExceptionMessage('Current customer does not have permission to address with ID "1"');
750+
/** @var \Magento\Customer\Model\Customer $customer1 */
751+
$customer1 = $this->fixtures->get('customer1');
752+
$customer1AddressId = current($customer1->getAddresses())->getId();
753+
$customer2 = $this->fixtures->get('customer2');
754+
$customer2 = $this->customerRepository->getById($customer2->getId());
727755

728-
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2);
756+
/** @var Quote $quote */
757+
$quote = $this->fixtures->get('cart');
758+
$maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId();
759+
760+
$quote->setCustomer($customer2);
761+
$quote->setCustomerIsGuest(false);
762+
$quote->save();
763+
764+
$this->expectException(\Exception::class);
765+
$this->expectExceptionMessage(
766+
'Current customer does not have permission to address with ID "'.$customer1AddressId.'"'
767+
);
729768

730769
$query = <<<QUERY
731770
mutation {
732771
setBillingAddressOnCart(
733772
input: {
734773
cart_id: "$maskedQuoteId"
735774
billing_address: {
736-
customer_address_id: 1
775+
customer_address_id: "$customer1AddressId"
737776
}
738777
}
739778
) {
@@ -745,7 +784,7 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
745784
}
746785
}
747786
QUERY;
748-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
787+
$this->graphQlMutation($query, [], '', $this->getHeaderMap($customer2->getEmail()));
749788
}
750789

751790
/**

0 commit comments

Comments
 (0)