Skip to content

Commit 041c4fe

Browse files
nikshostkorganin
authored andcommitted
MAGETWO-54963: Extensibility and modularity improvements
- Placeholders added to orders list - Unit test fix
1 parent d4bb397 commit 041c4fe

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

app/code/Magento/Sales/Block/Order/History.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Sales\Block\Order;
77

8+
use \Magento\Framework\App\ObjectManager;
9+
use \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
10+
811
/**
912
* Sales order history block
1013
*/
@@ -33,16 +36,21 @@ class History extends \Magento\Framework\View\Element\Template
3336
/** @var \Magento\Sales\Model\ResourceModel\Order\Collection */
3437
protected $orders;
3538

39+
/**
40+
* @var CollectionFactoryInterface
41+
*/
42+
private $orderCollectionFactory;
43+
3644
/**
3745
* @param \Magento\Framework\View\Element\Template\Context $context
38-
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory
46+
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
3947
* @param \Magento\Customer\Model\Session $customerSession
4048
* @param \Magento\Sales\Model\Order\Config $orderConfig
4149
* @param array $data
4250
*/
4351
public function __construct(
4452
\Magento\Framework\View\Element\Template\Context $context,
45-
\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface $orderCollectionFactory,
53+
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
4654
\Magento\Customer\Model\Session $customerSession,
4755
\Magento\Sales\Model\Order\Config $orderConfig,
4856
array $data = []
@@ -62,6 +70,19 @@ protected function _construct()
6270
$this->pageConfig->getTitle()->set(__('My Orders'));
6371
}
6472

73+
/**
74+
* @return CollectionFactoryInterface
75+
*
76+
* @deprecated
77+
*/
78+
private function getOrderCollectionFactory()
79+
{
80+
if ($this->orderCollectionFactory === null) {
81+
$this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
82+
}
83+
return $this->orderCollectionFactory;
84+
}
85+
6586
/**
6687
* @return bool|\Magento\Sales\Model\ResourceModel\Order\Collection
6788
*/
@@ -71,7 +92,7 @@ public function getOrders()
7192
return false;
7293
}
7394
if (!$this->orders) {
74-
$this->orders = $this->_orderCollectionFactory->create($customerId)->addFieldToSelect(
95+
$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
7596
'*'
7697
)->addFieldToFilter(
7798
'status',

app/code/Magento/Sales/Test/Unit/Block/Order/HistoryTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
2222
*/
2323
protected $orderCollectionFactory;
2424

25+
/**
26+
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $orderCollectionFactoryInterface;
29+
30+
/**
31+
* @var \Magento\Framework\App\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $objectManager;
34+
2535
/**
2636
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
2737
*/
@@ -48,6 +58,14 @@ protected function setUp()
4858
$this->orderCollectionFactory =
4959
$this->getMockBuilder('Magento\Sales\Model\ResourceModel\Order\CollectionFactory')
5060
->disableOriginalConstructor()->setMethods(['create'])->getMock();
61+
$this->orderCollectionFactoryInterface =
62+
$this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)
63+
->disableOriginalConstructor()->setMethods(['create'])->getMock();
64+
$this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
65+
$this->objectManager->expects($this->any())
66+
->method('get')
67+
->will($this->returnValue($this->orderCollectionFactoryInterface));
68+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
5169

5270
$this->customerSession = $this->getMockBuilder('Magento\Customer\Model\Session')
5371
->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
@@ -101,7 +119,7 @@ public function testConstructMethod()
101119
->method('setOrder')
102120
->with('created_at', 'desc')
103121
->will($this->returnSelf());
104-
$this->orderCollectionFactory->expects($this->atLeastOnce())
122+
$this->orderCollectionFactoryInterface->expects($this->atLeastOnce())
105123
->method('create')
106124
->will($this->returnValue($orderCollection));
107125
$this->pageConfig->expects($this->atLeastOnce())

0 commit comments

Comments
 (0)