Skip to content

Commit

Permalink
Merge pull request #1248 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests

#10052
#9992
#9726
#9754
#9611
#9363
  • Loading branch information
Oleksii Korshenko authored Jun 29, 2017
2 parents 3eb0183 + 2de5e40 commit c350871
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 49 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class EditorTest extends \PHPUnit_Framework_TestCase
*/
protected $objectManager;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $serializer;

protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand All @@ -62,13 +67,16 @@ protected function setUp()
$this->escaperMock = $this->getMock(\Magento\Framework\Escaper::class, [], [], '', false);
$this->configMock = $this->getMock(\Magento\Framework\DataObject::class, ['getData'], [], '', false);

$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);

$this->model = $this->objectManager->getObject(
\Magento\Framework\Data\Form\Element\Editor::class,
[
'factoryElement' => $this->factoryMock,
'factoryCollection' => $this->collectionFactoryMock,
'escaper' => $this->escaperMock,
'data' => ['config' => $this->configMock]
'data' => ['config' => $this->configMock],
'serializer' => $this->serializer
]
);

Expand Down Expand Up @@ -202,8 +210,17 @@ public function testGetConfig()
*/
public function testGetTranslatedString()
{
$callback = function ($params) {
return json_encode($params);
};

$this->configMock->expects($this->any())->method('getData')->withConsecutive(['enabled'])->willReturn(true);
$this->serializer->expects($this->any())
->method('serialize')
->willReturnCallback($callback);

$html = $this->model->getElementHtml();

$this->assertRegExp('/.*"Insert Image...":"Insert Image...".*/i', $html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ abstract class AbstractAggregateException extends LocalizedException
*
* @param \Magento\Framework\Phrase $phrase
* @param \Exception $cause
* @param int $code
*/
public function __construct(Phrase $phrase, \Exception $cause = null)
public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0)
{
$this->originalPhrase = $phrase;
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class AlreadyExistsException extends LocalizedException
/**
* @param 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('Unique constraint violation found');
}
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
}
}
Loading

0 comments on commit c350871

Please sign in to comment.