Skip to content

Commit

Permalink
MAGETWO-70325: Merge branch 'develop' of github.com:magento/magento2c…
Browse files Browse the repository at this point in the history
…e into MAGETWO-70325-PR-4147
  • Loading branch information
ishakhsuvarov committed Jun 30, 2017
2 parents 8e01016 + c350871 commit a02001f
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,16 @@ public function getGridIdsJson()
if (!$this->getUseSelectAll()) {
return '';
}

/** @var \Magento\Framework\Data\Collection $allIdsCollection */
$allIdsCollection = clone $this->getParentBlock()->getCollection();
$gridIds = $allIdsCollection->clear()->setPageSize(0)->getAllIds();


if ($this->getMassactionIdField()) {
$massActionIdField = $this->getMassactionIdField();
} else {
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
}

$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
if (!empty($gridIds)) {
return join(",", $gridIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,14 @@ public function getGridIdsJson()

/** @var \Magento\Framework\Data\Collection $allIdsCollection */
$allIdsCollection = clone $this->getParentBlock()->getCollection();
$gridIds = $allIdsCollection->clear()->setPageSize(0)->getAllIds();

if ($this->getMassactionIdField()) {
$massActionIdField = $this->getMassactionIdField();
} else {
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
}

$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);

if (!empty($gridIds)) {
return join(",", $gridIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
{
$this->_block->setUseSelectAll(true);


if ($this->_block->getMassactionIdField()) {
$massActionIdField = $this->_block->getMassactionIdField();
} else {
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
}

$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -141,15 +147,13 @@ public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
->method('getCollection')
->willReturn($collectionMock);

$collectionMock->expects($this->once())
->method('clear')
->willReturnSelf();
$collectionMock->expects($this->once())
->method('setPageSize')
->with(0)
->willReturnSelf();
$collectionMock->expects($this->once())
->method('getAllIds')
->method('getColumnValues')
->with($massActionIdField)
->willReturn($items);

$this->assertEquals($result, $this->_block->getGridIdsJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
{
$this->_block->setUseSelectAll(true);

if ($this->_block->getMassactionIdField()) {
$massActionIdField = $this->_block->getMassactionIdField();
} else {
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
}

$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
Expand All @@ -245,16 +251,13 @@ public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
$this->_gridMock->expects($this->once())
->method('getCollection')
->willReturn($collectionMock);

$collectionMock->expects($this->once())
->method('clear')
->willReturnSelf();
$collectionMock->expects($this->once())
->method('setPageSize')
->with(0)
->willReturnSelf();
$collectionMock->expects($this->once())
->method('getAllIds')
->method('getColumnValues')
->with($massActionIdField)
->willReturn($items);

$this->assertEquals($result, $this->_block->getGridIdsJson());
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Catalog/Block/Product/AbstractProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class AbstractProduct extends \Magento\Framework\View\Element\Template
*/
protected $stockRegistry;

/**
* @var ImageBuilder
*/
protected $imageBuilder;

/**
* @param Context $context
* @param array $data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ protected function isValidOptionPrice($priceType, $price, $storeId)
if ($storeId > \Magento\Store\Model\Store::DEFAULT_STORE_ID && $priceType === null && $price === null) {
return true;
}
if (!$priceType && !$price) {
return true;
}
if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,45 @@ protected function setUp()
}

/**
* @param bool $expectedResult
* @param array $value
* @dataProvider isValidSuccessDataProvider
*/
public function testIsValidSuccess($value)
public function testIsValidSuccess($expectedResult, array $value)
{
$value = [
'price_type' => 'fixed',
'price' => '10',
'title' => 'Some Title',
];
$this->valueMock->expects($this->once())->method('getTitle')->will($this->returnValue('option_title'));
$this->valueMock->expects($this->exactly(2))->method('getType')->will($this->returnValue('name 1.1'));
$this->valueMock->expects($this->never())->method('getPriceType');
$this->valueMock->expects($this->never())->method('getPrice');
$this->valueMock->expects($this->any())->method('getData')->with('values')->will($this->returnValue([$value]));
$this->assertTrue($this->validator->isValid($this->valueMock));
$this->assertEmpty($this->validator->getMessages());
$this->assertEquals($expectedResult, $this->validator->isValid($this->valueMock));
}

public function isValidSuccessDataProvider()
{
$value = [
'price_type' => 'fixed',
'price' => '10',
'title' => 'Some Title',
];

$valueWithoutAllData = [
'some_data' => 'data',
];

return [
'all_data' => [$value],
'not_all_data' => [$valueWithoutAllData]
[
true,
[
'price_type' => 'fixed',
'price' => '10',
'title' => 'Some Title',
]
],
[
true,
[
'title' => 'Some Title',
]
],
[
false,
[
'title' => 'Some Title',
'price_type' => 'fixed',
'price' => -10,
]
],
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Paypal/Model/Api/ProcessableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ProcessableException extends LocalizedException
*/
public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0)
{
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
$this->code = $code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ class MergeConflictException extends LocalizedException
* @param array $conflictingSynonyms
* @param Phrase|null $phrase
* @param \Exception|null $cause
* @param int $code
*/
public function __construct(array $conflictingSynonyms, Phrase $phrase = null, \Exception $cause = null)
public function __construct(array $conflictingSynonyms, Phrase $phrase = null, \Exception $cause = null, $code = 0)
{
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
$this->conflictingSynonyms = $conflictingSynonyms;
}

Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Store/Model/StoreIsInactiveException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class StoreIsInactiveException extends LocalizedException
/**
* @param \Magento\Framework\Phrase $phrase
* @param \Exception $cause
* @param int $code
*/
public function __construct(Phrase $phrase = null, \Exception $cause = null)
public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0)
{
if ($phrase === null) {
$phrase = new Phrase('Store is inactive');
}
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public function getConnectionName($resourceName)
{
$this->initConnections();
$connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;

$resourceName = preg_replace("/_setup$/", '', $resourceName);


if (!isset($this->_connectionNames[$resourceName])) {
$resourcesConfig = $this->get();
$pointerResourceName = $resourceName;
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/Magento/Framework/Config/etc/view.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
<xs:complexType name="mediaType" mixed="true">
<xs:all>
<xs:element name="images" type="imageType" minOccurs="0"/>
<xs:element name="videos" type="videoType" minOccurs="0"/>
</xs:all>
<xs:sequence>
<xs:element name="images" type="imageType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="videos" type="videoType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="imageType">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,36 @@
*/
namespace Magento\Framework\Data\Form\Element;

use Magento\Framework\Escaper;

class Editablemultiselect extends \Magento\Framework\Data\Form\Element\Multiselect
{
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Editablemultiselect constructor.
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
* Name of the default JavaScript class that is used to make multiselect editable
*
Expand All @@ -26,6 +54,7 @@ class Editablemultiselect extends \Magento\Framework\Data\Form\Element\Multisele
* Retrieve HTML markup of the element
*
* @return string
* @throws \InvalidArgumentException
*/
public function getElementHtml()
{
Expand All @@ -41,7 +70,7 @@ public function getElementHtml()
$elementJsClass = $this->getData('element_js_class');
}

$selectConfigJson = \Zend_Json::encode($selectConfig);
$selectConfigJson = $this->serializer->serialize($selectConfig);
$jsObjectName = $this->getJsObjectName();

// TODO: TaxRateEditableMultiselect should be moved to a static .js module.
Expand Down
36 changes: 30 additions & 6 deletions lib/internal/Magento/Framework/Data/Form/Element/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@
class Editor extends Textarea
{
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Editor constructor.
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
$data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);

Expand All @@ -36,6 +45,8 @@ public function __construct(
$this->setType('textarea');
$this->setExtType('textarea');
}
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
Expand All @@ -52,6 +63,21 @@ protected function getButtonTranslations()
return $buttonTranslations;
}

/**
* @return bool|string
* @throws \InvalidArgumentException
*/
private function getJsonConfig()
{
if (is_object($this->getConfig()) && method_exists($this->getConfig(), 'toJson')) {
return $this->getConfig()->toJson();
} else {
return $this->serializer->serialize(
$this->getConfig()
);
}
}

/**
* @return string
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down Expand Up @@ -132,7 +158,7 @@ public function getElementHtml()
], function(jQuery){' .
"\n" .
' (function($) {$.mage.translate.add(' .
\Zend_Json::encode(
$this->serializer->serialize(
$this->getButtonTranslations()
) .
')})(jQuery);' .
Expand All @@ -141,9 +167,7 @@ public function getElementHtml()
' = new tinyMceWysiwygSetup("' .
$this->getHtmlId() .
'", ' .
\Zend_Json::encode(
$this->getConfig()
) .
$this->getJsonConfig() .
');' .
$forceLoad .
'
Expand Down Expand Up @@ -180,7 +204,7 @@ public function getElementHtml()
//<![CDATA[
require(["jquery", "mage/translate", "mage/adminhtml/wysiwyg/widget"], function(jQuery){
(function($) {
$.mage.translate.add(' . \Zend_Json::encode($this->getButtonTranslations()) . ')
$.mage.translate.add(' . $this->serializer->serialize($this->getButtonTranslations()) . ')
})(jQuery);
});
//]]>
Expand Down
Loading

0 comments on commit a02001f

Please sign in to comment.