Skip to content

Commit

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

#8505
#8467
#8617
  • Loading branch information
Oleksii Korshenko authored Feb 21, 2017
2 parents c7fff61 + c74b6b7 commit b180d87
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ addons:
- postfix
language: php
php:
- 5.6
- 5.6.29
- 7.0
env:
global:
Expand Down
4 changes: 0 additions & 4 deletions app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ protected function setUp()
*/
public function testGetCaptcha()
{
if (!function_exists("imageftbbox")) {
$this->markTestSkipped('imageftbbox is not available on the test environment');
}

$this->configMock->expects(
$this->once()
)->method(
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ class DefaultTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
if (!function_exists("imageftbbox")) {
$this->markTestSkipped('imageftbbox is not available on the test environment');
}
$this->session = $this->_getSessionStub();

$this->_storeManager = $this->getMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type)
$products = $this->providers[$type]->getLinkedProducts($product);
$converter = $this->converterPool->getConverter($type);
$output = [];
$sorterItems = [];
foreach ($products as $item) {
$output[$item->getId()] = $converter->convert($item);
}
return $output;

foreach ($output as $item) {
$itemPosition = $item['position'];
if (!isset($sorterItems[$itemPosition])) {
$sorterItems[$itemPosition] = $item;
} else {
$newPosition = $itemPosition + 1;
$sorterItems[$newPosition] = $item;
}
}
ksort($sorterItems);
return $sorterItems;
}
}
110 changes: 110 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/CollectionProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model;

use Magento\Catalog\Model\ProductLink\CollectionProvider;
use Magento\Catalog\Model\ProductLink\CollectionProviderInterface;
use Magento\Catalog\Model\ProductLink\Converter\ConverterInterface;
use Magento\Catalog\Model\ProductLink\Converter\ConverterPool;
use Magento\Catalog\Model\Product;

class CollectionProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var CollectionProvider
*/
private $model;

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

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

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

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

protected function setUp()
{
$this->productMock = $this->getMock(Product::class, [], [], '', false, false);
$this->converterPoolMock = $this->getMock(ConverterPool::class, [], [], '', false, false);
$this->providerMock = $this->getMock(CollectionProviderInterface::class);
$this->converterMock = $this->getMock(ConverterInterface::class);

$this->model = new CollectionProvider($this->converterPoolMock, ['crosssell' => $this->providerMock]);
}

/**
* Test sort order of linked products based on configured item position.
*/
public function testGetCollection()
{
$linkedProductOneMock = $this->getMock(Product::class, [], [], '', false, false);
$linkedProductTwoMock = $this->getMock(Product::class, [], [], '', false, false);
$linkedProductThreeMock = $this->getMock(Product::class, [], [], '', false, false);

$linkedProductOneMock->expects($this->once())->method('getId')->willReturn(1);
$linkedProductTwoMock->expects($this->once())->method('getId')->willReturn(2);
$linkedProductThreeMock->expects($this->once())->method('getId')->willReturn(3);

$this->converterPoolMock->expects($this->once())
->method('getConverter')
->with('crosssell')
->willReturn($this->converterMock);

$map = [
[$linkedProductOneMock, ['name' => 'Product One', 'position' => 10]],
[$linkedProductTwoMock, ['name' => 'Product Two', 'position' => 2]],
[$linkedProductThreeMock, ['name' => 'Product Three', 'position' => 2]],
];

$this->converterMock->expects($this->exactly(3))->method('convert')->willReturnMap($map);

$this->providerMock->expects($this->once())
->method('getLinkedProducts')
->with($this->productMock)
->willReturn(
[
$linkedProductOneMock,
$linkedProductTwoMock,
$linkedProductThreeMock
]
);

$expectedResult = [
2 => ['name' => 'Product Two', 'position' => 2],
3 => ['name' => 'Product Three', 'position' => 2],
10 => ['name' => 'Product One', 'position' => 10],
];

$actualResult = $this->model->getCollection($this->productMock, 'crosssell');

$this->assertEquals($expectedResult, $actualResult, 'Sort order of linked products in incorrect');
}

/**
* Test exception when collection provider is not configured for product link type.
*
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedExceptionMessage Collection provider is not registered
*/
public function testGetCollectionWithMissingProviders()
{
$this->model->getCollection($this->productMock, 'upsell');
}
}
14 changes: 12 additions & 2 deletions app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ class Tree extends \Magento\Backend\Block\Template
*/
protected $_cmsWysiwygImages = null;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages
* @param \Magento\Framework\Registry $registry
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages,
\Magento\Framework\Registry $registry,
array $data = []
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->_coreRegistry = $registry;
$this->_cmsWysiwygImages = $cmsWysiwygImages;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct($context, $data);
}

Expand All @@ -65,7 +75,7 @@ public function getTreeJson()
'cls' => 'folder',
];
}
return \Zend_Json::encode($jsonArray);
return $this->serializer->serialize($jsonArray);
}

/**
Expand Down
26 changes: 24 additions & 2 deletions app/code/Magento/Customer/Block/Account/AuthenticationPopup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@ class AuthenticationPopup extends \Magento\Framework\View\Element\Template
*/
protected $jsLayout;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($context, $data);
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
* @return string
*/
public function getJsLayout()
{
return \Zend_Json::encode($this->jsLayout);
return $this->serializer->serialize($this->jsLayout);
}

/**
Expand All @@ -50,6 +60,18 @@ public function getConfig()
];
}

/**
* Returns popup config in JSON format.
*
* Added in scope of https://github.com/magento/magento2/pull/8617
*
* @return bool|string
*/
public function getSerializedConfig()
{
return $this->serializer->serialize($this->getConfig());
}

/**
* Is autocomplete enabled for storefront
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase
/** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
private $urlBuilderMock;

/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
private $serializerMock;

protected function setUp()
{
$this->contextMock = $this->getMockBuilder(Context::class)
Expand Down Expand Up @@ -72,8 +75,13 @@ function ($string) {
->method('getEscaper')
->willReturn($escaperMock);

$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
->getMock();

$this->model = new AuthenticationPopup(
$this->contextMock
$this->contextMock,
[],
$this->serializerMock
);
}

Expand All @@ -83,6 +91,7 @@ function ($string) {
* @param string $registerUrl
* @param string $forgotUrl
* @param array $result
* @throws \PHPUnit_Framework_Exception
*
* @dataProvider dataProviderGetConfig
*/
Expand Down Expand Up @@ -172,4 +181,51 @@ public function dataProviderGetConfig()
],
];
}

/**
* @param mixed $isAutocomplete
* @param string $baseUrl
* @param string $registerUrl
* @param string $forgotUrl
* @param array $result
* @throws \PHPUnit_Framework_Exception
*
* @dataProvider dataProviderGetConfig
*/
public function testGetSerializedConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result)
{
$this->scopeConfigMock->expects($this->any())
->method('getValue')
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
->willReturn($isAutocomplete);

/** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */
$storeMock = $this->getMockBuilder(StoreInterface::class)
->setMethods(['getBaseUrl'])
->getMockForAbstractClass();

$this->storeManagerMock->expects($this->any())
->method('getStore')
->with(null)
->willReturn($storeMock);

$storeMock->expects($this->any())
->method('getBaseUrl')
->willReturn($baseUrl);

$this->urlBuilderMock->expects($this->any())
->method('getUrl')
->willReturnMap(
[
['customer/account/create', [], $registerUrl],
['customer/account/forgotpassword', [], $forgotUrl],
]
);
$this->serializerMock->expects($this->any())->method('serialize')
->willReturn(
json_encode($this->model->getConfig())
);

$this->assertEquals(json_encode($result), $this->model->getSerializedConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
?>
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'" style="display: none;">
<script>
window.authenticationPopup = <?php /* @noEscape */ echo \Zend_Json::encode($block->getConfig()); ?>;
window.authenticationPopup = <?php /* @noEscape */ echo $block->getSerializedConfig(); ?>;
</script>
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
Expand Down
3 changes: 1 addition & 2 deletions dev/tests/integration/etc/di/preferences/ce.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
\Magento\Framework\App\ResourceConnection\ConnectionAdapterInterface::class =>
\Magento\TestFramework\Db\ConnectionAdapter::class,
\Magento\Framework\Filesystem\DriverInterface::class => \Magento\Framework\Filesystem\Driver\File::class,
\Magento\Framework\App\Config\ScopeConfigInterface::class => \Magento\TestFramework\App\Config::class,
\Magento\Captcha\Model\DefaultModel::class => \Magento\TestFramework\Captcha\DefaultModel::class,
\Magento\Framework\App\Config\ScopeConfigInterface::class => \Magento\TestFramework\App\Config::class
];
Loading

0 comments on commit b180d87

Please sign in to comment.