Skip to content

Commit

Permalink
⏫ Forwardport of #11702 to 2.3-develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-engcom-team committed Jan 29, 2018
1 parent 0379ead commit 77f34cf
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 18 deletions.
19 changes: 17 additions & 2 deletions app/code/Magento/Quote/Model/ResourceModel/Quote.php
Expand Up @@ -165,7 +165,7 @@ public function getReservedOrderId($quote)
{
return $this->sequenceManager->getSequence(
\Magento\Sales\Model\Order::ENTITY,
$quote->getStore()->getGroup()->getDefaultStoreId()
$quote->getStoreId()
)
->getNextValue();
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public function markQuotesRecollectOnCatalogRules()
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function substractProductFromQuotes($product)
public function subtractProductFromQuotes($product)
{
$productId = (int)$product->getId();
if (!$productId) {
Expand Down Expand Up @@ -272,6 +272,21 @@ public function substractProductFromQuotes($product)
return $this;
}

/**
* Subtract product from all quotes quantities
*
* @param \Magento\Catalog\Model\Product $product
*
* @deprecated 101.0.1
* @see \Magento\Quote\Model\ResourceModel\Quote::subtractProductFromQuotes
*
* @return $this
*/
public function substractProductFromQuotes($product)
{
return $this->subtractProductFromQuotes($product);
}

/**
* Mark recollect contain product(s) quotes
*
Expand Down
123 changes: 107 additions & 16 deletions app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php
Expand Up @@ -6,43 +6,71 @@

namespace Magento\Quote\Test\Unit\Model\ResourceModel;


use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\Pdo\Mysql;
use Magento\Framework\DB\Select;
use Magento\Framework\DB\Sequence\SequenceInterface;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
use Magento\SalesSequence\Model\Manager;

class QuoteTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Quote\Model\ResourceModel\Quote
*/
private $model;

/**
* @var \Magento\Framework\App\ResourceConnection
* @var ResourceConnection
*/
private $resourceMock;

/**
* @var \Magento\Framework\DB\Adapter\Pdo\Mysql
* @var Mysql
*/
private $adapterMock;

/**
* @var \Magento\Framework\DB\Select
* @var Select
*/
private $selectMock;

/**
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
*/
private $quoteMock;

/**
* @var Manager|\PHPUnit_Framework_MockObject_MockObject
*/
private $sequenceManagerMock;

/**
* @var SequenceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $sequenceMock;

/**
* @var QuoteResource
*/
private $model;

protected function setUp()
{
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
$objectManagerHelper = new ObjectManager($this);
$this->selectMock = $this->getMockBuilder(Select::class)
->disableOriginalConstructor()
->getMock();
$this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
$this->selectMock->expects($this->any())->method('where');

$this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
$this->adapterMock = $this->getMockBuilder(Mysql::class)
->disableOriginalConstructor()
->getMock();
$this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));

$this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)
->disableOriginalConstructor()
->getMock();
$this->resourceMock->expects(
Expand All @@ -53,10 +81,38 @@ protected function setUp()
$this->returnValue($this->adapterMock)
);

$this->model = $objectManagerHelper->getObject(
\Magento\Quote\Model\ResourceModel\Quote::class,
[
'resource' => $this->resourceMock
$context = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();
$context->expects(
$this->once()
)->method(
'getResources'
)->will(
$this->returnValue($this->resourceMock)
);

$snapshot = $this->getMockBuilder(Snapshot::class)
->disableOriginalConstructor()
->getMock();
$relationComposite = $this->getMockBuilder(RelationComposite::class)
->disableOriginalConstructor()
->getMock();
$this->quoteMock = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->getMock();
$this->sequenceManagerMock = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->sequenceMock = $this->getMockBuilder(SequenceInterface::class)
->disableOriginalConstructor()
->getMock();
$this->model = $objectManagerHelper->getObject(QuoteResource::class, [
'context' => $context,
'entitySnapshot' => $snapshot,
'entityRelationComposite' => $relationComposite,
'sequenceManager' => $this->sequenceManagerMock,
'connectionName' => null,
]
);
}
Expand All @@ -81,4 +137,39 @@ public function isOrderIncrementIdUsedDataProvider()
{
return [[100000001], ['10000000001'], ['M10000000001']];
}

/**
* /**
* @param $entityType
* @param $storeId
* @param $reservedOrderId
* @dataProvider getReservedOrderIdDataProvider
*/
public function testGetReservedOrderId($entityType, $storeId, $reservedOrderId)
{
$this->sequenceManagerMock->expects($this->once())
->method('getSequence')
->with($entityType, $storeId)
->willReturn($this->sequenceMock);
$this->quoteMock->expects($this->once())
->method('getStoreId')
->willReturn($storeId);
$this->sequenceMock->expects($this->once())
->method('getNextValue')
->willReturn($reservedOrderId);

$this->assertEquals($reservedOrderId, $this->model->getReservedOrderId($this->quoteMock));
}

/**
* @return array
*/
public function getReservedOrderIdDataProvider(): array
{
return [
[\Magento\Sales\Model\Order::ENTITY, 1, '1000000001'],
[\Magento\Sales\Model\Order::ENTITY, 2, '2000000001'],
[\Magento\Sales\Model\Order::ENTITY, 3, '3000000001']
];
}
}

0 comments on commit 77f34cf

Please sign in to comment.