diff --git a/app/code/Magento/Bundle/view/base/web/js/price-bundle.js b/app/code/Magento/Bundle/view/base/web/js/price-bundle.js index 3ad6f45b08d40194c9515e3769daf1936de8224c..399e152769f3fc24bce19a052aef9d60fa42af90 100644 --- a/app/code/Magento/Bundle/view/base/web/js/price-bundle.js +++ b/app/code/Magento/Bundle/view/base/web/js/price-bundle.js @@ -22,7 +22,8 @@ define([ ' +<%- finalPrice.formatted %>' + '<% } %>', controlContainer: 'dd', // should be eliminated - priceFormat: {} + priceFormat: {}, + isFixedPrice: false }; $.widget('mage.priceBundle', { @@ -116,17 +117,17 @@ define([ */ _applyQtyFix: function applyQtyFix() { var config = this.options.optionConfig; - _.each(config.options, function (option) { - _.each(option.selections, function (item) { - if (item.priceType === '0') { + if (config.isFixedPrice) { + _.each(config.options, function (option) { + _.each(option.selections, function (item) { if (item.qty && item.qty !== 1) { _.each(item.prices, function (price) { price.amount = price.amount / item.qty; }); } - } + }); }); - }); + } }, /** diff --git a/app/code/Magento/Sales/Api/Data/ShipmentInterface.php b/app/code/Magento/Sales/Api/Data/ShipmentInterface.php index 3af3b16ebf66154df3527aa22d298881cab5466e..41c676ea2081219e35d7e7d6561206f4f5bf5c24 100644 --- a/app/code/Magento/Sales/Api/Data/ShipmentInterface.php +++ b/app/code/Magento/Sales/Api/Data/ShipmentInterface.php @@ -253,7 +253,7 @@ interface ShipmentInterface extends \Magento\Framework\Api\ExtensibleDataInterfa * @param \Magento\Sales\Api\Data\ShipmentCommentInterface[] $comments * @return $this */ - public function setComments(array $comments = null); + public function setComments($comments = null); /** * Sets the store ID for the shipment. diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php b/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php index d432435aee29d49dc3ee4c36119ce5c9f30ece4a..829a106b47ca821ccdb5ebee117c95179960b9f6 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php @@ -167,7 +167,7 @@ class Item extends AbstractExtensibleModel implements CreditmemoItemInterface /** * Applying qty to order item * - * @return \Magento\Sales\Model\Order\Shipment\Item + * @return \Magento\Sales\Model\Order\Creditmemo\Item */ public function register() { diff --git a/app/code/Magento/Sales/Model/Order/Shipment.php b/app/code/Magento/Sales/Model/Order/Shipment.php index 51b24d4fb8946a28f8d21585e789ee561f611bb2..fae8ba458a55c9d9cd523b62c04f691824942d40 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Shipment.php @@ -733,7 +733,7 @@ class Shipment extends AbstractModel implements EntityInterface, ShipmentInterfa * @param \Magento\Sales\Api\Data\ShipmentCommentInterface[] $comments * @return $this */ - public function setComments(array $comments = null) + public function setComments($comments = null) { return $this->setData(ShipmentInterface::COMMENTS, $comments); } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Admin/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Admin/ItemTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e5bfaa4fa3efd7dbad0726d06976f98a61cbdf93 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Admin/ItemTest.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Sales\Test\Unit\Model\Order\Admin; + +/** + * Class ValidatorTest + */ +class ItemTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemMock; + + /** @var \Magento\Sales\Model\Order\Admin\Item */ + protected $item; + + + public function setUp() + { + $this->orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $this->item = new \Magento\Sales\Model\Order\Admin\Item(); + } + + public function testGetSku() + { + $sku = 'sku'; + $this->orderItemMock->expects($this->once()) + ->method('getSku') + ->willReturn($sku); + $result = $this->item->getSku($this->orderItemMock); + $this->assertEquals($sku, $result); + } + + public function testGetName() + { + $name = 'name'; + $this->orderItemMock->expects($this->once()) + ->method('getName') + ->willReturn($name); + $result = $this->item->getName($this->orderItemMock); + $this->assertEquals($name, $result); + } + + public function testGetProductId() + { + $productId = 1; + $this->orderItemMock->expects($this->once()) + ->method('getProductId') + ->willReturn($productId); + $result = $this->item->getProductId($this->orderItemMock); + $this->assertEquals($productId, $result); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php new file mode 100644 index 0000000000000000000000000000000000000000..afcf792c718dddc69eab5e23a17923b32a8e8a9c --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php @@ -0,0 +1,323 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Sales\Test\Unit\Model\Order\Creditmemo; + +use Magento\Sales\Api\Data\CreditmemoItemInterface; + +class ItemTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemFactoryMock; + + /** @var \Magento\Sales\Model\Order\Creditmemo\Item */ + protected $item; + + public function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->orderItemFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Order\ItemFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->item = $objectManager->getObject( + 'Magento\Sales\Model\Order\Creditmemo\Item', + [ + 'orderItemFactory' => $this->orderItemFactoryMock + ] + ); + } + + public function testGetOrderItemExist() + { + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $this->item->setOrderItem($orderItemMock); + $result = $this->item->getOrderItem(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Item', $result); + } + + public function testGetOrderItemFromCreditmemo() + { + $orderItemId = 1; + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + + $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') + ->disableOriginalConstructor() + ->getMock(); + $orderMock->expects($this->once()) + ->method('getItemById') + ->with($orderItemId) + ->willReturn($orderItemMock); + + $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') + ->disableOriginalConstructor() + ->getMock(); + $creditmemoMock->expects($this->once()) + ->method('getOrder') + ->willReturn($orderMock); + + $this->item->setData(CreditmemoItemInterface::ORDER_ITEM_ID, $orderItemId); + $this->item->setCreditmemo($creditmemoMock); + $result = $this->item->getOrderItem(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Item', $result); + } + + public function testGetOrderItemFromFactory() + { + $orderItemId = 1; + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('load') + ->with($orderItemId) + ->willReturnSelf(); + + $this->orderItemFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($orderItemMock); + + $this->item->setData(CreditmemoItemInterface::ORDER_ITEM_ID, $orderItemId); + $result = $this->item->getOrderItem(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Item', $result); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name". + */ + public function testSetQtyDecimalException() + { + $qty = 100; + $orderItemQty = 10; + $name = 'test_item_name'; + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getIsQtyDecimal') + ->willReturn(true); + $orderItemMock->expects($this->once()) + ->method('getQtyToRefund') + ->willReturn($orderItemQty); + + $this->item->setData(CreditmemoItemInterface::NAME, $name); + $this->item->setOrderItem($orderItemMock); + $this->item->setQty($qty); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name2". + */ + public function testSetQtyNumericException() + { + $qty = 100; + $orderItemQty = 10; + $name = 'test_item_name2'; + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getIsQtyDecimal') + ->willReturn(false); + $orderItemMock->expects($this->once()) + ->method('getQtyToRefund') + ->willReturn($orderItemQty); + + $this->item->setData(CreditmemoItemInterface::NAME, $name); + $this->item->setOrderItem($orderItemMock); + $this->item->setQty($qty); + } + + public function testSetQty() + { + $qty = 10; + $orderItemQty = 100; + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getIsQtyDecimal') + ->willReturn(false); + $orderItemMock->expects($this->once()) + ->method('getQtyToRefund') + ->willReturn($orderItemQty); + + $this->item->setOrderItem($orderItemMock); + $this->item->setQty($qty); + $this->assertEquals($qty, $this->item->getQty()); + } + + public function testRegister() + { + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getQtyRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getTaxRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getBaseTaxRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getHiddenTaxRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getBaseHiddenTaxRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getAmountRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getBaseAmountRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getDiscountRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getBaseDiscountRefunded') + ->willReturn(1); + $data = [ + 'qty' => 1, + 'tax_amount' => 1, + 'base_tax_amount' => 1, + 'hidden_tax_amount' => 1, + 'base_hidden_tax_amount' => 1, + 'row_total' => 1, + 'base_row_total' => 1, + 'discount_amount' => 1, + 'base_discount_amount' => 1 + ]; + $this->item->setOrderItem($orderItemMock); + $this->item->setData($data); + $result = $this->item->register(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result); + } + + public function testCancel() + { + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->setMethods( + [ + 'setQtyRefunded', + 'getQtyRefunded', + 'getTaxRefunded', + 'getBaseTaxAmount', + 'getQtyOrdered', + 'setTaxRefunded', + 'setHiddenTaxRefunded', + 'getHiddenTaxRefunded', + 'getHiddenTaxAmount' + ] + ) + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getQtyRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('setQtyRefunded') + ->with(0); + $orderItemMock->expects($this->once()) + ->method('getTaxRefunded') + ->willReturn(10); + $orderItemMock->expects($this->once()) + ->method('getBaseTaxAmount') + ->willReturn(5); + $orderItemMock->expects($this->exactly(2)) + ->method('getQtyOrdered') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('setTaxRefunded') + ->with(5); + + $orderItemMock->expects($this->once()) + ->method('setHiddenTaxRefunded') + ->with(0); + $orderItemMock->expects($this->once()) + ->method('getHiddenTaxRefunded') + ->willReturn(10); + $orderItemMock->expects($this->once()) + ->method('getHiddenTaxAmount') + ->willReturn(10); + + $this->item->setData('qty', 1); + $this->item->setOrderItem($orderItemMock); + $result = $this->item->cancel(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result); + } + + public function testCalcRowTotal() + { + $creditmemoMock = $this->getMockBuilder('\Magento\Sales\Model\Order\Creditmemo') + ->disableOriginalConstructor() + ->getMock(); + $creditmemoMock->expects($this->exactly(4)) + ->method('roundPrice') + ->willReturnMap( + [ + [0.375, 'regular', false, 0.4], + [0.375, 'base', false, 0.4], + [1, 'including', false, 1.0], + [1, 'including_base', false, 1.0] + ] + ); + + $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') + ->disableOriginalConstructor() + ->getMock(); + $orderItemMock->expects($this->once()) + ->method('getQtyInvoiced') + ->willReturn(10); + $orderItemMock->expects($this->once()) + ->method('getQtyRefunded') + ->willReturn(2); + $orderItemMock->expects($this->once()) + ->method('getRowInvoiced') + ->willReturn(5); + $orderItemMock->expects($this->once()) + ->method('getAmountRefunded') + ->willReturn(2); + $orderItemMock->expects($this->once()) + ->method('getBaseRowInvoiced') + ->willReturn(5); + $orderItemMock->expects($this->once()) + ->method('getBaseAmountRefunded') + ->willReturn(2); + $orderItemMock->expects($this->once()) + ->method('getRowTotalInclTax') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getBaseRowTotalInclTax') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getQtyRefunded') + ->willReturn(1); + $orderItemMock->expects($this->once()) + ->method('getQtyOrdered') + ->willReturn(1); + + $this->item->setData('qty', 1); + $this->item->setCreditmemo($creditmemoMock); + $this->item->setOrderItem($orderItemMock); + $result = $this->item->calcRowTotal(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/CostTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/CostTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1841b489d9c18d7eb8ed87664c4281db56d08668 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/CostTest.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Creditmemo\Total; + +/** + * Class CostTest + */ +class CostTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Total\Cost + */ + protected $total; + /** + * @var \Magento\Sales\Model\Order\Creditmemo|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoMock; + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoItemMock; + + public function setUp() + { + $this->creditmemoMock = $this->getMock('\Magento\Sales\Model\Order\Creditmemo', [ + 'setBaseCost', 'getAllItems' + ], [], '', false); + $this->creditmemoItemMock = $this->getMock( + '\Magento\Sales\Model\Order\Creditmemo\Item', + ['getHasChildren', 'getBaseCost', 'getQty'], + [], + '', + false + ); + $this->total = new \Magento\Sales\Model\Order\Creditmemo\Total\Cost(); + } + + public function testCollect() + { + $this->creditmemoMock->expects($this->once()) + ->method('getAllItems') + ->willReturn([$this->creditmemoItemMock, $this->creditmemoItemMock]); + $this->creditmemoItemMock->expects($this->exactly(2)) + ->method('getHasChildren') + ->willReturn(false); + $this->creditmemoItemMock->expects($this->exactly(2)) + ->method('getBaseCost') + ->willReturn(10); + $this->creditmemoItemMock->expects($this->exactly(2)) + ->method('getQty') + ->willReturn(2); + $this->creditmemoMock->expects($this->once()) + ->method('setBaseCost') + ->with(40) + ->willReturnSelf(); + $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/DiscountTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/DiscountTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c850a30af8431301a11ffbcef23c4ac423cd55c4 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/DiscountTest.php @@ -0,0 +1,146 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Creditmemo\Total; + +/** + * Class DiscountTest + */ +class DiscountTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Total\Cost + */ + protected $total; + /** + * @var \Magento\Sales\Model\Order\Creditmemo|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoMock; + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoItemMock; + /** + * @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderMock; + /** + * @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemMock; + + public function setUp() + { + $this->orderMock = $this->getMock( + 'Magento\Sales\Model\Order', + ['getBaseShippingDiscountAmount', 'getBaseShippingAmount', 'getShippingAmount'], + [], + '', + false + ); + $this->orderItemMock = $this->getMock( + 'Magento\Sales\Model\Order', + [ + 'isDummy', 'getDiscountInvoiced', 'getBaseDiscountInvoiced', 'getQtyInvoiced', 'getQty', + 'getDiscountRefunded', 'getQtyRefunded' + ], + [], + '', + false + ); + $this->creditmemoMock = $this->getMock( + '\Magento\Sales\Model\Order\Creditmemo', + [ + 'setBaseCost', 'getAllItems', 'getOrder', 'getBaseShippingAmount', 'roundPrice', + 'setDiscountAmount', 'setBaseDiscountAmount' + ], + [], + '', + false + ); + $this->creditmemoItemMock = $this->getMock( + '\Magento\Sales\Model\Order\Creditmemo\Item', + [ + 'getHasChildren', 'getBaseCost', 'getQty', 'getOrderItem', 'setDiscountAmount', + 'setBaseDiscountAmount', 'isLast' + ], + [], + '', + false + ); + $this->total = new \Magento\Sales\Model\Order\Creditmemo\Total\Discount(); + } + + public function testCollect() + { + $this->creditmemoMock->expects($this->exactly(2)) + ->method('setDiscountAmount') + ->willReturnSelf(); + $this->creditmemoMock->expects($this->exactly(2)) + ->method('setBaseDiscountAmount') + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('getOrder') + ->willReturn($this->orderMock); + $this->creditmemoMock->expects($this->once()) + ->method('getBaseShippingAmount') + ->willReturn(1); + $this->orderMock->expects($this->once()) + ->method('getBaseShippingDiscountAmount') + ->willReturn(1); + $this->orderMock->expects($this->exactly(2)) + ->method('getBaseShippingAmount') + ->willReturn(1); + $this->orderMock->expects($this->once()) + ->method('getShippingAmount') + ->willReturn(1); + $this->creditmemoMock->expects($this->once()) + ->method('getAllItems') + ->willReturn([$this->creditmemoItemMock]); + $this->creditmemoItemMock->expects($this->atLeastOnce()) + ->method('getOrderItem') + ->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once()) + ->method('isDummy') + ->willReturn(false); + $this->orderItemMock->expects($this->once()) + ->method('getDiscountInvoiced') + ->willReturn(1); + $this->orderItemMock->expects($this->once()) + ->method('getBaseDiscountInvoiced') + ->willReturn(1); + $this->orderItemMock->expects($this->once()) + ->method('getQtyInvoiced') + ->willReturn(1); + $this->orderItemMock->expects($this->once()) + ->method('getDiscountRefunded') + ->willReturn(1); + $this->orderItemMock->expects($this->once()) + ->method('getQtyRefunded') + ->willReturn(0); + $this->creditmemoItemMock->expects($this->once()) + ->method('isLast') + ->willReturn(false); + $this->creditmemoItemMock->expects($this->atLeastOnce()) + ->method('getQty') + ->willReturn(1); + $this->creditmemoItemMock->expects($this->exactly(1)) + ->method('setDiscountAmount') + ->willReturnSelf(); + $this->creditmemoItemMock->expects($this->exactly(1)) + ->method('setBaseDiscountAmount') + ->willReturnSelf(); + $this->creditmemoMock->expects($this->exactly(2)) + ->method('roundPrice') + ->willReturnMap( + [ + [1, 'regular', true, 1], + [1, 'base', true, 1] + ] + ); + $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/SubtotalTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/SubtotalTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e35203fb6e554d2af4cadeae8ad9e47a48b3912f --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/SubtotalTest.php @@ -0,0 +1,134 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Creditmemo\Total; + +/** + * Class SubtotalTest + */ +class SubtotalTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Total\Subtotal + */ + protected $total; + /** + * @var \Magento\Sales\Model\Order\Creditmemo|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoMock; + /** + * @var \Magento\Sales\Model\Order\Creditmemo\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $creditmemoItemMock; + /** + * @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemMock; + + public function setUp() + { + $this->orderMock = $this->getMock( + 'Magento\Sales\Model\Order', + ['getBaseShippingDiscountAmount', 'getBaseShippingAmount', 'getShippingAmount'], + [], + '', + false + ); + $this->orderItemMock = $this->getMock( + 'Magento\Sales\Model\Order', + [ + 'isDummy', 'getDiscountInvoiced', 'getBaseDiscountInvoiced', 'getQtyInvoiced', 'getQty', + 'getDiscountRefunded', 'getQtyRefunded' + ], + [], + '', + false + ); + $this->creditmemoMock = $this->getMock( + '\Magento\Sales\Model\Order\Creditmemo', + [ + 'setBaseCost', 'getAllItems', 'getOrder', 'getBaseShippingAmount', 'roundPrice', + 'setDiscountAmount', 'setBaseDiscountAmount', 'setSubtotal', 'setBaseSubtotal', + 'setSubtotalInclTax', 'setBaseSubtotalInclTax', 'getGrandTotal', 'setGrandTotal', + 'getBaseGrandTotal', 'setBaseGrandTotal' + ], + [], + '', + false + ); + $this->creditmemoItemMock = $this->getMock( + '\Magento\Sales\Model\Order\Creditmemo\Item', + [ + 'getHasChildren', 'getBaseCost', 'getQty', 'getOrderItem', 'setDiscountAmount', + 'setBaseDiscountAmount', 'isLast', 'getRowTotalInclTax', 'getBaseRowTotalInclTax', + 'getRowTotal', 'getBaseRowTotal', 'calcRowTotal' + ], + [], + '', + false + ); + $this->total = new \Magento\Sales\Model\Order\Creditmemo\Total\Subtotal(); + } + + public function testCollect() + { + $this->creditmemoMock->expects($this->once()) + ->method('getAllItems') + ->willReturn([$this->creditmemoItemMock]); + $this->creditmemoItemMock->expects($this->atLeastOnce()) + ->method('getOrderItem') + ->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once()) + ->method('isDummy') + ->willReturn(false); + $this->creditmemoItemMock->expects($this->once()) + ->method('calcRowTotal') + ->willReturnSelf(); + $this->creditmemoItemMock->expects($this->once()) + ->method('getRowTotal') + ->willReturn(1); + $this->creditmemoItemMock->expects($this->once()) + ->method('getBaseRowTotal') + ->willReturn(1); + $this->creditmemoItemMock->expects($this->once()) + ->method('getRowTotalInclTax') + ->willReturn(1); + $this->creditmemoItemMock->expects($this->once()) + ->method('getBaseRowTotalInclTax') + ->willReturn(1); + $this->creditmemoMock->expects($this->once()) + ->method('setSubtotal') + ->with(1) + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('setBaseSubtotal') + ->with(1) + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('setSubtotalInclTax') + ->with(1) + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('setBaseSubtotalInclTax') + ->with(1) + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('getGrandTotal') + ->willReturn(1); + $this->creditmemoMock->expects($this->once()) + ->method('setGrandTotal') + ->with(2) + ->willReturnSelf(); + $this->creditmemoMock->expects($this->once()) + ->method('getBaseGrandTotal') + ->willReturn(1); + $this->creditmemoMock->expects($this->once()) + ->method('setBaseGrandTotal') + ->with(2) + ->willReturnSelf(); + $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Massaction/ItemsUpdaterTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Massaction/ItemsUpdaterTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b7462307b57d4051562672cb3d4de51ab9a6b1c4 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Massaction/ItemsUpdaterTest.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Grid\Massaction; + +class ItemsUpdaterTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Grid\Massaction\ItemsUpdater + */ + protected $itemUpdater; + + /** + * @var \Magento\Framework\Authorization|\PHPUnit_Framework_MockObject_MockObject + */ + protected $authorizationMock; + + public function setUp() + { + $this->authorizationMock = $this->getMock('Magento\Framework\Authorization', [], [], '', false); + $this->itemUpdater = new \Magento\Sales\Model\Order\Grid\Massaction\ItemsUpdater( + $this->authorizationMock + ); + } + + public function testUpdate() + { + $arguments =[ + 'cancel_order' => null, + 'hold_order' => null, + 'unhold_order' => null, + 'other' => null + ]; + $this->authorizationMock->expects($this->exactly(3)) + ->method('isAllowed') + ->willReturnMap( + [ + ['Magento_Sales::cancel', null, false], + ['Magento_Sales::hold', null, false], + ['Magento_Sales::unhold', null, false], + + ] + ); + $this->assertEquals(['other' => null], $this->itemUpdater->update($arguments)); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Row/UrlGeneratorTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Row/UrlGeneratorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7ff72976db9ca895add21e5bae262e89054b1956 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Grid/Row/UrlGeneratorTest.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Grid\Row; + +class UrlGeneratorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Grid\Row\UrlGenerator + */ + protected $urlGenerator; + /** + * @var \Magento\Backend\Model\UrlInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $urlMock; + /** + * @var \Magento\Framework\AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $authorizationMock; + + public function setUp() + { + $this->urlMock = $this->getMockForAbstractClass( + 'Magento\Backend\Model\UrlInterface', + [], + '', + false, + false, + true, + [] + ); + $this->authorizationMock = $this->getMockForAbstractClass( + 'Magento\Framework\AuthorizationInterface', + [], + '', + false, + false, + true, + [] + ); + $this->urlGenerator = new \Magento\Sales\Model\Order\Grid\Row\UrlGenerator( + $this->urlMock, + $this->authorizationMock, + ['path' => 'path'] + ); + } + + /** + * Provides permission for url generation + * + * @return array + */ + public function permissionProvider() + { + return [ + [true, null], + [false, false] + ]; + } + + /** + * @param bool $isAllowed + * @param null|bool $url + * @dataProvider permissionProvider + */ + public function testGetUrl($isAllowed, $url) + { + $this->authorizationMock->expects($this->once()) + ->method('isAllowed') + ->with('Magento_Sales::actions_view', null) + ->willReturn($isAllowed); + $this->assertEquals($url, $this->urlGenerator->getUrl(new \Magento\Framework\Object())); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Grid/Row/UrlGeneratorTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Grid/Row/UrlGeneratorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6d237d96e64dd7ef1f71961f763cd002eb17ea22 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Grid/Row/UrlGeneratorTest.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Invoice\Grid\Row; + +class UrlGeneratorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Model\Order\Grid\Row\UrlGenerator + */ + protected $urlGenerator; + /** + * @var \Magento\Backend\Model\UrlInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $urlMock; + /** + * @var \Magento\Framework\AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $authorizationMock; + + public function setUp() + { + $this->urlMock = $this->getMockForAbstractClass( + 'Magento\Backend\Model\UrlInterface', + [], + '', + false, + false, + true, + [] + ); + $this->authorizationMock = $this->getMockForAbstractClass( + 'Magento\Framework\AuthorizationInterface', + [], + '', + false, + false, + true, + [] + ); + $this->urlGenerator = new \Magento\Sales\Model\Order\Invoice\Grid\Row\UrlGenerator( + $this->urlMock, + $this->authorizationMock, + [ + 'path' => 'path' + ] + ); + } + + /** + * Provides permission for url generation + * + * @return array + */ + public function permissionProvider() + { + return [ + [true, null], + [false, false] + ]; + } + + /** + * @param bool $isAllowed + * @param null|bool $url + * @dataProvider permissionProvider + */ + public function testGetUrl($isAllowed, $url) + { + $this->authorizationMock->expects($this->once()) + ->method('isAllowed') + ->with('Magento_Sales::sales_invoice', null) + ->willReturn($isAllowed); + $this->assertEquals($url, $this->urlGenerator->getUrl(new \Magento\Framework\Object())); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/ItemTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8e4abcc37683fc75b5a07ff063bdcee55cee1695 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/ItemTest.php @@ -0,0 +1,233 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Model\Order\Invoice; + +class ItemTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManager; + /** + * @var \Magento\Sales\Model\Order\Invoice\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $item; + /** + * @var \Magento\Sales\Model\Order\ItemFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemFactoryMock; + /** + * @var \Magento\Sales\Model\Order\Invoice|\PHPUnit_Framework_MockObject_MockObject + */ + protected $invoiceMock; + /** + * @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderMock; + /** + * @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderItemMock; + + public function setUp() + { + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->orderItemFactoryMock = $this->getMock( + 'Magento\Sales\Model\Order\ItemFactory', + ['create'], + [], + '', + false + ); + $this->invoiceMock = $this->getMock( + 'Magento\Sales\Model\Order\Invoice', + [], + [], + '', + false + ); + $this->orderMock = $this->getMock( + 'Magento\Sales\Model\Order', + [], + [], + '', + false + ); + $this->orderItemMock = $this->getMock( + 'Magento\Sales\Model\Order\Item', + [ + 'load', 'isDummy', 'getIsQtyDecimal', 'getQtyToInvoice', 'getQtyInvoiced', 'getTaxInvoiced', + 'getBaseTaxInvoiced', 'getHiddenTaxInvoiced', 'getBaseHiddenTaxInvoiced', 'getDiscountInvoiced', + 'getBaseDiscountInvoiced', 'getRowInvoiced', 'getBaseRowInvoiced', 'setQtyInvoiced', 'setTaxInvoiced', + 'setBaseTaxInvoiced', 'setHiddenTaxInvoiced', 'setBaseHiddenTaxInvoiced', 'setDiscountInvoiced', + 'setBaseDiscountInvoiced', 'setRowInvoiced', 'setBaseRowInvoiced', 'getQtyOrdered', 'getRowTotal', + 'getBaseRowTotal', 'getRowTotalInclTax', 'getBaseRowTotalInclTax' + ], + [], + '', + false + ); + $this->item = $this->objectManager->getObject( + 'Magento\Sales\Model\Order\Invoice\Item', + [ + 'orderItemFactory' => $this->orderItemFactoryMock + ] + ); + } + + public function testGetOrderItemFromOrder() + { + $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); + $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock); + $this->item->setInvoice($this->invoiceMock); + $this->item->setOrderItemId(1); + $this->assertEquals($this->orderItemMock, $this->item->getOrderItem()); + } + + public function testGetOrderItemFromFactory() + { + $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturn($this->orderItemMock); + $this->item->setOrderItemId(1); + $this->assertEquals($this->orderItemMock, $this->item->getOrderItem()); + } + + public function testSetQty() + { + $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn(true); + $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(2); + $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(true); + $this->item->setOrderItemId(1); + $this->assertEquals($this->item->setQty(3), $this->item); + } + + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage We found an invalid quantity to invoice item "Item Name". + */ + public function testSetQtyWrongQty() + { + $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn(true); + $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(2); + $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false); + $this->item->setOrderItemId(1); + $this->item->setName('Item Name'); + $this->assertEquals($this->item->setQty(3), $this->item); + } + + public function testRegister() + { + $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getHiddenTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseHiddenTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('setQtyInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setTaxInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseTaxInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setHiddenTaxInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseHiddenTaxInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setDiscountInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseDiscountInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setRowInvoiced')->with(2)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseRowInvoiced')->with(2)->willReturnSelf(); + $this->item->setData( + [ + 'order_item_id' => 1, + 'qty' => 1, + 'tax_amount' => 1, + 'base_tax_amount' => 1, + 'hidden_tax_amount' => 1, + 'base_hidden_tax_amount' => 1, + 'discount_amount' => 1, + 'base_discount_amount' => 1, + 'row_total' => 1, + 'base_row_total' => 1 + ] + ); + $this->assertEquals($this->item->register(), $this->item); + } + + public function testCancel() + { + $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getHiddenTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseHiddenTaxInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('setQtyInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setTaxInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseTaxInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setHiddenTaxInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseHiddenTaxInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setDiscountInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseDiscountInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setRowInvoiced')->with(0)->willReturnSelf(); + $this->orderItemMock->expects($this->once())->method('setBaseRowInvoiced')->with(0)->willReturnSelf(); + $this->item->setData( + [ + 'order_item_id' => 1, + 'qty' => 1, + 'tax_amount' => 1, + 'base_tax_amount' => 1, + 'hidden_tax_amount' => 1, + 'base_hidden_tax_amount' => 1, + 'discount_amount' => 1, + 'base_discount_amount' => 1, + 'row_total' => 1, + 'base_row_total' => 1 + ] + ); + $this->assertEquals($this->item->cancel(), $this->item); + } + + public function testCalcRowTotal() + { + $this->item->setData([ + 'order_item_id' => 1, + 'qty' => 2 + ]); + $this->item->setInvoice($this->invoiceMock); + $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); + $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock); + $this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2); + $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2); + $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1); + $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0); + $this->invoiceMock->expects($this->exactly(4)) + ->method('roundPrice') + ->willReturnMap([ + [2, 'regular', false, 2], + [2, 'base', false, 2], + [2, 'including', false, 2], + [2, 'including_base', false, 2], + ]); + $this->assertEquals($this->item->calcRowTotal(), $this->item); + } +} diff --git a/dev/tests/integration/etc/install-config-mysql.php.dist b/dev/tests/integration/etc/install-config-mysql.php.dist index 0f5adb4727c5fecff8c195f6c70d25fb7b0cee0a..391e1a7679b00c152b165b379be8bd5d9ea508bb 100644 --- a/dev/tests/integration/etc/install-config-mysql.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.php.dist @@ -7,7 +7,7 @@ return [ 'db_host' => 'localhost', 'db_user' => 'root', - 'db_pass' => 'root', + 'db_pass' => '', 'db_name' => 'magento_integration_tests', 'db_prefix' => '', 'backend_frontname' => 'backend',