Skip to content

Commit

Permalink
Merge branch 'project_pepe' of github.com:lfolco/magento2 into projec…
Browse files Browse the repository at this point in the history
…t_pepe
  • Loading branch information
lfolco committed Jan 9, 2020
2 parents 74389d7 + 0ed4e6a commit 5111c05
Show file tree
Hide file tree
Showing 21 changed files with 1,024 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function getFinalPrice();

/**
* Set the final price: usually it calculated as minimal price of the product
*
* Can be different depends on type of product
*
* @param string $finalPrice
Expand All @@ -39,6 +40,7 @@ public function setFinalPrice($finalPrice);

/**
* Retrieve max price of a product
*
* E.g. for product with custom options is price with the most expensive custom option
*
* @return string
Expand All @@ -57,6 +59,7 @@ public function setMaxPrice($maxPrice);

/**
* Retrieve the minimal price of the product or variation
*
* The minimal price is for example, the lowest price of all variations for complex product
*
* @return string
Expand All @@ -66,7 +69,7 @@ public function getMinimalPrice();

/**
* Set max regular price
* Max regular price is the same, as maximum price, except of excluding calculating special price and catalogules
* Max regular price is the same, as maximum price, except of excluding calculating special price and catalog rules
* in it
*
* @param string $maxRegularPrice
Expand Down Expand Up @@ -130,6 +133,7 @@ public function setMinimalPrice($minimalPrice);

/**
* Regular price - is price of product without discounts and special price with taxes and fixed product tax
*
* Usually this price is corresponding to price in admin panel of product
*
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,29 @@ define([
*/
function categoryProductRowClick(grid, event) {
var trElement = Event.findElement(event, 'tr'),
isInput = Event.element(event).tagName === 'INPUT',
eventElement = Event.element(event),
isInputCheckbox = eventElement.tagName === 'INPUT' && eventElement.type === 'checkbox',
isInputPosition = grid.targetElement &&
grid.targetElement.tagName === 'INPUT' &&
grid.targetElement.name === 'position',
checked = false,
checkbox = null;

if (trElement) {
if (eventElement.tagName === 'LABEL' &&
trElement.querySelector('#' + eventElement.htmlFor) &&
trElement.querySelector('#' + eventElement.htmlFor).type === 'checkbox'
) {
event.stopPropagation();
trElement.querySelector('#' + eventElement.htmlFor).trigger('click');

return;
}

if (trElement && !isInputPosition) {
checkbox = Element.getElementsBySelector(trElement, 'input');

if (checkbox[0]) {
checked = isInput ? checkbox[0].checked : !checkbox[0].checked;
checked = isInputCheckbox ? checkbox[0].checked : !checkbox[0].checked;
gridJsObject.setCheckboxChecked(checkbox[0], checked);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Magento\CatalogGraphQl\Model\Resolver\Products\Query;

use GraphQL\Language\AST\SelectionNode;
use Magento\Framework\GraphQl\Query\FieldTranslator;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

Expand Down Expand Up @@ -37,57 +36,18 @@ public function __construct(FieldTranslator $fieldTranslator)
*/
public function getProductsFieldSelection(ResolveInfo $resolveInfo): array
{
return $this->getProductFields($resolveInfo);
}
$productFields = $resolveInfo->getFieldSelection(1);
$sectionNames = ['items', 'product'];

/**
* Return field names for all requested product fields.
*
* @param ResolveInfo $info
* @return string[]
*/
private function getProductFields(ResolveInfo $info): array
{
$fieldNames = [];
foreach ($info->fieldNodes as $node) {
if ($node->name->value !== 'products' && $node->name->value !== 'variants') {
continue;
}
foreach ($node->selectionSet->selections as $selection) {
if ($selection->name->value !== 'items' && $selection->name->value !== 'product') {
continue;
}
$fieldNames[] = $this->collectProductFieldNames($selection, $fieldNames);
}
}
if (!empty($fieldNames)) {
$fieldNames = array_merge(...$fieldNames);
}
return $fieldNames;
}

/**
* Collect field names for each node in selection
*
* @param SelectionNode $selection
* @param array $fieldNames
* @return array
*/
private function collectProductFieldNames(SelectionNode $selection, array $fieldNames = []): array
{
foreach ($selection->selectionSet->selections as $itemSelection) {
if ($itemSelection->kind === 'InlineFragment') {
foreach ($itemSelection->selectionSet->selections as $inlineSelection) {
if ($inlineSelection->kind === 'InlineFragment') {
continue;
}
$fieldNames[] = $this->fieldTranslator->translate($inlineSelection->name->value);
foreach ($sectionNames as $sectionName) {
if (isset($productFields[$sectionName])) {
foreach (array_keys($productFields[$sectionName]) as $fieldName) {
$fieldNames[] = $this->fieldTranslator->translate($fieldName);
}
continue;
}
$fieldNames[] = $this->fieldTranslator->translate($itemSelection->name->value);
}

return $fieldNames;
return array_unique($fieldNames);
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Config/Model/Config/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public function getFieldPathsByAttribute($attributeName, $attributeValue)
foreach ($section['children'] as $group) {
if (isset($group['children'])) {
$path = $section['id'] . '/' . $group['id'];
// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
$result = array_merge(
$result,
$this->_getGroupFieldPathsByAttribute(
Expand Down Expand Up @@ -398,7 +399,7 @@ private function getFieldsRecursively(array $elements = [])
$this->getFieldsRecursively($element['children'])
);
} else {
if ($element['_elementType'] === 'field' && isset($element['label'])) {
if ($element['_elementType'] === 'field') {
$structurePath = (isset($element['path']) ? $element['path'] . '/' : '') . $element['id'];
$configPath = isset($element['config_path']) ? $element['config_path'] : $structurePath;

Expand Down
128 changes: 98 additions & 30 deletions app/code/Magento/Config/Test/Unit/Model/Config/StructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class StructureTest extends \PHPUnit\Framework\TestCase
*/
protected $_structureData;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->_flyweightFactory = $this->getMockBuilder(FlyweightFactory::class)
Expand Down Expand Up @@ -82,7 +85,12 @@ protected function setUp()
);
}

public function testGetTabsBuildsSectionTree()
/**
* Verify tabs build section tree
*
* @return void
*/
public function testGetTabsBuildsSectionTree(): void
{
$expected = ['tab1' => ['children' => ['section1' => ['tab' => 'tab1']]]];

Expand All @@ -108,7 +116,12 @@ public function testGetTabsBuildsSectionTree()
$this->assertEquals($this->_tabIteratorMock, $model->getTabs());
}

public function testGetSectionList()
/**
* Verify get section list method
*
* @return void
*/
public function testGetSectionList(): void
{
$expected = [
'section1_child_id_1' => true,
Expand Down Expand Up @@ -152,6 +165,8 @@ public function testGetSectionList()
}

/**
* Verify Get Element return empty element if element is requested
*
* @param string $path
* @param string $expectedType
* @param string $expectedId
Expand All @@ -174,6 +189,8 @@ public function testGetElementReturnsEmptyElementIfNotExistingElementIsRequested
}

/**
* Verify get Element return empty by path element if not exist
*
* @param string $path
* @param string $expectedType
* @param string $expectedId
Expand All @@ -196,6 +213,8 @@ public function testGetElementReturnsEmptyByConfigPathElementIfNotExistingElemen
}

/**
* Verify Element return e,pty element if not exists
*
* @param string $expectedType
* @param string $expectedId
* @param string $expectedPath
Expand Down Expand Up @@ -234,21 +253,33 @@ public function emptyElementDataProvider()
];
}

public function testGetElementReturnsProperElementByPath()
/**
* Verify get element returns proper element by path
*
* @return void
*/
public function testGetElementReturnsProperElementByPath(): void
{
$elementMock = $this->getElementPathReturnsProperElementByPath();

$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
}

public function testGetElementByConfigPathReturnsProperElementByPath()
/**
* Verify get element by config path return proper path
*
* @return void
*/
public function testGetElementByConfigPathReturnsProperElementByPath(): void
{
$elementMock = $this->getElementPathReturnsProperElementByPath();

$this->assertEquals($elementMock, $this->_model->getElementByConfigPath('section_1/group_level_1/field_3'));
}

/**
* Build mock element
*
* @return Mock
*/
private function getElementPathReturnsProperElementByPath()
Expand All @@ -271,7 +302,12 @@ private function getElementPathReturnsProperElementByPath()
return $elementMock;
}

public function testGetElementByPathPartsIfSectionDataIsEmpty()
/**
* Verefy get element by path part
*
* @return void
*/
public function testGetElementByPathPartsIfSectionDataIsEmpty(): void
{
$fieldData = [
'id' => 'field_3',
Expand Down Expand Up @@ -342,15 +378,25 @@ public function testGetFirstSectionReturnsFirstAllowedSection()
$this->assertEquals('currentSection', $this->_model->getFirstSection()->getData());
}

public function testGetElementReturnsProperElementByPathCachesObject()
/**
* Verify get element return element by path caches object
*
* @return void
*/
public function testGetElementReturnsProperElementByPathCachesObject(): void
{
$elementMock = $this->getElementReturnsProperElementByPathCachesObject();

$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
}

public function testGetElementByConfigPathReturnsProperElementByPathCachesObject()
/**
* Verify Get Element by id returns proper element
*
* @return void
*/
public function testGetElementByConfigPathReturnsProperElementByPathCachesObject(): void
{
$elementMock = $this->getElementReturnsProperElementByPathCachesObject();

Expand Down Expand Up @@ -393,6 +439,8 @@ public function testGetFieldPathsByAttribute($attributeName, $attributeValue, $p
}

/**
* DataProvider
*
* @return array
*/
public function getFieldPathsByAttributeDataProvider()
Expand All @@ -411,33 +459,53 @@ public function getFieldPathsByAttributeDataProvider()
];
}

public function testGetFieldPaths()
/**
* Verify get Fields paths method
*
* @dataProvider getFieldPaths
* @param array $expected
* @return void
*/
public function testGetFieldPaths(array $expected): void
{
$expected = [
'section/group/field2' => [
'field_2'
],
'field_3' => [
'field_3',
'field_3'
],
'field_3_1' => [
'field_3_1'
],
'field_3_1_1' => [
'field_3_1_1'
],
'section/group/field4' => [
'field_4',
],
'field_5' => [
'field_5',
],
];

$this->assertSame(
$expected,
$this->_model->getFieldPaths()
);
}

/**
* dataprovider for Field Paths
*
* @return array
*/
public function getFieldPaths(): array
{
return [
[
[
'section/group/field2' => [
'field_2'
],
'field_3' => [
'field_3',
'field_3'
],
'field_3_1' => [
'field_3_1'
],
'field_3_1_1' => [
'field_3_1_1'
],
'section/group/field4' => [
'field_4',
],
'field_5' => [
'field_5',
'field_5'
]
]
]
];
}
}
Loading

0 comments on commit 5111c05

Please sign in to comment.