Skip to content

Commit 04ab6f5

Browse files
Merge branch '2.4-develop' into AC10721April24
2 parents d326ac0 + 2e08b17 commit 04ab6f5

File tree

3 files changed

+128
-139
lines changed

3 files changed

+128
-139
lines changed

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

Lines changed: 52 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,13 @@ 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: 'block', count: 2)
113+
]
102114
public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
103115
{
104-
$block1 = $this->blockRepository->getById('enabled_block');
105-
$block2 = $this->blockRepository->getById('fixture_block');
116+
$block1 = $this->fixtures->get('block1');
117+
$block2 = $this->fixtures->get('block2');
106118

107119
$query = $this->getQuery([
108120
$block1->getIdentifier(),
@@ -139,13 +151,12 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest()
139151
);
140152
}
141153

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

150161
$query = $this->getQuery([
151162
$block->getIdentifier(),
@@ -177,13 +188,12 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted()
177188
);
178189
}
179190

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

188198
$query = $this->getQuery([
189199
$block->getIdentifier(),
@@ -217,14 +227,20 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled()
217227
}
218228

219229
/**
220-
* @magentoConfigFixture default_store web/seo/use_rewrites 1
221-
* @magentoDataFixture Magento/Cms/_files/block.php
222-
* @magentoDataFixture Magento/Store/_files/second_store.php
230+
* @throws LocalizedException
231+
* @throws \Zend_Cache_Exception
223232
*/
233+
#[
234+
DataFixture(BlockFixture::class, as: 'block'),
235+
DataFixture(Store::class, as: 'second_store'),
236+
]
224237
public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView()
225238
{
226239
/** @var Block $block */
227-
$block = $this->blockRepository->getById('fixture_block');
240+
$block = $this->fixtures->get('block');
241+
242+
/** @var \Magento\Store\Model\Store $store */
243+
$store = $this->fixtures->get('second_store');
228244

229245
$query = $this->getQuery([
230246
$block->getIdentifier(),
@@ -238,17 +254,17 @@ public function testCmsBlockResolverCacheIsInvalidatedAfterChangingItsStoreView(
238254
$cacheEntryDecoded = json_decode($cacheEntry, true);
239255

240256
$this->assertEqualsCanonicalizing(
241-
$this->generateExpectedDataFromBlocks([$block]),
242-
$cacheEntryDecoded
257+
$cacheEntryDecoded,
258+
$this->generateExpectedDataFromBlocks([$block])
243259
);
244260

245261
$this->assertTagsByCacheIdentityAndBlocks(
246-
$cacheKey,
262+
(string)$cacheKey,
247263
[$block]
248264
);
249265

250266
// assert that cache is invalidated after changing block's store view
251-
$secondStoreViewId = $this->storeManager->getStore('fixture_second_store')->getId();
267+
$secondStoreViewId = $store->getId();
252268
$block->setStoreId($secondStoreViewId);
253269
$this->blockRepository->save($block);
254270

@@ -283,15 +299,14 @@ public function testCmsBlockResolverCacheDoesNotSaveNonExistentCmsBlock()
283299
);
284300
}
285301

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-
*/
302+
#[
303+
Config('system/full_page_cache/caching_application', '2'),
304+
DataFixture(BlockFixture::class, as: 'block', count: 2)
305+
]
291306
public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
292307
{
293308
// query block1
294-
$block1 = $this->blockRepository->getById('fixture_block');
309+
$block1 = $this->fixtures->get('block1');
295310

296311
$queryBlock1 = $this->getQuery([
297312
$block1->getIdentifier(),
@@ -302,7 +317,7 @@ public function testCmsBlockResolverCacheRetainsEntriesThatHaveNotBeenUpdated()
302317
$cacheKeyBlock1 = $this->getResolverCacheKeyFromBlocks([$block1]);
303318

304319
// query block2
305-
$block2 = $this->blockRepository->getById('enabled_block');
320+
$block2 = $this->fixtures->get('block2');
306321

307322
$queryBlock2 = $this->getQuery([
308323
$block2->getIdentifier(),

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

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@
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\TestFramework\Fixture\DataFixture;
24+
use Magento\TestFramework\Fixture\DataFixtureStorage;
25+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1826
use Magento\TestFramework\Helper\Bootstrap;
1927
use Magento\TestFramework\TestCase\GraphQlAbstract;
2028

@@ -61,6 +69,11 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract
6169
*/
6270
private $customerRepository;
6371

72+
/**
73+
* @var DataFixtureStorage
74+
*/
75+
private $fixtures;
76+
6477
protected function setUp(): void
6578
{
6679
$objectManager = Bootstrap::getObjectManager();
@@ -72,6 +85,7 @@ protected function setUp(): void
7285
$this->customerAddressRepository = $objectManager->get(AddressRepositoryInterface::class);
7386
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
7487
$this->customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
88+
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
7589
}
7690

7791
/**
@@ -715,25 +729,45 @@ public function testSetBillingAddressToAnotherCustomerCart()
715729
* Tests that a logged-in customer cannot use a saved customer address that is not their own.
716730
*
717731
* _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-
*
722732
*/
733+
#[
734+
DataFixture(Customer::class, ['addresses' => [['postcode' => '12345']]], as: 'customer', count: 2),
735+
DataFixture(Product::class, as: 'product'),
736+
DataFixture(GuestCart::class, ['customer_email' => '$customer2.email$'], as: 'cart'),
737+
DataFixture(AddProductToCart::class, [
738+
'cart_id' => '$cart.id$',
739+
'product_id' => '$product.id$',
740+
'qty' => 1
741+
])
742+
]
723743
public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
724744
{
725-
$this->expectException(\Exception::class);
726-
$this->expectExceptionMessage('Current customer does not have permission to address with ID "1"');
745+
/** @var \Magento\Customer\Model\Customer $customer1 */
746+
$customer1 = $this->fixtures->get('customer1');
747+
$customer1AddressId = current($customer1->getAddresses())->getId();
748+
$customer2 = $this->fixtures->get('customer2');
749+
$customer2 = $this->customerRepository->getById($customer2->getId());
727750

728-
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2);
751+
/** @var Quote $quote */
752+
$quote = $this->fixtures->get('cart');
753+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
754+
755+
$quote->setCustomer($customer2);
756+
$quote->setCustomerIsGuest(false);
757+
$quote->save();
758+
759+
$this->expectException(\Exception::class);
760+
$this->expectExceptionMessage(
761+
'Current customer does not have permission to address with ID "'.$customer1AddressId.'"'
762+
);
729763

730764
$query = <<<QUERY
731765
mutation {
732766
setBillingAddressOnCart(
733767
input: {
734768
cart_id: "$maskedQuoteId"
735769
billing_address: {
736-
customer_address_id: 1
770+
customer_address_id: "$customer1AddressId"
737771
}
738772
}
739773
) {
@@ -745,7 +779,7 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
745779
}
746780
}
747781
QUERY;
748-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
782+
$this->graphQlMutation($query, [], '', $this->getHeaderMap($customer2->getEmail()));
749783
}
750784

751785
/**

0 commit comments

Comments
 (0)