Skip to content

Commit 296c250

Browse files
committed
Merge remote-tracking branch 'origin/MC-15079' into 2.2.8-develop-pr82
2 parents b3a5ecd + 5be5bb2 commit 296c250

File tree

2 files changed

+99
-2
lines changed
  • app/code/Magento/Quote/Model/ResourceModel/Quote/Item
  • dev/tests/integration/testsuite/Magento/Quote/Model/ResourceModel/Quote/Item

2 files changed

+99
-2
lines changed

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ private function getOptionProductIds(
325325
/**
326326
* Check is valid product.
327327
*
328-
* @param ProductInterface $product
328+
* @param ProductInterface|null $product
329329
* @return bool
330330
*/
331-
private function isValidProduct(ProductInterface $product): bool
331+
private function isValidProduct(ProductInterface $product = null): bool
332332
{
333333
$result = ($product && (int)$product->getStatus() !== ProductStatus::STATUS_DISABLED);
334334

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Model\ResourceModel\Quote\Item;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\Quote\Model\ResourceModel\Quote\Item\Collection as QuoteItemCollection;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
18+
/**
19+
* Tests Magento\Quote\Model\ResourceModel\Quote\Item\Collection.
20+
*/
21+
class CollectionTest extends \PHPUnit\Framework\TestCase
22+
{
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var ProductRepositoryInterface
30+
*/
31+
private $productRepository;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
$this->objectManager = Bootstrap::getObjectManager();
39+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
40+
}
41+
42+
/**
43+
* Covers case when during quote item collection load product exists in db but not accessible.
44+
*
45+
* @magentoDataFixture Magento/Sales/_files/quote.php
46+
* @return void
47+
*/
48+
public function testLoadCollectionWithNotAccessibleProduct()
49+
{
50+
/** @var Quote $quote */
51+
$quote = $this->objectManager->create(Quote::class);
52+
$quote->load('test01', 'reserved_order_id');
53+
54+
$this->assertCount(1, $quote->getItemsCollection());
55+
56+
$product = $this->productRepository->get('simple');
57+
/** @var ProductCollection $productCollection */
58+
$productCollection = $this->objectManager->create(ProductCollection::class);
59+
$this->setPropertyValue($productCollection, '_isCollectionLoaded', true);
60+
/** @var ProductCollectionFactory|\PHPUnit_Framework_MockObject_MockObject $productCollectionFactoryMock */
61+
$productCollectionFactoryMock = $this->createMock(ProductCollectionFactory::class);
62+
$productCollectionFactoryMock->expects($this->any())->method('create')->willReturn($productCollection);
63+
64+
/** @var QuoteItemCollection $quoteItemCollection */
65+
$quoteItemCollection = $this->objectManager->create(
66+
QuoteItemCollection::class,
67+
[
68+
'productCollectionFactory' => $productCollectionFactoryMock,
69+
]
70+
);
71+
72+
$quoteItemCollection->setQuote($quote);
73+
$this->assertCount(1, $quoteItemCollection);
74+
$item = $quoteItemCollection->getItemByColumnValue('product_id', $product->getId());
75+
76+
$this->assertNotNull($item);
77+
$this->assertTrue($item->isDeleted());
78+
}
79+
80+
/**
81+
* Set object non-public property value.
82+
*
83+
* @param object $object
84+
* @param string $propertyName
85+
* @param mixed $value
86+
* @return void
87+
*/
88+
private function setPropertyValue($object, string $propertyName, $value)
89+
{
90+
$reflectionClass = new \ReflectionClass($object);
91+
if ($reflectionClass->hasProperty($propertyName)) {
92+
$reflectionProperty = $reflectionClass->getProperty($propertyName);
93+
$reflectionProperty->setAccessible(true);
94+
$reflectionProperty->setValue($object, $value);
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)