Skip to content

Commit

Permalink
merge magento/2.3-develop into magento-engcom/graphql-develop-prs
Browse files Browse the repository at this point in the history
  • Loading branch information
Magento CICD authored Oct 3, 2018
2 parents 0f2cafc + 20f1162 commit 5bd6c1c
Show file tree
Hide file tree
Showing 34 changed files with 519 additions and 147 deletions.
13 changes: 9 additions & 4 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements

const CACHE_TAG = 'cat_c';

/**
* Category Store Id
*/
const STORE_ID = 'store_id';

/**#@-*/
protected $_eventPrefix = 'catalog_category';

Expand Down Expand Up @@ -564,12 +569,12 @@ public function getStoreIds()
*
* If store id is underfined for category return current active store id
*
* @return integer
* @return int
*/
public function getStoreId()
{
if ($this->hasData('store_id')) {
return (int)$this->_getData('store_id');
if ($this->hasData(self::STORE_ID)) {
return (int)$this->_getData(self::STORE_ID);
}
return (int)$this->_storeManager->getStore()->getId();
}
Expand All @@ -585,7 +590,7 @@ public function setStoreId($storeId)
if (!is_numeric($storeId)) {
$storeId = $this->_storeManager->getStore($storeId)->getId();
}
$this->setData('store_id', $storeId);
$this->setData(self::STORE_ID, $storeId);
$this->getResource()->setStoreId($storeId);
return $this;
}
Expand Down
65 changes: 43 additions & 22 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,9 @@ protected function _getResource()
}

/**
* Get a list of custom attribute codes that belongs to product attribute set. If attribute set not specified for
* product will return all product attribute codes
* Get a list of custom attribute codes that belongs to product attribute set.
*
* If attribute set not specified for product will return all product attribute codes
*
* @return string[]
*/
Expand All @@ -526,9 +527,9 @@ protected function getCustomAttributesCodes()
public function getStoreId()
{
if ($this->hasData(self::STORE_ID)) {
return $this->getData(self::STORE_ID);
return (int)$this->getData(self::STORE_ID);
}
return $this->_storeManager->getStore()->getId();
return (int)$this->_storeManager->getStore()->getId();
}

/**
Expand Down Expand Up @@ -584,8 +585,9 @@ public function getPrice()
}

/**
* @codeCoverageIgnoreStart
* Get visibility status
*
* @codeCoverageIgnoreStart
* @see \Magento\Catalog\Model\Product\Visibility
*
* @return int
Expand Down Expand Up @@ -662,6 +664,7 @@ public function getStatus()

/**
* Retrieve type instance of the product.
*
* Type instance implements product type depended logic and is a singleton shared by all products of the same type.
*
* @return \Magento\Catalog\Model\Product\Type\AbstractType
Expand Down Expand Up @@ -822,9 +825,10 @@ public function getStoreIds()

/**
* Retrieve product attributes
* if $groupId is null - retrieve all product attributes
*
* @param int $groupId Retrieve attributes of the specified group
* If $groupId is null - retrieve all product attributes
*
* @param int $groupId Retrieve attributes of the specified group
* @param bool $skipSuper Not used
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
Expand Down Expand Up @@ -916,6 +920,7 @@ public function beforeSave()

/**
* Check/set if options can be affected when saving product
*
* If value specified, it will be set.
*
* @param bool $value
Expand Down Expand Up @@ -976,7 +981,7 @@ public function setQty($qty)
*/
public function getQty()
{
return $this->getData('qty');
return (float)$this->getData('qty');
}

/**
Expand Down Expand Up @@ -1036,6 +1041,7 @@ public function reindex()

/**
* Clear cache related with product and protect delete from not admin
*
* Register indexing event before delete product
*
* @return \Magento\Catalog\Model\Product
Expand Down Expand Up @@ -1545,11 +1551,11 @@ public function hasGalleryAttribute()
/**
* Add image to media gallery
*
* @param string $file file path of image in file system
* @param string|array $mediaAttribute code of attribute with type 'media_image',
* leave blank if image should be only in gallery
* @param boolean $move if true, it will move source file
* @param boolean $exclude mark image as disabled in product page view
* @param string $file file path of image in file system
* @param string|array $mediaAttribute code of attribute with type 'media_image',
* leave blank if image should be only in gallery
* @param bool $move if true, it will move source file
* @param bool $exclude mark image as disabled in product page view
* @return \Magento\Catalog\Model\Product
*/
public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
Expand Down Expand Up @@ -1711,6 +1717,7 @@ public function getIsSalable()

/**
* Check is a virtual product
*
* Data helper wrapper
*
* @return bool
Expand Down Expand Up @@ -1803,9 +1810,9 @@ public function formatUrlKey($str)
/**
* Save current attribute with code $code and assign new value
*
* @param string $code Attribute code
* @param mixed $value New attribute value
* @param int $store Store ID
* @param string $code Attribute code
* @param mixed $value New attribute value
* @param int $store Store ID
* @return void
*/
public function addAttributeUpdate($code, $value, $store)
Expand Down Expand Up @@ -1875,6 +1882,7 @@ public function getRequestPath()

/**
* Custom function for other modules
*
* @return string
*/
public function getGiftMessageAvailable()
Expand Down Expand Up @@ -1993,6 +2001,8 @@ public function getOptions()
}

/**
* Set product options
*
* @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface[] $options
* @return $this
*/
Expand All @@ -2016,10 +2026,10 @@ public function getIsVirtual()
/**
* Add custom option information to product
*
* @param string $code Option code
* @param mixed $value Value of the option
* @param int|Product $product Product ID
* @return $this
* @param string $code Option code
* @param mixed $value Value of the option
* @param int|Product $product Product ID
* @return $this
*/
public function addCustomOption($code, $value, $product = null)
{
Expand Down Expand Up @@ -2213,6 +2223,7 @@ public function getPreconfiguredValues()

/**
* Prepare product custom options.
*
* To be sure that all product custom options does not has ID and has product instance
*
* @return \Magento\Catalog\Model\Product
Expand Down Expand Up @@ -2547,7 +2558,7 @@ public function setTypeId($typeId)
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
*/
Expand All @@ -2557,7 +2568,7 @@ public function getExtensionAttributes()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes
* @return $this
Expand All @@ -2570,6 +2581,8 @@ public function setExtensionAttributes(\Magento\Catalog\Api\Data\ProductExtensio
//@codeCoverageIgnoreEnd

/**
* Convert array to media gallery interface
*
* @param array $mediaGallery
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
*/
Expand All @@ -2587,6 +2600,8 @@ protected function convertToMediaGalleryInterface(array $mediaGallery)
}

/**
* Returns media gallery entries
*
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
*/
public function getMediaGalleryEntries()
Expand All @@ -2601,6 +2616,8 @@ public function getMediaGalleryEntries()
}

/**
* Set media gallery entries
*
* @param ProductAttributeMediaGalleryEntryInterface[] $mediaGalleryEntries
* @return $this
*/
Expand Down Expand Up @@ -2643,6 +2660,8 @@ public function setId($value)
}

/**
* Returns link repository instance
*
* @return ProductLinkRepositoryInterface
*/
private function getLinkRepository()
Expand All @@ -2655,6 +2674,8 @@ private function getLinkRepository()
}

/**
* Returns media gallery processor instance
*
* @return Product\Gallery\Processor
*/
private function getMediaGalleryProcessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
*/
define([
'mage/url',
'Magento_Ui/js/model/messageList'
], function (url, globalMessageList) {
'Magento_Ui/js/model/messageList',
'consoleLogger'
], function (url, globalMessageList, consoleLogger) {
'use strict';

return {
Expand All @@ -25,8 +26,12 @@ define([
if (response.status == 401) { //eslint-disable-line eqeqeq
window.location.replace(url.build('customer/account/login/'));
} else {
error = JSON.parse(response.responseText);
messageContainer.addErrorMessage(error);
try {
error = JSON.parse(response.responseText);
messageContainer.addErrorMessage(error);
} catch (e) {
consoleLogger.error(e);
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function process($scope, $scopeCode, $value, $path)
$field = $configStructure->getElementByConfigPath($path);

/** @var Value $backendModel */
$backendModel = $field && $field->hasBackendModel()
$backendModel = $field instanceof Field && $field->hasBackendModel()
? $field->getBackendModel()
: $this->configValueFactory->create();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Cron\Test\Unit\Model\System\Config\Initial;

use Magento\Cron\Model\Groups\Config\Data as GroupsConfigModel;
use Magento\Cron\Model\System\Config\Initial\Converter as ConverterPlugin;
use Magento\Framework\App\Config\Initial\Converter;

/**
* Class ConverterTest
*
* Unit test for \Magento\Cron\Model\System\Config\Initial\Converter
*/
class ConverterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var GroupsConfigModel|\PHPUnit_Framework_MockObject_MockObject
*/
private $groupsConfigMock;

/**
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
*/
private $converterMock;

/**
* @var ConverterPlugin
*/
private $converterPlugin;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->groupsConfigMock = $this->getMockBuilder(
GroupsConfigModel::class
)->disableOriginalConstructor()->getMock();
$this->converterMock = $this->getMockBuilder(Converter::class)->getMock();
$this->converterPlugin = new ConverterPlugin($this->groupsConfigMock);
}

/**
* Tests afterConvert method with no $result['data']['default']['system'] set
*/
public function testAfterConvertWithNoData()
{
$expectedResult = ['test'];
$this->groupsConfigMock->expects($this->never())
->method('get');

$result = $this->converterPlugin->afterConvert($this->converterMock, $expectedResult);

self::assertSame($expectedResult, $result);
}

/**
* Tests afterConvert method with $result['data']['default']['system'] set
*/
public function testAfterConvertWithData()
{
$groups = [
'group1' => ['val1' => ['value' => '1']],
'group2' => ['val2' => ['value' => '2']]
];
$expectedResult['data']['default']['system']['cron'] = [
'group1' => [
'val1' => '1'
],
'group2' => [
'val2' => '2'
]
];
$result['data']['default']['system']['cron'] = '1';

$this->groupsConfigMock->expects($this->once())
->method('get')
->willReturn($groups);

$result = $this->converterPlugin->afterConvert($this->converterMock, $result);

self::assertEquals($expectedResult, $result);
}
}
Loading

0 comments on commit 5bd6c1c

Please sign in to comment.