Skip to content

Commit ad31951

Browse files
merge magento/2.3-qwerty into magento-qwerty/2.3-bugfixes-230119
2 parents 40952c3 + 49ceb88 commit ad31951

File tree

13 files changed

+185
-141
lines changed

13 files changed

+185
-141
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,11 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato
101101

102102
$collection->addFieldToFilter('level', ['gt' => $level]);
103103
$collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]);
104-
$collection->addIsActiveFilter();
105104
$collection->setOrder('level');
106-
$collection->setOrder(
107-
'position',
108-
$collection::SORT_ORDER_DESC
109-
);
110105
$collection->getSelect()->orWhere(
111-
$collection->getSelect()
112-
->getConnection()
113-
->quoteIdentifier(
114-
'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField()
115-
) . ' = ?',
106+
$this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?',
116107
$rootCategoryId
117108
);
118-
119109
return $collection->getIterator();
120110
}
121111

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ class ExtractDataFromCategoryTree
2020
*/
2121
private $categoryHydrator;
2222

23-
/**
24-
* @var CategoryInterface;
25-
*/
26-
private $iteratingCategory;
27-
28-
/**
29-
* @var int
30-
*/
31-
private $startCategoryFetchLevel = 1;
32-
3323
/**
3424
* @param Hydrator $categoryHydrator
3525
*/
@@ -52,63 +42,14 @@ public function execute(\Iterator $iterator): array
5242
/** @var CategoryInterface $category */
5343
$category = $iterator->current();
5444
$iterator->next();
55-
56-
$pathElements = explode("/", $category->getPath());
57-
if (empty($tree)) {
58-
$this->startCategoryFetchLevel = count($pathElements) - 1;
45+
$nextCategory = $iterator->current();
46+
$tree[$category->getId()] = $this->categoryHydrator->hydrateCategory($category);
47+
$tree[$category->getId()]['model'] = $category;
48+
if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) {
49+
$tree[$category->getId()]['children'] = $this->execute($iterator);
5950
}
60-
61-
$this->iteratingCategory = $category;
62-
$currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel);
63-
if (empty($tree)) {
64-
$tree = $currentLevelTree;
65-
}
66-
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
6751
}
6852

6953
return $tree;
7054
}
71-
72-
/**
73-
* Merge together complex categories trees
74-
*
75-
* @param array $tree1
76-
* @param array $tree2
77-
* @return array
78-
*/
79-
private function mergeCategoriesTrees(array &$tree1, array &$tree2): array
80-
{
81-
$mergedTree = $tree1;
82-
foreach ($tree2 as $currentKey => &$value) {
83-
if (is_array($value) && isset($mergedTree[$currentKey]) && is_array($mergedTree[$currentKey])) {
84-
$mergedTree[$currentKey] = $this->mergeCategoriesTrees($mergedTree[$currentKey], $value);
85-
} else {
86-
$mergedTree[$currentKey] = $value;
87-
}
88-
}
89-
return $mergedTree;
90-
}
91-
92-
/**
93-
* Recursive method to generate tree for one category path
94-
*
95-
* @param array $pathElements
96-
* @param int $index
97-
* @return array
98-
*/
99-
private function explodePathToArray(array $pathElements, int $index): array
100-
{
101-
$tree = [];
102-
$tree[$pathElements[$index]]['id'] = $pathElements[$index];
103-
if ($index === count($pathElements) - 1) {
104-
$tree[$pathElements[$index]] = $this->categoryHydrator->hydrateCategory($this->iteratingCategory);
105-
$tree[$pathElements[$index]]['model'] = $this->iteratingCategory;
106-
}
107-
$currentIndex = $index;
108-
$index++;
109-
if (isset($pathElements[$index])) {
110-
$tree[$pathElements[$currentIndex]]['children'] = $this->explodePathToArray($pathElements, $index);
111-
}
112-
return $tree;
113-
}
11455
}

app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerAddress.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ private function updateCustomerAddress(int $customerId, int $addressId, array $a
109109
{
110110
$address = $this->getCustomerAddressForUser->execute($addressId, $customerId);
111111
$this->dataObjectHelper->populateWithArray($address, $addressData, AddressInterface::class);
112-
if (isset($addressData['region']['region_id'])) {
113-
$address->setRegionId($address->getRegion()->getRegionId());
114-
}
115-
116112
return $this->addressRepository->save($address);
117113
}
118114
}

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type Query {
55
}
66

77
type Mutation {
8+
placeholderMutation: String @doc(description: "Mutation type cannot be declared without fields. The placeholder will be removed when at least one mutation field is declared.")
89
}
910

1011
input FilterTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {

app/code/Magento/StoreGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Query {
66

77
type Website @doc(description: "The type contains information about a website") {
88
id : Int @doc(description: "The ID number assigned to the website")
9-
name : String @doc(description: "The website name. Websites use this name to identify it easier.")
9+
name : String @doc(description: "The website name. Websites use this name to identify it easyer.")
1010
code : String @doc(description: "A code assigned to the website to identify it")
1111
sort_order : Int @doc(description: "The attribute to use for sorting websites")
12-
default_group_id : String @doc(description: "The default group ID that the website has")
12+
default_group_id : String @doc(description: "The default group id that the website has")
1313
is_default : Boolean @doc(description: "Specifies if this is the default website")
1414
}
1515

app/code/Magento/Wishlist/Model/Rss/Wishlist.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ public function __construct(
118118
*/
119119
public function isAllowed()
120120
{
121-
return $this->scopeConfig->isSetFlag(
122-
'rss/wishlist/active',
123-
ScopeInterface::SCOPE_STORE
124-
);
121+
return $this->scopeConfig->isSetFlag('rss/wishlist/active', ScopeInterface::SCOPE_STORE)
122+
&& $this->getWishlist()->getCustomerId() === $this->wishlistHelper->getCustomer()->getId();
125123
}
126124

127125
/**
@@ -185,8 +183,8 @@ public function getRssData()
185183
}
186184
} else {
187185
$data = [
188-
'title' => __('We cannot retrieve the Wish List.'),
189-
'description' => __('We cannot retrieve the Wish List.'),
186+
'title' => __('We cannot retrieve the Wish List.')->render(),
187+
'description' => __('We cannot retrieve the Wish List.')->render(),
190188
'link' => $this->urlBuilder->getUrl(),
191189
'charset' => 'UTF-8',
192190
];
@@ -202,7 +200,7 @@ public function getRssData()
202200
*/
203201
public function getCacheKey()
204202
{
205-
return 'rss_wishlist_data';
203+
return 'rss_wishlist_data_' . $this->getWishlist()->getId();
206204
}
207205

208206
/**
@@ -224,7 +222,7 @@ public function getHeader()
224222
{
225223
$customerId = $this->getWishlist()->getCustomerId();
226224
$customer = $this->customerFactory->create()->load($customerId);
227-
$title = __('%1\'s Wishlist', $customer->getName());
225+
$title = __('%1\'s Wishlist', $customer->getName())->render();
228226
$newUrl = $this->urlBuilder->getUrl(
229227
'wishlist/shared/index',
230228
['code' => $this->getWishlist()->getSharingCode()]

app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,35 @@ protected function processWishlistItemDescription($wishlistModelMock, $staticArg
278278

279279
public function testIsAllowed()
280280
{
281+
$customerId = 1;
282+
$customerServiceMock = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
283+
$wishlist = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class)->setMethods(
284+
['getId', '__wakeup', 'getCustomerId', 'getItemCollection', 'getSharingCode']
285+
)->disableOriginalConstructor()->getMock();
286+
$wishlist->expects($this->once())->method('getCustomerId')->willReturn($customerId);
287+
$this->wishlistHelperMock->expects($this->any())->method('getWishlist')
288+
->will($this->returnValue($wishlist));
289+
$this->wishlistHelperMock->expects($this->any())
290+
->method('getCustomer')
291+
->will($this->returnValue($customerServiceMock));
292+
$customerServiceMock->expects($this->once())->method('getId')->willReturn($customerId);
281293
$this->scopeConfig->expects($this->once())->method('isSetFlag')
282294
->with('rss/wishlist/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
283295
->will($this->returnValue(true));
296+
284297
$this->assertTrue($this->model->isAllowed());
285298
}
286299

287300
public function testGetCacheKey()
288301
{
289-
$this->assertEquals('rss_wishlist_data', $this->model->getCacheKey());
302+
$wishlistId = 1;
303+
$wishlist = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class)->setMethods(
304+
['getId', '__wakeup', 'getCustomerId', 'getItemCollection', 'getSharingCode']
305+
)->disableOriginalConstructor()->getMock();
306+
$wishlist->expects($this->once())->method('getId')->willReturn($wishlistId);
307+
$this->wishlistHelperMock->expects($this->any())->method('getWishlist')
308+
->will($this->returnValue($wishlist));
309+
$this->assertEquals('rss_wishlist_data_1', $this->model->getCacheKey());
290310
}
291311

292312
public function testGetCacheLifetime()

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public function testCategoriesTree()
8383
$responseDataObject = new DataObject($response);
8484
//Some sort of smoke testing
8585
self::assertEquals(
86-
'Its a description of Test Category 1.2',
87-
$responseDataObject->getData('category/children/0/children/1/description')
86+
'Ololo',
87+
$responseDataObject->getData('category/children/7/children/1/description')
8888
);
8989
self::assertEquals(
9090
'default-category',
@@ -99,54 +99,16 @@ public function testCategoriesTree()
9999
$responseDataObject->getData('category/children/0/default_sort_by')
100100
);
101101
self::assertCount(
102-
7,
102+
8,
103103
$responseDataObject->getData('category/children')
104104
);
105105
self::assertCount(
106106
2,
107-
$responseDataObject->getData('category/children/0/children')
107+
$responseDataObject->getData('category/children/7/children')
108108
);
109109
self::assertEquals(
110-
13,
111-
$responseDataObject->getData('category/children/0/children/1/id')
112-
);
113-
}
114-
115-
/**
116-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
117-
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
118-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
119-
*/
120-
public function testGetCategoryById()
121-
{
122-
$rootCategoryId = 13;
123-
$query = <<<QUERY
124-
{
125-
category(id: {$rootCategoryId}) {
126-
id
127-
name
128-
}
129-
}
130-
QUERY;
131-
132-
// get customer ID token
133-
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
134-
$customerTokenService = $this->objectManager->create(
135-
\Magento\Integration\Api\CustomerTokenServiceInterface::class
136-
);
137-
$customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
138-
139-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
140-
$response = $this->graphQlQuery($query, [], '', $headerMap);
141-
$responseDataObject = new DataObject($response);
142-
//Some sort of smoke testing
143-
self::assertEquals(
144-
'Category 1.2',
145-
$responseDataObject->getData('category/name')
146-
);
147-
self::assertEquals(
148-
13,
149-
$responseDataObject->getData('category/id')
110+
5,
111+
$responseDataObject->getData('category/children/7/children/1/children/0/id')
150112
);
151113
}
152114

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ private function assertCustomerAddressesFields(AddressInterface $address, $actua
218218
];
219219
$this->assertResponseFields($actualResponse, $assertionMap);
220220
$this->assertTrue(is_array([$actualResponse['region']]), "region field must be of an array type.");
221-
$assertionRegionMap = [
222-
['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
223-
['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
224-
['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
225-
];
226-
$this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
221+
// https://github.com/magento/graphql-ce/issues/270
222+
// $assertionRegionMap = [
223+
// ['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
224+
// ['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
225+
// ['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
226+
// ];
227+
// $this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
227228
}
228229

229230
/**

dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
->setParentId(3)
179179
->setPath('1/2/3/13')
180180
->setLevel(3)
181-
->setDescription('Its a description of Test Category 1.2')
181+
->setDescription('Ololo')
182182
->setAvailableSortBy('name')
183183
->setDefaultSortBy('name')
184184
->setIsActive(true)

0 commit comments

Comments
 (0)