Skip to content

Commit 70e695c

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-64221' into NORD-BUGFIXES-PR
2 parents e1e2afe + 6c22cbf commit 70e695c

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getProducts(ProductInterface $product)
6363
);
6464

6565
$this->linkedProductMap[$product->getId()] = $this->collectionFactory->create()
66-
->addAttributeToSelect(['price', 'special_price'])
66+
->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date'])
6767
->addIdFilter($productIds)
6868
->getItems();
6969
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
12+
13+
class LowestPriceOptionsProviderTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $resourceConnection;
24+
25+
/**
26+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $connection;
29+
30+
/**
31+
* @var LinkedProductSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $linkedProductSelectBuilder;
34+
35+
/**
36+
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $collectionFactory;
39+
40+
/**
41+
* @var \Magento\Catalog\Model\ResourceModel\Product\Collection|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $productCollection;
44+
45+
protected function setUp()
46+
{
47+
$this->connection = $this
48+
->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
49+
->getMock();
50+
$this->resourceConnection = $this
51+
->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
52+
->disableOriginalConstructor()
53+
->setMethods(['getConnection'])
54+
->getMock();
55+
$this->resourceConnection->expects($this->once())->method('getConnection')->willReturn($this->connection);
56+
$this->linkedProductSelectBuilder = $this
57+
->getMockBuilder(LinkedProductSelectBuilderInterface::class)
58+
->setMethods(['build'])
59+
->getMock();
60+
$this->productCollection = $this
61+
->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['addAttributeToSelect', 'addIdFilter', 'getItems'])
64+
->getMock();
65+
$this->collectionFactory = $this
66+
->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
67+
->disableOriginalConstructor()
68+
->setMethods(['create'])
69+
->getMock();
70+
$this->collectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection);
71+
72+
$objectManager = new ObjectManager($this);
73+
$this->model = $objectManager->getObject(
74+
\Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider::class,
75+
[
76+
'resourceConnection' => $this->resourceConnection,
77+
'linkedProductSelectBuilder' => $this->linkedProductSelectBuilder,
78+
'collectionFactory' => $this->collectionFactory,
79+
]
80+
);
81+
}
82+
83+
public function testGetProducts()
84+
{
85+
$productId = 1;
86+
$linkedProducts = ['some', 'linked', 'products', 'dataobjects'];
87+
$product = $this->getMockBuilder(ProductInterface::class)->disableOriginalConstructor()->getMock();
88+
$product->expects($this->any())->method('getId')->willReturn($productId);
89+
$this->linkedProductSelectBuilder->expects($this->any())->method('build')->with($productId)->willReturn([]);
90+
$this->productCollection
91+
->expects($this->once())
92+
->method('addAttributeToSelect')
93+
->with(['price', 'special_price', 'special_from_date', 'special_to_date'])
94+
->willReturnSelf();
95+
$this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf();
96+
$this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts);
97+
98+
$this->assertEquals($linkedProducts, $this->model->getProducts($product));
99+
}
100+
}

0 commit comments

Comments
 (0)