Skip to content

Commit

Permalink
MAGETWO-64902: [GitHub][PR] bug #8277 fixing bug with https downloadi…
Browse files Browse the repository at this point in the history
…ng. #8278
  • Loading branch information
Oleksii Korshenko committed Feb 22, 2017
2 parents 49fb152 + 131ada4 commit 86fd9ff
Show file tree
Hide file tree
Showing 72 changed files with 2,280 additions and 171 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 @@ -8,6 +8,8 @@

namespace Magento\Catalog\Model\Indexer\Category\Product;

use Magento\Framework\DB\Query\BatchIteratorInterface as BatchIteratorInterface;
use Magento\Framework\DB\Query\Generator as QueryGenerator;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;

Expand Down Expand Up @@ -102,20 +104,29 @@ abstract class AbstractAction
*/
protected $tempTreeIndexTableName;

/**
* @var QueryGenerator
*/
private $queryGenerator;

/**
* @param ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Model\Config $config
* @param QueryGenerator $queryGenerator
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Config $config
\Magento\Catalog\Model\Config $config,
QueryGenerator $queryGenerator = null
) {
$this->resource = $resource;
$this->connection = $resource->getConnection();
$this->storeManager = $storeManager;
$this->config = $config;
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(QueryGenerator::class);
}

/**
Expand Down Expand Up @@ -309,15 +320,26 @@ protected function isRangingNeeded()
* @param int $range
* @return \Magento\Framework\DB\Select[]
*/
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
{
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
$field,
$select,
$range
) : [
$select
];
protected function prepareSelectsByRange(
\Magento\Framework\DB\Select $select,
$field,
$range = self::RANGE_CATEGORY_STEP
) {
if($this->isRangingNeeded()) {
$iterator = $this->queryGenerator->generate(
$field,
$select,
$range,
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
);

$queries = [];
foreach ($iterator as $query) {
$queries[] = $query;
}
return $queries;
}
return [$select];
}

/**
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');
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/etc/eav_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<field code="is_searchable" locked="true" />
</attribute>
<attribute code="category_ids">
<field code="is_global" locked="true" />
<field code="is_searchable" locked="true" />
<field code="used_for_sort_by" locked="true" />
<field code="is_used_in_grid" locked="true" />
Expand Down
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
Loading

0 comments on commit 86fd9ff

Please sign in to comment.