Skip to content

Commit b180d87

Browse files
author
Oleksii Korshenko
authored
Merge pull request #858 from magento-engcom/develop-prs
Public Pull Requests #8505 #8467 #8617
2 parents c7fff61 + c74b6b7 commit b180d87

File tree

12 files changed

+222
-62
lines changed

12 files changed

+222
-62
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ addons:
99
- postfix
1010
language: php
1111
php:
12-
- 5.6
12+
- 5.6.29
1313
- 7.0
1414
env:
1515
global:

app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ protected function setUp()
5353
*/
5454
public function testGetCaptcha()
5555
{
56-
if (!function_exists("imageftbbox")) {
57-
$this->markTestSkipped('imageftbbox is not available on the test environment');
58-
}
59-
6056
$this->configMock->expects(
6157
$this->once()
6258
)->method(

app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ class DefaultTest extends \PHPUnit_Framework_TestCase
8888
*/
8989
protected function setUp()
9090
{
91-
if (!function_exists("imageftbbox")) {
92-
$this->markTestSkipped('imageftbbox is not available on the test environment');
93-
}
9491
$this->session = $this->_getSessionStub();
9592

9693
$this->_storeManager = $this->getMock(

app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,21 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type)
4848
$products = $this->providers[$type]->getLinkedProducts($product);
4949
$converter = $this->converterPool->getConverter($type);
5050
$output = [];
51+
$sorterItems = [];
5152
foreach ($products as $item) {
5253
$output[$item->getId()] = $converter->convert($item);
5354
}
54-
return $output;
55+
56+
foreach ($output as $item) {
57+
$itemPosition = $item['position'];
58+
if (!isset($sorterItems[$itemPosition])) {
59+
$sorterItems[$itemPosition] = $item;
60+
} else {
61+
$newPosition = $itemPosition + 1;
62+
$sorterItems[$newPosition] = $item;
63+
}
64+
}
65+
ksort($sorterItems);
66+
return $sorterItems;
5567
}
5668
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model;
8+
9+
use Magento\Catalog\Model\ProductLink\CollectionProvider;
10+
use Magento\Catalog\Model\ProductLink\CollectionProviderInterface;
11+
use Magento\Catalog\Model\ProductLink\Converter\ConverterInterface;
12+
use Magento\Catalog\Model\ProductLink\Converter\ConverterPool;
13+
use Magento\Catalog\Model\Product;
14+
15+
class CollectionProviderTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var CollectionProvider
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var \PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $converterPoolMock;
26+
27+
/**
28+
* @var \PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $providerMock;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $productMock;
36+
37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $converterMock;
41+
42+
protected function setUp()
43+
{
44+
$this->productMock = $this->getMock(Product::class, [], [], '', false, false);
45+
$this->converterPoolMock = $this->getMock(ConverterPool::class, [], [], '', false, false);
46+
$this->providerMock = $this->getMock(CollectionProviderInterface::class);
47+
$this->converterMock = $this->getMock(ConverterInterface::class);
48+
49+
$this->model = new CollectionProvider($this->converterPoolMock, ['crosssell' => $this->providerMock]);
50+
}
51+
52+
/**
53+
* Test sort order of linked products based on configured item position.
54+
*/
55+
public function testGetCollection()
56+
{
57+
$linkedProductOneMock = $this->getMock(Product::class, [], [], '', false, false);
58+
$linkedProductTwoMock = $this->getMock(Product::class, [], [], '', false, false);
59+
$linkedProductThreeMock = $this->getMock(Product::class, [], [], '', false, false);
60+
61+
$linkedProductOneMock->expects($this->once())->method('getId')->willReturn(1);
62+
$linkedProductTwoMock->expects($this->once())->method('getId')->willReturn(2);
63+
$linkedProductThreeMock->expects($this->once())->method('getId')->willReturn(3);
64+
65+
$this->converterPoolMock->expects($this->once())
66+
->method('getConverter')
67+
->with('crosssell')
68+
->willReturn($this->converterMock);
69+
70+
$map = [
71+
[$linkedProductOneMock, ['name' => 'Product One', 'position' => 10]],
72+
[$linkedProductTwoMock, ['name' => 'Product Two', 'position' => 2]],
73+
[$linkedProductThreeMock, ['name' => 'Product Three', 'position' => 2]],
74+
];
75+
76+
$this->converterMock->expects($this->exactly(3))->method('convert')->willReturnMap($map);
77+
78+
$this->providerMock->expects($this->once())
79+
->method('getLinkedProducts')
80+
->with($this->productMock)
81+
->willReturn(
82+
[
83+
$linkedProductOneMock,
84+
$linkedProductTwoMock,
85+
$linkedProductThreeMock
86+
]
87+
);
88+
89+
$expectedResult = [
90+
2 => ['name' => 'Product Two', 'position' => 2],
91+
3 => ['name' => 'Product Three', 'position' => 2],
92+
10 => ['name' => 'Product One', 'position' => 10],
93+
];
94+
95+
$actualResult = $this->model->getCollection($this->productMock, 'crosssell');
96+
97+
$this->assertEquals($expectedResult, $actualResult, 'Sort order of linked products in incorrect');
98+
}
99+
100+
/**
101+
* Test exception when collection provider is not configured for product link type.
102+
*
103+
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
104+
* @expectedExceptionMessage Collection provider is not registered
105+
*/
106+
public function testGetCollectionWithMissingProviders()
107+
{
108+
$this->model->getCollection($this->productMock, 'upsell');
109+
}
110+
}

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,30 @@ class Tree extends \Magento\Backend\Block\Template
2626
*/
2727
protected $_cmsWysiwygImages = null;
2828

29+
/**
30+
* @var \Magento\Framework\Serialize\Serializer\Json
31+
*/
32+
private $serializer;
33+
2934
/**
3035
* @param \Magento\Backend\Block\Template\Context $context
3136
* @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages
3237
* @param \Magento\Framework\Registry $registry
3338
* @param array $data
39+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
40+
* @throws \RuntimeException
3441
*/
3542
public function __construct(
3643
\Magento\Backend\Block\Template\Context $context,
3744
\Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages,
3845
\Magento\Framework\Registry $registry,
39-
array $data = []
46+
array $data = [],
47+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4048
) {
4149
$this->_coreRegistry = $registry;
4250
$this->_cmsWysiwygImages = $cmsWysiwygImages;
51+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
52+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
4353
parent::__construct($context, $data);
4454
}
4555

@@ -65,7 +75,7 @@ public function getTreeJson()
6575
'cls' => 'folder',
6676
];
6777
}
68-
return \Zend_Json::encode($jsonArray);
78+
return $this->serializer->serialize($jsonArray);
6979
}
7080

7181
/**

app/code/Magento/Customer/Block/Account/AuthenticationPopup.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,34 @@ class AuthenticationPopup extends \Magento\Framework\View\Element\Template
1515
*/
1616
protected $jsLayout;
1717

18+
/**
19+
* @var \Magento\Framework\Serialize\Serializer\Json
20+
*/
21+
private $serializer;
22+
1823
/**
1924
* @param \Magento\Framework\View\Element\Template\Context $context
2025
* @param array $data
26+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
27+
* @throws \RuntimeException
2128
*/
2229
public function __construct(
2330
\Magento\Framework\View\Element\Template\Context $context,
24-
array $data = []
31+
array $data = [],
32+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
2533
) {
2634
parent::__construct($context, $data);
2735
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
36+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
37+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
2838
}
2939

3040
/**
3141
* @return string
3242
*/
3343
public function getJsLayout()
3444
{
35-
return \Zend_Json::encode($this->jsLayout);
45+
return $this->serializer->serialize($this->jsLayout);
3646
}
3747

3848
/**
@@ -50,6 +60,18 @@ public function getConfig()
5060
];
5161
}
5262

63+
/**
64+
* Returns popup config in JSON format.
65+
*
66+
* Added in scope of https://github.com/magento/magento2/pull/8617
67+
*
68+
* @return bool|string
69+
*/
70+
public function getSerializedConfig()
71+
{
72+
return $this->serializer->serialize($this->getConfig());
73+
}
74+
5375
/**
5476
* Is autocomplete enabled for storefront
5577
*

app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php

+57-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase
3131
/** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
3232
private $urlBuilderMock;
3333

34+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
35+
private $serializerMock;
36+
3437
protected function setUp()
3538
{
3639
$this->contextMock = $this->getMockBuilder(Context::class)
@@ -72,8 +75,13 @@ function ($string) {
7275
->method('getEscaper')
7376
->willReturn($escaperMock);
7477

78+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
79+
->getMock();
80+
7581
$this->model = new AuthenticationPopup(
76-
$this->contextMock
82+
$this->contextMock,
83+
[],
84+
$this->serializerMock
7785
);
7886
}
7987

@@ -83,6 +91,7 @@ function ($string) {
8391
* @param string $registerUrl
8492
* @param string $forgotUrl
8593
* @param array $result
94+
* @throws \PHPUnit_Framework_Exception
8695
*
8796
* @dataProvider dataProviderGetConfig
8897
*/
@@ -172,4 +181,51 @@ public function dataProviderGetConfig()
172181
],
173182
];
174183
}
184+
185+
/**
186+
* @param mixed $isAutocomplete
187+
* @param string $baseUrl
188+
* @param string $registerUrl
189+
* @param string $forgotUrl
190+
* @param array $result
191+
* @throws \PHPUnit_Framework_Exception
192+
*
193+
* @dataProvider dataProviderGetConfig
194+
*/
195+
public function testGetSerializedConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result)
196+
{
197+
$this->scopeConfigMock->expects($this->any())
198+
->method('getValue')
199+
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
200+
->willReturn($isAutocomplete);
201+
202+
/** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */
203+
$storeMock = $this->getMockBuilder(StoreInterface::class)
204+
->setMethods(['getBaseUrl'])
205+
->getMockForAbstractClass();
206+
207+
$this->storeManagerMock->expects($this->any())
208+
->method('getStore')
209+
->with(null)
210+
->willReturn($storeMock);
211+
212+
$storeMock->expects($this->any())
213+
->method('getBaseUrl')
214+
->willReturn($baseUrl);
215+
216+
$this->urlBuilderMock->expects($this->any())
217+
->method('getUrl')
218+
->willReturnMap(
219+
[
220+
['customer/account/create', [], $registerUrl],
221+
['customer/account/forgotpassword', [], $forgotUrl],
222+
]
223+
);
224+
$this->serializerMock->expects($this->any())->method('serialize')
225+
->willReturn(
226+
json_encode($this->model->getConfig())
227+
);
228+
229+
$this->assertEquals(json_encode($result), $this->model->getSerializedConfig());
230+
}
175231
}

app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
?>
1111
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'" style="display: none;">
1212
<script>
13-
window.authenticationPopup = <?php /* @noEscape */ echo \Zend_Json::encode($block->getConfig()); ?>;
13+
window.authenticationPopup = <?php /* @noEscape */ echo $block->getSerializedConfig(); ?>;
1414
</script>
1515
<!-- ko template: getTemplate() --><!-- /ko -->
1616
<script type="text/x-magento-init">

dev/tests/integration/etc/di/preferences/ce.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
\Magento\Framework\App\ResourceConnection\ConnectionAdapterInterface::class =>
2323
\Magento\TestFramework\Db\ConnectionAdapter::class,
2424
\Magento\Framework\Filesystem\DriverInterface::class => \Magento\Framework\Filesystem\Driver\File::class,
25-
\Magento\Framework\App\Config\ScopeConfigInterface::class => \Magento\TestFramework\App\Config::class,
26-
\Magento\Captcha\Model\DefaultModel::class => \Magento\TestFramework\Captcha\DefaultModel::class,
25+
\Magento\Framework\App\Config\ScopeConfigInterface::class => \Magento\TestFramework\App\Config::class
2726
];

0 commit comments

Comments
 (0)