diff --git a/app/code/Magento/CatalogInventory/Model/Stock/Status.php b/app/code/Magento/CatalogInventory/Model/Stock/Status.php index 50e58e5b756f8fa14ebb608f5c59828ab64901f9..b375da3434e3f2a02d7dfa00265a7dbe2157fa02 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock/Status.php +++ b/app/code/Magento/CatalogInventory/Model/Stock/Status.php @@ -100,7 +100,7 @@ class Status extends AbstractExtensibleModel implements StockStatusInterface */ public function getStockId() { - return $this->getData(self::KEY_WEBSITE_ID); + return $this->getData(self::KEY_STOCK_ID); } /** diff --git a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php index c6ef3aac3ba7e667be7edf52d64ddd8a5eddd0fb..04d347ec237a9435964a5f4fcce784708c4365a4 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php @@ -7,6 +7,7 @@ namespace Magento\Checkout\Test\Unit\Model; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase { @@ -70,10 +71,38 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase */ protected $model; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cartExtensionFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $cartExtensionMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingMock; + protected function setUp() { - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->paymentMethodManagementMock = $this->getMock(\Magento\Quote\Api\PaymentMethodManagementInterface::class); $this->paymentDetailsFactoryMock = $this->getMock( \Magento\Checkout\Model\PaymentDetailsFactory::class, @@ -96,21 +125,6 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase $this->scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->totalsCollectorMock = $this->getMock(\Magento\Quote\Model\Quote\TotalsCollector::class, [], [], '', false); - $this->model = $objectManager->getObject( - \Magento\Checkout\Model\ShippingInformationManagement::class, - [ - 'paymentMethodManagement' => $this->paymentMethodManagementMock, - 'paymentDetailsFactory' => $this->paymentDetailsFactoryMock, - 'cartTotalsRepository' => $this->cartTotalsRepositoryMock, - 'quoteRepository' => $this->quoteRepositoryMock, - 'addressValidator' => $this->addressValidatorMock, - 'logger' => $this->loggerMock, - 'addressRepository' => $this->addressRepositoryMock, - 'scopeConfig' => $this->scopeConfigMock, - 'totalsCollector' => $this->totalsCollectorMock - ] - ); - $this->shippingAddressMock = $this->getMock( \Magento\Quote\Model\Quote\Address::class, [ @@ -144,39 +158,40 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase 'getStoreId', 'setShippingAddress', 'getShippingAddress', - 'collectTotals' + 'collectTotals', + 'getExtensionAttributes', + 'setExtensionAttributes', + 'setBillingAddress' ], [], '', false ); - } - - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable. - */ - public function testSaveAddressInformationIfCartIsVirtual() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); - - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->model->saveAddressInformation($cartId, $addressInformationMock); + $this->shippingAssignmentFactoryMock = + $this->getMock(\Magento\Quote\Model\ShippingAssignmentFactory::class, ['create'], [], '', false); + $this->cartExtensionFactoryMock = + $this->getMock(\Magento\Quote\Api\Data\CartExtensionInterfaceFactory::class, ['create'], [], '', false); + $this->shippingFactoryMock = + $this->getMock(\Magento\Quote\Model\ShippingFactory::class, ['create'], [], '', false); + + $this->prepareObjectManager([ + [\Magento\Quote\Model\ShippingAssignmentFactory::class, $this->shippingAssignmentFactoryMock], + [\Magento\Quote\Api\Data\CartExtensionFactory::class, $this->cartExtensionFactoryMock], + [\Magento\Quote\Model\ShippingFactory::class, $this->shippingFactoryMock], + ]); + + $this->model = new \Magento\Checkout\Model\ShippingInformationManagement( + $this->paymentMethodManagementMock, + $this->paymentDetailsFactoryMock, + $this->cartTotalsRepositoryMock, + $this->quoteRepositoryMock, + $this->addressValidatorMock, + $this->loggerMock, + $this->addressRepositoryMock, + $this->scopeConfigMock, + $this->totalsCollectorMock + ); } /** @@ -185,19 +200,23 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase */ public function testSaveAddressInformationIfCartIsEmpty() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); + + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(0); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') @@ -208,468 +227,209 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception\StateException - * @expectedExceptionMessage Shipping address is not set + * @param string $shippingMethod */ - public function testSaveAddressInformationIfShippingAddressNotSet() + private function setShippingAssignmentsMocks($shippingMethod) { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null); - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); + $this->cartExtensionMock = $this->getMock( + \Magento\Quote\Api\Data\CartExtension::class, + ['getShippingAssignments', 'setShippingAssignments'], + [], + '', + false + ); + $this->cartExtensionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->cartExtensionMock); + $this->cartExtensionMock->expects($this->once())->method('getShippingAssignments')->willReturn(null); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $this->shippingAssignmentMock = $this->getMock( + \Magento\Quote\Model\ShippingAssignment::class, + [], + [], + '', + false + ); + $this->shippingAssignmentFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->shippingAssignmentMock); + $this->shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn(null); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->shippingMock = $this->getMock(\Magento\Quote\Model\Shipping::class, [], [], '', false); + $this->shippingFactoryMock->expects($this->once())->method('create')->willReturn($this->shippingMock); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') + $this->shippingMock->expects($this->once()) + ->method('setAddress') ->with($this->shippingAddressMock) ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->shippingMock->expects($this->once())->method('setMethod')->with($shippingMethod)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) + $this->shippingAssignmentMock->expects($this->once()) + ->method('setShipping') + ->with($this->shippingMock) ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(false); - $this->model->saveAddressInformation($cartId, $addressInformationMock); - } - - /** - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Unable to save address. Please check input data. - */ - public function testSaveAddressInformationThrowExceptionWhileAddressSaving() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 100; - $carrierCode = 'carrier_code'; - $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $exception = new \Exception(); - - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); - $addressInformationMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); - $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) + $this->cartExtensionMock->expects($this->once()) + ->method('setShippingAssignments') + ->with([$this->shippingAssignmentMock]) ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->willThrowException($exception); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) + ->method('setExtensionAttributes') + ->with($this->cartExtensionMock) ->willReturnSelf(); - - $this->loggerMock->expects($this->once())->method('critical')->with($exception); - - $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Carrier with such method not found: carrier_code, shipping_method + * @expectedException \Magento\Framework\Exception\StateException + * @expectedExceptionMessage Shipping address is not set */ - public function testSaveAddressInformationIfCarrierCodeIsInvalid() + public function testSaveAddressInformationIfShippingAddressNotSet() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($this->quoteMock); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); + $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); - - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('getShippingRateByCode') - ->with($shippingMethod) - ->willReturn(false); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(null); $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Wrong minimum amount. + * @expectedExceptionMessage Unable to save shipping information. Please check input data. */ - public function testSaveAddressInformationIfMinimumAmountIsNotValid() + public function testSaveAddressInformationIfCanNotSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $storeId = 500; - $minAmountExceptionMessage = __('Wrong minimum amount.'); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(false); - $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); - - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once()) - ->method('getShippingRateByCode') - ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId) - ->willReturn($minAmountExceptionMessage); + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock) + ->willThrowException(new \Exception()); $this->model->saveAddressInformation($cartId, $addressInformationMock); } /** - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Unable to save shipping information. Please check input data. + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Carrier with such method not found: carrier_code, shipping_method */ - public function testSaveAddressInformationIfCanNotSaveQuote() + public function testSaveAddressInformationIfCarrierCodeIsInvalid() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - $exception = new \Exception(); - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(true); - $this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->shippingAddressMock); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('save')->willReturnSelf(); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); $this->shippingAddressMock->expects($this->once()) ->method('getShippingRateByCode') ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); - - $this->loggerMock->expects($this->once())->method('critical')->with($exception); + ->willReturn(false); $this->model->saveAddressInformation($cartId, $addressInformationMock); } public function testSaveAddressInformation() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $carrierCode = 'carrier_code'; $shippingMethod = 'shipping_method'; - $customerAddressId = 200; - - $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(5); - $this->quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(true); - $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); - $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->with(true)->willReturn(true); - $this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with($cartId) ->willReturn($this->quoteMock); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock); - - $addressInformationMock = $this->getMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class); $addressInformationMock->expects($this->once()) ->method('getShippingAddress') ->willReturn($this->shippingAddressMock); $addressInformationMock->expects($this->once())->method('getShippingCarrierCode')->willReturn($carrierCode); $addressInformationMock->expects($this->once())->method('getShippingMethodCode')->willReturn($shippingMethod); - $this->shippingAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - $this->shippingAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); - $this->shippingAddressMock->expects($this->once()) - ->method('getCustomerAddressId') - ->willReturn($customerAddressId); + $billingAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); + $addressInformationMock->expects($this->once())->method('getBillingAddress')->willReturn($billingAddress); + $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn('USA'); - $this->addressValidatorMock->expects($this->once()) - ->method('validate') - ->with($this->shippingAddressMock) - ->willReturn(true); + $this->setShippingAssignmentsMocks($carrierCode . '_' . $shippingMethod); - $this->quoteMock->expects($this->once()) - ->method('setShippingAddress') - ->with($this->shippingAddressMock) - ->willReturnSelf(); - $this->quoteMock->expects($this->exactly(2)) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); - $this->addressRepositoryMock->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); + $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(100); + $this->quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddress)->willReturnSelf(); + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->shippingAddressMock); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->quoteMock); - $this->shippingAddressMock->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true) - ->willReturnSelf(); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(1); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($this->quoteMock, $this->shippingAddressMock); $this->shippingAddressMock->expects($this->once())->method('getShippingMethod')->willReturn($shippingMethod); $this->shippingAddressMock->expects($this->once()) ->method('getShippingRateByCode') ->with($shippingMethod) - ->willReturn($this->getMock(\Magento\Quote\Model\Quote\Address\Rate::class, [], [], '', false)); + ->willReturn('rates'); $paymentDetailsMock = $this->getMock(\Magento\Checkout\Api\Data\PaymentDetailsInterface::class); $this->paymentDetailsFactoryMock->expects($this->once())->method('create')->willReturn($paymentDetailsMock); @@ -679,18 +439,38 @@ class ShippingInformationManagementTest extends \PHPUnit_Framework_TestCase ->method('getList') ->with($cartId) ->willReturn([$paymentMethodMock]); - $totalsMock = $this->getMock(\Magento\Quote\Api\Data\TotalsInterface::class); - $this->cartTotalsRepositoryMock->expects($this->once())->method('get')->with($cartId)->willReturn($totalsMock); + + $cartTotalsMock = $this->getMock(\Magento\Quote\Api\Data\TotalsInterface::class); + $this->cartTotalsRepositoryMock->expects($this->once()) + ->method('get') + ->with($cartId) + ->willReturn($cartTotalsMock); $paymentDetailsMock->expects($this->once()) ->method('setPaymentMethods') ->with([$paymentMethodMock]) ->willReturnSelf(); - $paymentDetailsMock->expects($this->once())->method('setTotals')->with($totalsMock)->willReturnSelf(); + $paymentDetailsMock->expects($this->once())->method('setTotals')->with()->willReturnSelf($cartTotalsMock); $this->assertEquals( $paymentDetailsMock, $this->model->saveAddressInformation($cartId, $addressInformationMock) ); } + + /** + * @param array $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php index 4e0922721de5c2413619a06bf827651d0640b123..32112ccdeb1aec053955226a49eb1838f8c4276b 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php @@ -245,15 +245,14 @@ class AbstractAddressTest extends \PHPUnit_Framework_TestCase */ public function testSetDataWithMultidimensionalArray() { - $this->markTestSkipped('Need to revert changes from MAGETWO-39106 and then modify this test.'); $expected = [ 'key' => 'value', - 'array' => 'value1', + 'street' => 'value1', ]; $key = [ 'key' => 'value', - 'array' => [ + 'street' => [ 'key1' => 'value1', ] ]; diff --git a/app/code/Magento/Paypal/Model/Config.php b/app/code/Magento/Paypal/Model/Config.php index 0af8b18355ec32b045c4e609137cb0eed7944373..100b5525ecb8885b1f8d832041213cb9b1db2822 100644 --- a/app/code/Magento/Paypal/Model/Config.php +++ b/app/code/Magento/Paypal/Model/Config.php @@ -866,7 +866,7 @@ class Config extends AbstractConfig */ public function getExpressCheckoutStartUrl($token) { - return sprintf('https://www.%spaypal.com/checkoutnow/2%s', + return sprintf('https://www.%spaypal.com/checkoutnow%s', $this->getValue('sandboxFlag') ? 'sandbox.' : '', '?token=' . urlencode($token)); } diff --git a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php index 3219b137b47750593a65cd73c3f4f42b51dfc0fa..81eaeed19fe15c4676bf4936a81b82aae954d8b1 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/BillingAddressManagementTest.php @@ -40,6 +40,11 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase */ protected $addressRepository; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingAssignmentMock; + /** * @return void */ @@ -59,6 +64,19 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase 'addressRepository' => $this->addressRepository ] ); + + $this->shippingAssignmentMock = $this->getMock( + \Magento\Quote\Model\ShippingAddressAssignment::class, + ['setAddress'], + [], + '', + false + ); + $this->objectManager->setBackwardCompatibleProperty( + $this->model, + 'shippingAddressAssignment', + $this->shippingAssignmentMock + ); } /** @@ -76,95 +94,44 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase $this->assertEquals($addressMock, $this->model->get('cartId')); } - /** - * @return void - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage error123 - */ - public function testSetAddressValidationFailed() - { - $this->markTestSkipped('MAGETWO-48531'); - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with('cartId') - ->will($this->returnValue($quoteMock)); - - $this->validatorMock->expects($this->once()) - ->method('validate') - ->will($this->throwException(new \Magento\Framework\Exception\NoSuchEntityException(__('error123')))); - - $this->model->assign('cartId', $address); - } - /** * @return void */ public function testSetAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 100; $useForShipping = true; $addressId = 1; - $customerAddressId = 10; $address = $this->getMock( \Magento\Quote\Model\Quote\Address::class, - ['setSaveInAddressBook', 'getCustomerAddressId', 'getSaveInAddressBook'], + ['getId'], [], '', false ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->willReturn($quoteMock); - $this->validatorMock->expects($this->once())->method('validate') - ->with($address) - ->willReturn(true); - - $address->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); - $address->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); - - $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class, [], [], '', false); - $this->addressRepository->expects($this->once()) - ->method('getById') - ->with($customerAddressId) - ->willReturn($customerAddressMock); - - $quoteBillingAddress = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false); - $quoteBillingAddress->expects($this->once())->method('getId')->will($this->returnValue($addressId)); - $quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($quoteBillingAddress); - $quoteBillingAddress->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - - $quoteShippingAddress = $this->getMock( - \Magento\Quote\Model\Quote\Address::class, - ['setSaveInAddressBook', 'setSameAsBilling', 'setCollectShippingRates', 'importCustomerAddressData'], + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['removeAddress', 'getBillingAddress', 'setBillingAddress', 'setDataChanges'], [], '', false ); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteShippingAddress); - $quoteShippingAddress->expects($this->once()) - ->method('importCustomerAddressData') - ->with($customerAddressMock) - ->willReturnSelf(); - $quoteShippingAddress->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $quoteBillingAddress->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); - $quoteMock->expects($this->once())->method('setBillingAddress')->with($quoteBillingAddress)->willReturnSelf(); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->willReturn($quoteMock); - $quoteShippingAddress->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); - $quoteShippingAddress->expects($this->once())->method('setCollectShippingRates')->with(true)->willReturnSelf(); + $address->expects($this->exactly(2))->method('getId')->willReturn($addressId); + $quoteMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($address); + $quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); - $quoteMock->expects($this->once())->method('setShippingAddress')->with($quoteShippingAddress); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); + $this->shippingAssignmentMock->expects($this->once()) + ->method('setAddress') + ->with($quoteMock, $address, $useForShipping); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $this->assertEquals($addressId, $this->model->assign($cartId, $address, $useForShipping)); @@ -177,27 +144,45 @@ class BillingAddressManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetAddressWithInabilityToSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); - $address = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false, false); + $cartId = 100; + $addressId = 1; + + $address = $this->getMock( + \Magento\Quote\Model\Quote\Address::class, + ['getId'], + [], + '', + false + ); + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['removeAddress', 'getBillingAddress', 'setBillingAddress', 'setDataChanges'], + [], + '', + false + ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') - ->with('cartId') - ->will($this->returnValue($quoteMock)); + ->with($cartId) + ->willReturn($quoteMock); + + $address->expects($this->once())->method('getId')->willReturn($addressId); + $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($address); + $quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address)->willReturnSelf(); + $quoteMock->expects($this->once())->method('setDataChanges')->with(1)->willReturnSelf(); - $this->validatorMock->expects($this->once())->method('validate') - ->with($address) - ->will($this->returnValue(true)); + $this->shippingAssignmentMock->expects($this->once()) + ->method('setAddress') + ->with($quoteMock, $address, false); - $quoteMock->expects($this->once())->method('setBillingAddress')->with($address); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); $this->quoteRepositoryMock->expects($this->once()) ->method('save') ->with($quoteMock) ->willThrowException( new \Exception('Some DB Error') ); - $this->model->assign('cartId', $address); + $this->model->assign($cartId, $address); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php index 76c3766d1f2481ba4251540dfcb2c084d435a0b7..dae3d56aa04b093c76d33f671606e2acfedb57af 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php @@ -30,7 +30,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $dataMock; + protected $itemMock; /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -58,6 +58,11 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $shippingAddressMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $optionsProcessorMock; + /** * @return void */ @@ -67,7 +72,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $this->productRepositoryMock = $this->getMock(\Magento\Catalog\Api\ProductRepositoryInterface::class); $this->itemDataFactoryMock = $this->getMock(\Magento\Quote\Api\Data\CartItemInterfaceFactory::class, ['create'], [], '', false); - $this->dataMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); + $this->itemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); $this->quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); $methods = ['getId', 'getSku', 'getQty', 'setData', '__wakeUp', 'getProduct', 'addProduct']; @@ -88,6 +93,20 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase false ); + $this->optionsProcessorMock = $this->getMock( + \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor::class, + [], + [], + '', + false + ); + $this->prepareObjectManager([ + [ + \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor::class, + $this->optionsProcessorMock + ] + ]); + $this->repository = new \Magento\Quote\Model\Quote\Item\Repository( $this->quoteRepositoryMock, $this->productRepositoryMock, @@ -96,395 +115,40 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase ); } - /** - * @param null|string|bool|int|float $value - * @return void - * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Invalid value of - * @dataProvider addItemWithInvalidQtyDataProvider - */ - public function testSaveItemWithInvalidQty($value) - { - $this->markTestSkipped('MAGETWO-48531'); - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue($value)); - $this->repository->save($this->dataMock); - } - - /** - * @return array - */ - public function addItemWithInvalidQtyDataProvider() - { - return [ - ['string'], - [0], - [''], - [null], - [-12], - [false], - [-13.1], - ]; - } - - /** - * @return void - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Please specify all the required information. - */ - public function testSaveCouldNotAddProduct() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn('Please specify all the required information.'); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteRepositoryMock->expects($this->never())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->repository->save($this->dataMock); - } - - /** - * @return void - * @expectedException \Magento\Framework\Exception\CouldNotSaveException - * @expectedExceptionMessage Could not save quote - */ - public function testSaveCouldNotSaveException() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $exceptionMessage = 'Could not save quote'; - $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->repository->save($this->dataMock); - } - /** * @return void */ public function testSave() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock - ->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $itemId = 20; - public function testSaveWithCustomOption() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 13; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock->expects($this->once()) - ->method('addProduct') - ->with($this->productMock, $buyRequest) - ->willReturn($this->productMock); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $this->quoteMock->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId'); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getItems', 'setItems', 'collectTotals', 'getLastAddedItem'], + [], + '', + false + ); - /** - * @return void - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Cart 11 doesn't contain item 5 - */ - public function testUpdateItemWithInvalidQuoteItem() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); + $this->itemMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue(false)); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); + ->method('getActive') + ->with($cartId) + ->willReturn($quoteMock); - $this->repository->save($this->dataMock); - } + $quoteMock->expects($this->once())->method('getItems')->willReturn([]); + $quoteMock->expects($this->once()) + ->method('setItems') + ->with([$this->itemMock]) + ->willReturnSelf(); - /** - * @return void - * @expectedException \Magento\Framework\Exception\CouldNotSaveException - * @expectedExceptionMessage Could not save quote - */ - public function testUpdateItemWithCouldNotSaveException() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock - ->expects($this->never()) - ->method('getAllItems'); - $this->quoteItemMock->expects($this->never())->method('getId'); - $exceptionMessage = 'Could not save quote'; - $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once()) - ->method('save') - ->with($this->quoteMock) - ->willThrowException($exception); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->repository->save($this->dataMock); - } + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); - /** - * @return void - */ - public function testUpdateItemQty() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $this->dataMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getId')->willReturn($itemId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->quoteItemMock->expects($this->never())->method('setData'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteItemMock->expects($this->never())->method('addProduct'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId')->willReturn($itemId); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $buyRequest->expects($this->once()) - ->method('setData') - ->with('qty', '12'); - $this->quoteMock->expects($this->once()) - ->method('updateItem') - ->with($itemId, $buyRequest) - ->willReturn($this->dataMock); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); - } + $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $quoteMock->expects($this->once())->method('getLastAddedItem')->willReturn($itemId); - /** - * @return void - */ - public function testUpdateItemOptions() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 11; - $itemId = 5; - $buyRequest = $this->getMock(\Magento\Framework\DataObject::class, [], [], '', false); - $cartItemProcessorMock = $this->getMock(\Magento\Quote\Model\Quote\Item\CartItemProcessorInterface::class); - $this->repository = new \Magento\Quote\Model\Quote\Item\Repository( - $this->quoteRepositoryMock, - $this->productRepositoryMock, - $this->itemDataFactoryMock, - ['simple' => $cartItemProcessorMock, 'custom_options' => $this->customOptionProcessor] - ); - $requestMock = $this->getMock(\Magento\Framework\DataObject::class, ['setQty', 'getData'], [], '', false); - $cartItemProcessorMock->expects($this->once())->method('convertToBuyRequest')->willReturn($requestMock); - $cartItemProcessorMock - ->expects($this->once()) - ->method('processOptions') - ->willReturn($this->quoteItemMock); - $requestMock->expects($this->once())->method('setQty')->with(12)->willReturnSelf(); - $requestMock->expects($this->once()) - ->method('getData') - ->willReturn([]); - $this->quoteMock - ->expects($this->once()) - ->method('updateItem') - ->with($itemId, $buyRequest) - ->willReturn($this->quoteItemMock); - $this->dataMock->expects($this->any())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock); - $this->productMock->expects($this->once())->method('getTypeId')->willReturn('simple'); - $this->productRepositoryMock - ->expects($this->never())->method('get'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->shippingAddressMock); - $this->shippingAddressMock->expects($this->once()) - ->method('setCollectShippingRates') - ->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getAllItems') - ->willReturn([$this->quoteItemMock]); - $this->quoteItemMock->expects($this->any())->method('getId')->willReturn($itemId); - $this->quoteItemMock->expects($this->any())->method('getQty')->willReturn(12); - $this->customOptionProcessor->expects($this->once()) - ->method('convertToBuyRequest') - ->with($this->dataMock) - ->willReturn($buyRequest); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + $this->assertEquals($itemId, $this->repository->save($this->itemMock)); } /** @@ -512,16 +176,20 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase */ public function testDeleteWithCouldNotSaveException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 11; $itemId = 5; $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + ->method('getActive') + ->with($cartId) + ->willReturn($this->quoteMock); $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + ->method('getItemById') + ->with($itemId) + ->willReturn($this->quoteItemMock); $this->quoteMock->expects($this->once()) - ->method('removeItem')->with($itemId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + ->method('removeItem') + ->with($itemId) + ->willReturn($this->quoteMock); $exceptionMessage = 'Could not remove item from quote'; $exception = new \Magento\Framework\Exception\CouldNotSaveException(__($exceptionMessage)); $this->quoteRepositoryMock->expects($this->once()) @@ -537,13 +205,23 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase */ public function testGetList() { - $this->markTestSkipped('MAGETWO-48531'); + $productType = 'type'; $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('getActive') ->with(33) ->will($this->returnValue($quoteMock)); $itemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false); - $quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); + $quoteMock->expects($this->once())->method('getAllVisibleItems')->will($this->returnValue([$itemMock])); + $itemMock->expects($this->once())->method('getProductType')->willReturn($productType); + + $this->optionsProcessorMock->expects($this->once()) + ->method('addProductOptions') + ->with($productType, $itemMock) + ->willReturn($itemMock); + $this->optionsProcessorMock->expects($this->once()) + ->method('applyCustomOptions') + ->with($itemMock) + ->willReturn($itemMock); $this->assertEquals([$itemMock], $this->repository->getList(33)); } @@ -553,17 +231,35 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase */ public function testDeleteById() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 11; $itemId = 5; $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + ->method('getActive') + ->with($cartId) + ->willReturn($this->quoteMock); $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + ->method('getItemById') + ->with($itemId) + ->willReturn($this->quoteItemMock); $this->quoteMock->expects($this->once())->method('removeItem'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); $this->assertTrue($this->repository->deleteById($cartId, $itemId)); } + + /** + * @param array $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php index 2ba9aaa751e4d4d58107f2dedd151d93c5a1ea3a..9d75c219e697877f94e5932777a4536a08ded08e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteAddressValidatorTest.php @@ -96,10 +96,10 @@ class QuoteAddressValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidateInvalidAddress() { - $this->markTestSkipped('MAGETWO-48531'); $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); $this->customerRepositoryMock->expects($this->never())->method('getById'); - $address->expects($this->atLeastOnce())->method('getId')->willReturn(101); + $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn(101); + $address->expects($this->once())->method('getId')->willReturn(101); $this->addressRepositoryMock->expects($this->once())->method('getById') ->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException()); @@ -118,70 +118,23 @@ class QuoteAddressValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->model->validate($address)); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Invalid address id 100 - */ - public function testValidateWithAddressOfOtherCustomer() - { - $this->markTestSkipped('MAGETWO-48531'); - $addressCustomer = 100; - $addressId = 100; - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); - - $this->customerRepositoryMock->expects($this->once())->method('getById')->with($addressCustomer) - ->willReturn($customerMock); - $this->addressRepositoryMock->expects($this->once())->method('getById')->willReturn($this->quoteAddressMock); - $customerMock->expects($this->once())->method('getId')->willReturn(42); - $address->expects($this->atLeastOnce())->method('getId')->willReturn($addressId); - $address->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($addressCustomer); - - $this->quoteAddressMock->expects($this->once())->method('getCustomerId')->willReturn(42); - $this->model->validate($address); - } - - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Invalid address id 42 - */ - public function testValidateWithInvalidCustomerAddressId() - { - $this->markTestSkipped('MAGETWO-48531'); - $customerAddressId = 42; - $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); - - $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn($customerAddressId); - $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerMock); - $customerMock->expects($this->once())->method('getAddresses')->willReturn([$customerAddress]); - $customerAddress->expects($this->once())->method('getId')->willReturn(43); - - $this->model->validate($address); - } - public function testValidateWithValidAddress() { - $this->markTestSkipped('MAGETWO-48531'); $addressCustomer = 100; - $addressId = 100; $customerAddressId = 42; $address = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $address->expects($this->atLeastOnce())->method('getId')->willReturn($addressId); $address->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($addressCustomer); $address->expects($this->atLeastOnce())->method('getCustomerAddressId')->willReturn($customerAddressId); $customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class); $customerAddress = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class); - $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($customerMock); + $this->customerRepositoryMock->expects($this->exactly(2))->method('getById')->willReturn($customerMock); $customerMock->expects($this->once())->method('getId')->willReturn($addressCustomer); $this->addressRepositoryMock->expects($this->once())->method('getById')->willReturn($this->quoteAddressMock); $this->quoteAddressMock->expects($this->any())->method('getCustomerId')->willReturn($addressCustomer); - $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerMock); $customerMock->expects($this->once())->method('getAddresses')->willReturn([$customerAddress]); $customerAddress->expects($this->once())->method('getId')->willReturn(42); diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php index 3bd838d9d4b75f0c8d0fe1ab7188883283e61b72..891eb108b224deb9a35bd05e7e57ae903fea243d 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepositoryTest.php @@ -11,6 +11,7 @@ use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\QuoteRepository\LoadHandler; +use Magento\Quote\Model\QuoteRepository\SaveHandler; use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory; /** @@ -63,6 +64,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase */ private $loadHandlerMock; + /** + * @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject + */ + private $saveHandlerMock; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -91,7 +97,9 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase 'setSharedStoreIds', 'save', 'delete', - 'getCustomerId' + 'getCustomerId', + 'getStoreId', + 'getData' ], [], '', @@ -136,10 +144,16 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase ); $this->loadHandlerMock = $this->getMock(LoadHandler::class, [], [], '', false); + $this->saveHandlerMock = $this->getMock(SaveHandler::class, [], [], '', false); + $reflection = new \ReflectionClass(get_class($this->model)); $reflectionProperty = $reflection->getProperty('loadHandler'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->model, $this->loadHandlerMock); + + $reflectionProperty = $reflection->getProperty('saveHandler'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $this->saveHandlerMock); } /** @@ -235,7 +249,6 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase public function testGetWithSharedStoreIds() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 16; $sharedStoreIds = [1, 2]; @@ -252,7 +265,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); } @@ -316,7 +333,6 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase */ public function testGetActiveWithExceptionByIsActive() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 15; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); @@ -330,12 +346,16 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(0); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->model->getActive($cartId); } public function testGetActive() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 15; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); @@ -347,15 +367,18 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase ->with($cartId) ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(1); + + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); - $this->assertEquals($this->quoteMock, $this->model->getActive($cartId)); $this->assertEquals($this->quoteMock, $this->model->getActive($cartId)); } public function testGetActiveWithSharedStoreIds() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 16; $sharedStoreIds = [1, 2]; @@ -371,15 +394,18 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase ->with($cartId) ->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(1); + + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); - $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds)); $this->assertEquals($this->quoteMock, $this->model->getActive($cartId, $sharedStoreIds)); } public function testGetActiveForCustomer() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 17; $customerId = 23; @@ -394,19 +420,50 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase $this->quoteMock->expects($this->exactly(2))->method('getId')->willReturn($cartId); $this->quoteMock->expects($this->exactly(2))->method('getIsActive')->willReturn(1); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + $this->assertEquals($this->quoteMock, $this->model->getActiveForCustomer($customerId)); $this->assertEquals($this->quoteMock, $this->model->getActiveForCustomer($customerId)); } public function testSave() { - $this->markTestSkipped('MAGETWO-48531'); + $cartId = 100; + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getId', 'getCustomerId', 'getStoreId', 'hasData', 'setData'], + [], + '', + false + ); + $quoteMock->expects($this->exactly(3))->method('getId')->willReturn($cartId); + $quoteMock->expects($this->once())->method('getCustomerId')->willReturn(2); + $quoteMock->expects($this->once())->method('getStoreId')->willReturn(5); + + $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); + $this->storeMock->expects($this->once())->method('getId')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); + $this->quoteMock->expects($this->once())->method('setSharedStoreIds'); $this->quoteMock->expects($this->once()) - ->method('save'); - $this->quoteMock->expects($this->exactly(1))->method('getId')->willReturn(1); - $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); + ->method('load') + ->with($cartId) + ->willReturn($this->storeMock); + $this->loadHandlerMock->expects($this->once()) + ->method('load') + ->with($this->quoteMock) + ->willReturn($this->quoteMock); + + $this->quoteMock->expects($this->once())->method('getData')->willReturn(['key' => 'value']); + + $quoteMock->expects($this->once())->method('hasData')->with('key')->willReturn(false); + $quoteMock->expects($this->once())->method('setData')->with('key', 'value')->willReturnSelf(); - $this->model->save($this->quoteMock); + $this->saveHandlerMock->expects($this->once())->method('save')->with($quoteMock)->willReturn($quoteMock); + $this->model->save($quoteMock); } public function testDelete() diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php index 09125c032872513c9d5bfb10401c89c36549bf81..abae7bae110e6521fbf7b708270eb32cb6792c69 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php @@ -50,6 +50,16 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase */ protected $totalsCollectorMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $addressRepository; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $amountErrorMessageMock; + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -66,7 +76,10 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase 'save', 'getId', 'getCustomerAddressId', - 'getSaveInAddressBook' + 'getSaveInAddressBook', + 'getSameAsBilling', + 'importCustomerAddressData', + 'setSaveInAddressBook', ], [], '', @@ -82,6 +95,22 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase '', false ); + $this->addressRepository = $this->getMock(\Magento\Customer\Api\AddressRepositoryInterface::class); + + $this->amountErrorMessageMock = $this->getMock( + \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class, + ['getMessage'], + [], + '', + false + ); + $this->prepareObjectManager([ + [ + \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class, + $this->amountErrorMessageMock + ] + ]); + $this->service = $this->objectManager->getObject( \Magento\Quote\Model\ShippingAddressManagement::class, [ @@ -89,7 +118,8 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase 'addressValidator' => $this->validatorMock, 'logger' => $this->getMock(\Psr\Log\LoggerInterface::class), 'scopeConfig' => $this->scopeConfigMock, - 'totalsCollector' => $this->totalsCollectorMock + 'totalsCollector' => $this->totalsCollectorMock, + 'addressRepository' => $this->addressRepository ] ); } @@ -114,34 +144,58 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase public function testSetAddress() { - $this->markTestSkipped('MAGETWO-48531'); $addressId = 1; - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); + $customerAddressId = 150; + + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with('cart867') - ->will($this->returnValue($quoteMock)); + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); $this->validatorMock->expects($this->once())->method('validate') ->with($this->quoteAddressMock) - ->will($this->returnValue(true)); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); - $this->quoteAddressMock->expects($this->once())->method('save')->willReturnSelf(); - $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); + ->willReturn(true); - $quoteMock->expects($this->any()) - ->method('setShippingAddress') - ->with($this->quoteAddressMock) + $quoteMock->expects($this->exactly(3))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) ->willReturnSelf(); - $quoteMock->expects($this->any()) - ->method('getShippingAddress') - ->will($this->returnValue($this->quoteAddressMock)); - $quoteMock->expects($this->once())->method('validateMinimumAmount')->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('save')->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); $this->assertEquals($addressId, $this->service->assign('cart867', $this->quoteAddressMock)); } @@ -174,52 +228,122 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetAddressWithInabilityToSaveQuote() { - $this->markTestSkipped('MAGETWO-48531'); $this->quoteAddressMock->expects($this->once())->method('save')->willThrowException( new \Exception('Unable to save address. Please check input data.') ); - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); + $customerAddressId = 150; + + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive') ->with('cart867') - ->will($this->returnValue($quoteMock)); + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); $this->validatorMock->expects($this->once())->method('validate') ->with($this->quoteAddressMock) - ->will($this->returnValue(true)); + ->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(true); + $this->service->assign('cart867', $this->quoteAddressMock); } /** * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Incorrect amount */ public function testSetAddressWithViolationOfMinimumAmount() { - $this->markTestSkipped('MAGETWO-48531'); - $storeId = 12; - $this->quoteAddressMock->expects($this->once())->method('save'); + $customerAddressId = 150; - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); - $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cart123') - ->will($this->returnValue($quoteMock)); + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getIsMultiShipping', 'isVirtual', 'validateMinimumAmount', 'setShippingAddress', 'getShippingAddress'], + [], + '', + false + ); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with('cart867') + ->willReturn($quoteMock); $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->quoteAddressMock); - $quoteMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); - $this->totalsCollectorMock - ->expects($this->once()) - ->method('collectAddressTotals') - ->with($quoteMock, $this->quoteAddressMock); - $this->scopeConfigMock->expects($this->once())->method('getValue') - ->with('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); - - $this->service->assign('cart123', $this->quoteAddressMock); + $quoteMock->expects($this->once()) + ->method('setShippingAddress') + ->with($this->quoteAddressMock) + ->willReturnSelf(); + + $customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class); + + $this->addressRepository->expects($this->once()) + ->method('getById') + ->with($customerAddressId) + ->willReturn($customerAddressMock); + + $this->validatorMock->expects($this->once())->method('validate') + ->with($this->quoteAddressMock) + ->willReturn(true); + + $this->quoteAddressMock->expects($this->once())->method('getSaveInAddressBook')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getSameAsBilling')->willReturn(1); + $this->quoteAddressMock->expects($this->once())->method('getCustomerAddressId')->willReturn($customerAddressId); + + $quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($this->quoteAddressMock); + $this->quoteAddressMock->expects($this->once()) + ->method('importCustomerAddressData') + ->with($customerAddressMock) + ->willReturnSelf(); + + $this->quoteAddressMock->expects($this->once())->method('setSameAsBilling')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once())->method('setSaveInAddressBook')->with(1)->willReturnSelf(); + $this->quoteAddressMock->expects($this->once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + + $this->amountErrorMessageMock->expects($this->once()) + ->method('getMessage') + ->willReturn(__('Incorrect amount')); + $quoteMock->expects($this->once())->method('getIsMultiShipping')->willReturn(false); + $quoteMock->expects($this->once())->method('validateMinimumAmount')->with(false)->willReturn(false); + + $this->service->assign('cart867', $this->quoteAddressMock); } public function testGetAddress() @@ -251,4 +375,20 @@ class ShippingAddressManagementTest extends \PHPUnit_Framework_TestCase $this->service->get('cartId'); } + + /** + * @param $map + */ + private function prepareObjectManager($map) + { + $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); + $objectManagerMock->expects($this->any())->method('getInstance')->willReturnSelf(); + $objectManagerMock->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + $reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class); + $reflectionProperty = $reflectionClass->getProperty('_instance'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($objectManagerMock); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php index 5f31b7b1219ce7bebaa821e78212556392397193..bb0eab1d8aed263448502575d1bf630d9bf6129b 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php @@ -311,12 +311,13 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetMethodWithInputException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(0)); $this->quote->expects($this->never())->method('isVirtual'); @@ -329,13 +330,14 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetMethodWithVirtualProduct() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(true)); @@ -348,12 +350,13 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetMethodWithoutShippingAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) @@ -363,60 +366,34 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase $this->model->set($cartId, $carrierCode, $methodCode); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - * @expectedExceptionMessage Carrier with such method not found: 34, 56 - */ - public function testSetMethodWithNotFoundMethod() - { - $this->markTestSkipped('MAGETWO-48531'); - $cartId = 12; - $carrierCode = 34; - $methodCode = 56; - $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); - $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); - $this->shippingAddress->expects($this->once()) - ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddress->expects($this->once()) - ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(false)); - $this->shippingAddress->expects($this->never())->method('save'); - - $this->model->set($cartId, $carrierCode, $methodCode); - } - /** * @expectedException \Magento\Framework\Exception\CouldNotSaveException * @expectedExceptionMessage Cannot set shipping method. Custom Error */ public function testSetMethodWithCouldNotSaveException() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); - $this->shippingAddress->expects($this->once()) - ->method('getCountryId')->will($this->returnValue($countryId)); + ->method('getShippingAddress') + ->willReturn($this->shippingAddress); $this->shippingAddress->expects($this->once()) - ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); + ->method('getCountryId') + ->willReturn($countryId); $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(true)); + ->method('setShippingMethod') + ->with($carrierCode . '_' . $methodCode); $exception = new \Exception('Custom Error'); - $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); + $this->quote->expects($this->once())->method('collectTotals')->willReturnSelf(); $this->quoteRepository->expects($this->once()) ->method('save') ->with($this->quote) @@ -431,16 +408,18 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase */ public function testSetMethodWithoutAddress() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + ->method('getShippingAddress') + ->willReturn($this->shippingAddress); $this->shippingAddress->expects($this->once())->method('getCountryId'); $this->model->set($cartId, $carrierCode, $methodCode); @@ -448,13 +427,14 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase public function testSetMethod() { - $this->markTestSkipped('MAGETWO-48531'); $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepository->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quoteRepository->expects($this->exactly(2)) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quote->expects($this->once()) @@ -463,8 +443,6 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase ->method('getCountryId')->will($this->returnValue($countryId)); $this->shippingAddress->expects($this->once()) ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddress->expects($this->once()) - ->method('getShippingRateByCode')->will($this->returnValue(true)); $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); $this->quoteRepository->expects($this->once())->method('save')->with($this->quote); diff --git a/app/code/Magento/Vault/Setup/UpgradeData.php b/app/code/Magento/Vault/Setup/UpgradeData.php index 3925aaa6c94fb39f512ce8e44e66f5a74663093d..757b5f4d3167cb00254e8f2ef20fad3addc1cb27 100644 --- a/app/code/Magento/Vault/Setup/UpgradeData.php +++ b/app/code/Magento/Vault/Setup/UpgradeData.php @@ -5,6 +5,9 @@ */ namespace Magento\Vault\Setup; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; @@ -16,13 +19,18 @@ use Magento\Vault\Model\CreditCardTokenFactory; */ class UpgradeData implements UpgradeDataInterface { + /** + * @var AdapterInterface + */ + private $connection; + /** * @inheritdoc */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - $connection = $setup->getConnection(); + $connection = $this->getConnection(); // data update for Vault module < 2.0.1 if (version_compare($context->getVersion(), '2.0.1', '<')) { @@ -59,4 +67,23 @@ class UpgradeData implements UpgradeDataInterface $setup->endSetup(); } + + /** + * Tries to get connection for scalable sales DB, otherwise returns default connection + * @return AdapterInterface + */ + private function getConnection() + { + if ($this->connection === null) { + /** @var ResourceConnection $conn */ + $conn = ObjectManager::getInstance()->get(ResourceConnection::class); + try { + $this->connection = $conn->getConnectionByName('sales'); + } catch (\DomainException $e) { + $this->connection = $conn->getConnection(); + } + } + + return $this->connection; + } } diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php index 070de886077ffd60f74c2e380f6459089bdcc078..0b8e468b014d689db4b61f6884b69adf51e0ae2c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php @@ -51,7 +51,6 @@ class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAb */ public function testRemoveChild() { - $this->markTestSkipped('must be unskipped after fixing bug about wrong saving bundle option price'); $productSku = 'bundle-product'; $childSku = 'simple'; $optionIds = $this->getProductOptions(3); diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php index 47e6db6a27e0bdce53e7aded9c11ef0c9fe41ce6..63b5b76a8d15d968d1105e94c873f54561a80092 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php @@ -144,16 +144,12 @@ class ProductServiceTest extends WebapiAbstract */ public function testUpdateBundleModifyExistingOptionOnly() { - $this->markTestSkipped('Skipped, due to MAGETWO-46857'); $bundleProduct = $this->createFixedPriceBundleProduct(); $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); - $existingSelectionId = $bundleProductOptions[0]['product_links'][0]['id']; - //Change the type of existing option $bundleProductOptions[0]['type'] = 'select'; - //unset product_links attribute - unset($bundleProductOptions[0]['product_links']); + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); $updatedProduct = $this->saveProduct($bundleProduct); @@ -162,7 +158,6 @@ class ProductServiceTest extends WebapiAbstract $this->assertEquals('select', $bundleOptions[0]['type']); $this->assertEquals('simple', $bundleOptions[0]['product_links'][0]['sku']); $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['qty']); - $this->assertEquals($existingSelectionId, $bundleOptions[0]['product_links'][0]['id']); $this->assertEquals(20, $bundleOptions[0]['product_links'][0]['price']); $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['price_type']); } diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php index 9828d85fb5de0ff6ce0ebe328692d41e8712e5dc..3e03ea49771c938170940316f9026f715c966c23 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryLinkRepositoryTest.php @@ -27,8 +27,6 @@ class CategoryLinkRepositoryTest extends WebapiAbstract */ public function testSave($productLink, $productId, $productPosition = 0) { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX @@ -71,8 +69,6 @@ class CategoryLinkRepositoryTest extends WebapiAbstract */ public function testUpdateProduct($productLink, $productId, $productPosition = 0) { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX @@ -111,8 +107,6 @@ class CategoryLinkRepositoryTest extends WebapiAbstract */ public function testDelete() { - $this->checkIfTestable(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH_SUFFIX . '/' . $this->categoryId . @@ -153,20 +147,4 @@ class CategoryLinkRepositoryTest extends WebapiAbstract return false; } } - - /** - * MAGETWO-41737: Skip tests when the flag 'custom_categories_sort' is up - * @return void - */ - private function checkIfTestable() - { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ - $config = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class); - - if ($config->getValue('catalog/custom_categories_sort') == 1) { - $this->markTestSkipped('Will be fixed after MAGETWO-41737'); - } - } } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php index c7227d4ecca16daa0b7757e957c9d6adef301083..3bf5d592fef3cef2942174cf59212442cb8d8a29 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -54,7 +54,6 @@ class GuestCartTotalRepositoryTest extends WebapiAbstract */ public function testGetTotals() { - $this->markTestSkipped('Will be fixed after MAGETWO-35573'); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); $quote->load('test_order_1', 'reserved_order_id'); @@ -86,6 +85,7 @@ class GuestCartTotalRepositoryTest extends WebapiAbstract Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), + Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], ]; @@ -93,7 +93,17 @@ class GuestCartTotalRepositoryTest extends WebapiAbstract $data = $this->formatTotalsData($data); - $this->assertEquals($data, $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData)); + $actual = $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData); + + unset($actual['items'][0]['options']); + unset($actual['weee_tax_applied_amount']); + + unset($actual['total_segments']); + if (array_key_exists('extension_attributes', $actual)) { + unset($actual['extension_attributes']); + } + + $this->assertEquals($data, $actual); } /** @@ -162,6 +172,7 @@ class GuestCartTotalRepositoryTest extends WebapiAbstract $item = array_shift($items); return [ + ItemTotals::KEY_ITEM_ID => $item->getItemId(), ItemTotals::KEY_PRICE => $item->getPrice(), ItemTotals::KEY_BASE_PRICE => $item->getBasePrice(), ItemTotals::KEY_QTY => $item->getQty(), @@ -178,6 +189,9 @@ class GuestCartTotalRepositoryTest extends WebapiAbstract ItemTotals::KEY_BASE_PRICE_INCL_TAX => $item->getBasePriceInclTax(), ItemTotals::KEY_ROW_TOTAL_INCL_TAX => $item->getRowTotalInclTax(), ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => $item->getBaseRowTotalInclTax(), + ItemTotals::KEY_WEEE_TAX_APPLIED_AMOUNT => $item->getWeeeTaxAppliedAmount(), + ItemTotals::KEY_WEEE_TAX_APPLIED => $item->getWeeeTaxApplied(), + ItemTotals::KEY_NAME => $item->getName(), ]; } } diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php index 8ab7c765409b564ac55224f5e56ff06d52eb1b83..941a27cdbb69907d89936fce4442d55224bf3ff0 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php @@ -78,7 +78,6 @@ class ShippingMethodManagementTest extends WebapiAbstract */ public function testGetListForMyCart() { - $this->markTestSkipped('Will be fixed after MAGETWO-35573'); $this->_markTestAsRestOnly(); $this->quote->load('test_order_1', 'reserved_order_id'); @@ -89,9 +88,9 @@ class ShippingMethodManagementTest extends WebapiAbstract ); $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ + /** @var \Magento\Quote\Model\ShippingMethodManagementInterface $shippingMethodManagementService */ $shippingMethodManagementService = $this->objectManager->create( - \Magento\Quote\Api\ShippingMethodManagementInterface::class + \Magento\Quote\Model\ShippingMethodManagementInterface::class ); $shippingMethodManagementService->set($this->quote->getId(), 'flatrate', 'flatrate'); diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php index d9f7bf1425c9663ab1b067436ce8348e873c1c34..8446c27d3d45ff60dee832290e6ade27999c621a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/CreditmemoCancelTest.php @@ -20,10 +20,11 @@ class CreditmemoCancelTest extends WebapiAbstract /** * @magentoApiDataFixture Magento/Sales/_files/creditmemo_with_list.php + * @expectedException \Exception + * @expectedExceptionMessage You can not cancel Credit Memo */ public function testCreditmemoCancel() { - $this->markTestSkipped('You can not cancel Credit Memo'); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection $creditmemoCollection */ @@ -44,7 +45,6 @@ class CreditmemoCancelTest extends WebapiAbstract ], ]; $requestData = ['id' => $creditmemo->getId()]; - $result = $this->_webApiCall($serviceInfo, $requestData); - $this->assertTrue($result); + $this->_webApiCall($serviceInfo, $requestData); } } diff --git a/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml index 97c11284d77c88194a5a5271e31ca7b91a4babf3..3e7550b9d784e3858bd9800e66b88b8c60326b1b 100644 --- a/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml @@ -95,9 +95,9 @@ </field> <field name="qty" xsi:type="string">1</field> <field name="cartItem" xsi:type="array"> - <item name="price" xsi:type="string">756</item> + <item name="price" xsi:type="string">755</item> <item name="qty" xsi:type="string">1</item> - <item name="subtotal" xsi:type="string">756</item> + <item name="subtotal" xsi:type="string">755</item> </field> </dataset> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml index 026b32c0219803432c69b250e786de07d2f5e13d..5fb85d4c4f0532244824289a2e14267b6679253a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductVirtual/CheckoutData.xml @@ -34,6 +34,11 @@ <dataset name="virtual_update_mini_shopping_cart"> <field name="qty" xsi:type="string">2</field> + <field name="cartItem" xsi:type="array"> + <item name="price" xsi:type="string">10</item> + <item name="qty" xsi:type="string">2</item> + <item name="subtotal" xsi:type="string">20</item> + </field> </dataset> </repository> </config> diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php index b171a7062e94297ad73bebf4da5e15bbc19b8511..1eb5ddf43fc5259e9252b15507bb91429df16c8c 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Sidebar/Item.php @@ -46,7 +46,7 @@ class Item extends Sidebar * * @var string */ - protected $price = '.product .price'; + protected $price = '.minicart-price .price'; /** * CSS selector for update button. diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php index ef7ac1fc55f329d7b61fab9a0895dca554943b08..2cf6d5ad87dfff1d9f5c96b9ed40414abb822d44 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php @@ -205,6 +205,8 @@ class Totals extends Block */ public function getDiscount() { + $this->waitForElementNotVisible($this->blockWaitElement); + $this->waitForElementVisible($this->discount, Locator::SELECTOR_CSS); $priceElement = $this->_rootElement->find($this->discount, Locator::SELECTOR_CSS); return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml index f64258b1de297587789b5f675f56a36fb04d89ae..30688723ae8edb8c83b761e89f2805f5dcdcd588 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml @@ -99,8 +99,8 @@ <data name="productsData/4" xsi:type="string">configurableProduct::default</data> <data name="productsData/5" xsi:type="string">bundleProduct::bundle_fixed_product</data> <data name="productsData/6" xsi:type="string">bundleProduct::bundle_dynamic_product</data> - <data name="cart/data/grand_total" xsi:type="string">2922.43</data> - <data name="cart/data/subtotal" xsi:type="string">2852.43</data> + <data name="cart/data/grand_total" xsi:type="string">3473.43</data> + <data name="cart/data/subtotal" xsi:type="string">3408.43</data> <constraint name="Magento\Checkout\Test\Constraint\AssertPriceInShoppingCart" /> <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> <constraint name="Magento\Checkout\Test\Constraint\AssertSubtotalInShoppingCart" /> diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml index f075312343c210b8f86f73d109e31b6f9e85a9f3..bb9f7a4ae03b19500b954e187a8765121579acf7 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml @@ -64,7 +64,7 @@ </field> <field name="qty" xsi:type="string">1</field> <field name="cartItem" xsi:type="array"> - <item name="price" xsi:type="string">120</item> + <item name="price" xsi:type="string">42</item> <item name="qty" xsi:type="string">1</item> <item name="subtotal" xsi:type="string">172</item> </field> diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml index 74abeeb6cb325f3e010f3270f693a065cc71ca0a..5170d8f9c54272eb0a2b92031efbb6110f71db83 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProduct/CheckoutData.xml @@ -73,8 +73,8 @@ </item> </field> <field name="cartItem" xsi:type="array"> - <item name="price" xsi:type="string">23</item> - <item name="subtotal" xsi:type="string">23</item> + <item name="price" xsi:type="string">25.43</item> + <item name="subtotal" xsi:type="string">25.43</item> </field> </dataset> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php index 501d3ec65dd743348ab02473aac355c043fd2412..9b15cfb39a30b0c23401005c4ae65e9804782fb1 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertInvoiceInInvoicesTab.php @@ -36,13 +36,13 @@ class AssertInvoiceInInvoicesTab extends AbstractConstraint $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $salesOrderView->getOrderForm()->openTab('invoices'); /** @var Grid $grid */ - $grid = $salesOrderView->getOrderForm()->getTab('invoices')->getGridBlock(); + $grid = $salesOrderView->getOrderInvoiceGrid(); $amount = $order->getPrice(); foreach ($ids['invoiceIds'] as $key => $invoiceId) { $filter = [ 'id' => $invoiceId, - 'amount_from' => $amount[$key]['grand_invoice_total'], - 'amount_to' => $amount[$key]['grand_invoice_total'], + 'grand_total_from' => $amount[$key]['grand_invoice_total'], + 'grand_total_to' => $amount[$key]['grand_invoice_total'], ]; $grid->search($filter); $filter['amount_from'] = number_format($amount[$key]['grand_invoice_total'], 2); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml index d5b7d99661806e4cf3f49f29575ab0c1100520a9..674b42732d2cd955db0e05b03ef79a8021492642 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/SalesOrderView.xml @@ -16,5 +16,6 @@ <block name="orderHistoryBlock" class="Magento\Sales\Test\Block\Adminhtml\Order\History" locator=".order-comments-history" strategy="css selector" /> <block name="informationBlock" class="Magento\Sales\Test\Block\Adminhtml\Order\View\Info" locator=".order-account-information" strategy="css selector" /> <block name="orderInfoBlock" class="Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info" locator="[data-ui-id='sales-order-tabs-tab-content-order-info']" strategy="css selector" /> + <block name="orderInvoiceGrid" class="Magento\Sales\Test\Block\Adminhtml\Invoice\Grid" locator="//div[contains(@data-bind, 'sales_order_view_invoice_grid.sales_order_view_invoice_grid')]" strategy="xpath" /> </page> </config> diff --git a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml index 89435ba2fb7f8f2829d7bc009c34f993ca6f103c..eeb0dd7ab12e9e33eec107f17d3678d4ec1827ad 100644 --- a/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml +++ b/dev/tests/functional/tests/app/Magento/Security/Test/TestCase/LockCustomerOnEditPageTest.xml @@ -14,7 +14,7 @@ <data name="customer/data/current_password" xsi:type="string">incorrect password</data> <data name="customer/data/password" xsi:type="string">123123^a</data> <data name="customer/data/password_confirmation" xsi:type="string">123123^a</data> - <data name="attempts" xsi:type="string">6</data> + <data name="attempts" xsi:type="string">7</data> <constraint name="Magento\Security\Test\Constraint\AssertCustomerIsLocked" /> </variation> </testCase> diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php deleted file mode 100644 index 22acb1197631580dba7245a1fbc39f13fd1b59dc..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * This test was moved to the separate file. - * Because of fixture applying order magentoAppIsolation -> magentoDataFixture -> magentoConfigFixture - * (https://wiki.magento.com/display/PAAS/Integration+Tests+Development+Guide - * #IntegrationTestsDevelopmentGuide-ApplyingAnnotations) - * config fixtures can't be applied before data fixture. - */ -namespace Magento\Catalog\Model\Category; - -use Magento\Catalog\Model\Category\CategoryImageTest\StubZendLogWriterStream; - -class CategoryImageTest extends \PHPUnit_Framework_TestCase -{ - /** @var int */ - protected $_oldLogActive; - - /** @var string */ - protected $_oldExceptionFile; - - /** @var string */ - protected $_oldWriterModel; - - protected function setUp() - { - $this->_oldLogActive = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Store\Model\StoreManagerInterface::class - )->getStore()->getConfig( - 'dev/log/active' - ); - $this->_oldExceptionFile = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Store\Model\StoreManagerInterface::class - )->getStore()->getConfig( - 'dev/log/exception_file' - ); - } - - protected function tearDown() - { - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class - )->setValue( - 'dev/log/active', - $this->_oldLogActive, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - $this->_oldLogActive = null; - - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class - )->setValue( - 'dev/log/exception_file', - $this->_oldExceptionFile, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - $this->_oldExceptionFile = null; - - $this->_oldWriterModel = null; - - /** - * @TODO: refactor this test - * Changing store configuration in such a way totally breaks the idea of application isolation. - * Class declaration in data fixture file is dumb too. - * Added a quick fix to be able run separate tests with "phpunit --filter testMethod" - */ - if (class_exists(\Magento\Catalog\Model\Category\CategoryImageTest\StubZendLogWriterStreamTest::class, false)) { - StubZendLogWriterStream::$exceptions = []; - } - } - - /** - * Test that there is no exception '$_FILES array is empty' in \Magento\Framework\File\Uploader::_setUploadFileId() - * if category image was not set - * - */ - public function testSaveCategoryWithoutImage() - { - $this->markTestSkipped('MAGETWO-15096'); - - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var $category \Magento\Catalog\Model\Category */ - $category = $objectManager->get(\Magento\Framework\Registry::class) - ->registry('_fixture/Magento\Catalog\Model\Category'); - $this->assertNotEmpty($category->getId()); - - foreach (StubZendLogWriterStream::$exceptions as $exception) { - $this->assertNotContains('$_FILES array is empty', $exception['message']); - } - } -} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php deleted file mode 100644 index 3915ad47b3b1c3108c001b7b80969600a09d92c5..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Category/CategoryImageTest/StubZendLogWriterStream.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Catalog\Model\Category\CategoryImageTest; - -\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class -)->setValue( - 'dev/log/active', - 1, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE -); - -\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\App\Config\MutableScopeConfigInterface::class -)->setValue( - 'dev/log/exception_file', - 'save_category_without_image.log', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE -); -class StubZendLogWriterStream extends \Zend_Log_Writer_Stream -{ - /** @var array */ - public static $exceptions = []; - - public function write($event) - { - self::$exceptions[] = $event; - - parent::write($event); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php index 83e0f352a68ea0e2bb02df78fe7ffba3fd3fdf91..a3e90819912f03a9413311600c7cd5cbcfddff60 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryTest.php @@ -275,6 +275,27 @@ class CategoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals('5', $category->getPosition()); } + /** + * @magentoDbIsolation enabled + */ + public function testSaveCategoryWithoutImage() + { + $model = $this->objectManager->create(\Magento\Catalog\Model\Category::class); + $repository = $this->objectManager->get(\Magento\Catalog\Api\CategoryRepositoryInterface::class); + + $model->setName('Test Category 100') + ->setParentId(2) + ->setLevel(2) + ->setAvailableSortBy(['position', 'name']) + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->isObjectNew(true); + + $repository->save($model); + $this->assertNull($model->getImage()); + } + /** * @magentoAppArea adminhtml */ diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php index febb4941c273886adb4da64397181683cb4f9a56..9f3d16a998987d600e1f702f4a4228e1ff06c9b7 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php @@ -1197,7 +1197,6 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase */ public function testExistingProductWithUrlKeys() { - $this->markTestSkipped('Test must be unskiped after implementation MAGETWO-48871'); $products = [ 'simple1' => 'url-key1', 'simple2' => 'url-key2', diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php index 21486448f6191e913cdc75e3d5181186541730aa..7a9e73fe78f166ca5d37cf71a430fe4cddf9efcb 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php @@ -11,7 +11,11 @@ require 'quote_with_address.php'; -$quote->collectTotals()->save(); + +$quoteRepository = \Magento\Framework\App\ObjectManager::getInstance()->get( + \Magento\Quote\Api\CartRepositoryInterface::class +); +$quoteRepository->save($quote); /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php index 90fac3c4caca7af34b5ddde487a3b048091831d0..37a087eaa02b2e9c02d58cb4b963e26568336763 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/OptionRepositoryTest.php @@ -12,7 +12,6 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase */ public function testGetListWithExtensionAttributes() { - $this->markTestSkipped('Test skipped due to MAGETWO-45654'); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $productSku = 'configurable'; /** @var \Magento\ConfigurableProduct\Api\OptionRepositoryInterface $optionRepository */ diff --git a/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php b/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php index 3a9bee9f8aad26f68b7d3499d41cecff13bcc507..ff908c78b9fed8703ad939ce0c1219b2d70b8922 100644 --- a/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php +++ b/dev/tests/integration/testsuite/Magento/DownloadableImportExport/Model/DownloadableTest.php @@ -43,11 +43,11 @@ class DownloadableTest extends AbstractProductExportImportTestCase * @dataProvider exportImportDataProvider * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testExport($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** @@ -56,11 +56,11 @@ class DownloadableTest extends AbstractProductExportImportTestCase * @dataProvider exportImportDataProvider * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testImportDelete($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** @@ -72,12 +72,13 @@ class DownloadableTest extends AbstractProductExportImportTestCase * @param string[] $skus * @param string[] $skippedAttributes * @dataProvider importReplaceDataProvider + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * - * @todo remove after MAGETWO-49467 resolved + * @todo remove after MAGETWO-38240 resolved */ public function testImportReplace($fixtures, $skus, $skippedAttributes = [], $rollbackFixtures = []) { - $this->markTestSkipped('Uncomment after MAGETWO-49467 resolved'); + $this->markTestSkipped('Uncomment after MAGETWO-38240 resolved'); } /** diff --git a/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php b/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php index 8a6e4747a0d7a8868659fa413d454f16dc0bd9dd..9afc2ca119bbab23bf59f751ba581d247894c15b 100644 --- a/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php +++ b/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php @@ -20,7 +20,7 @@ class MemoryUsageTest extends \PHPUnit_Framework_TestCase protected function setUp() { if (defined('HHVM_VERSION')) { - $this->markTestSkipped("For HHVM it's not relevant while MAGETWO-33679 is not resolved"); + $this->markTestSkipped("Test not relevant because no gc in HHVM."); } $this->_helper = new \Magento\TestFramework\Helper\Memory( new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer()) @@ -32,7 +32,7 @@ class MemoryUsageTest extends \PHPUnit_Framework_TestCase */ public function testAppReinitializationNoMemoryLeak() { - $this->markTestSkipped('Test fails at Travis. Skipped in scope of MAGETWO-48538'); + $this->markTestSkipped('Test fails at Travis. Skipped until MAGETWO-47111'); $this->_deallocateUnusedMemory(); $actualMemoryUsage = $this->_helper->getRealMemoryUsage(); diff --git a/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php b/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php index afa5981e70f7e340bed21b2325dbc91b2fb032e0..811f62186eeae49bd290e53894377ccf281aaf4c 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php +++ b/dev/tests/static/framework/Magento/TestFramework/Integrity/AbstractConfig.php @@ -36,7 +36,7 @@ abstract class AbstractConfig extends \PHPUnit_Framework_TestCase public function testSchemaUsingInvalidXml($expectedErrors = null) { if (!function_exists('libxml_set_external_entity_loader')) { - $this->markTestSkipped('Skipped due to MAGETWO-44919'); + $this->markTestSkipped('Skipped due to MAGETWO-45033'); } $xmlFile = $this->_getKnownInvalidXml(); $schema = $this->_getXsd(); @@ -46,7 +46,7 @@ abstract class AbstractConfig extends \PHPUnit_Framework_TestCase public function testFileSchemaUsingPartialXml() { if (!function_exists('libxml_set_external_entity_loader')) { - $this->markTestSkipped('Skipped due to MAGETWO-44919'); + $this->markTestSkipped('Skipped due to MAGETWO-45033'); } $xmlFile = $this->_getKnownValidPartialXml(); if ($xmlFile === null) { diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt index 852bb6707cd84154f8e23c878fbd04ea63fb8295..56e0d51516c2632a28acd50ca2c3999e984720df 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt @@ -1,5 +1,3 @@ -app/code/Magento -lib/internal/Magento Magento/Adminhtml Magento/Authorizenet/Model Magento/Backend @@ -160,3 +158,42 @@ Magento/Sales/Setup Magento/SalesRule/Setup Magento/Eav/Setup setup/src/Magento/Setup/Fixtures +Magento/ConfigurableProduct/Setup +Magento/Weee/Setup +Magento/Wishlist/Setup +Magento/CatalogUrlRewrite/Setup +Magento/AdvancedSalesRule/Setup +Magento/VisualMerchandiser/Setup +Magento/Catalog/Model +Magento/Catalog/Ui/Component/Listing +Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config +Magento/Payment/Gateway/Data/Order +Magento/ProductAlert/Controller/Unsubscribe +Magento/Reports/Model/ResourceModel/Customer/Orders +Magento/Sales/Model/ResourceModel/Report +Magento/SalesRule/Model +Magento/Search/Ui/Component/Listing/Column/Scope +Magento/Tax/Model/Calculation +Magento/Tax/Observer +Magento/Vault/Model/Ui +Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price +Magento/AdvancedSalesRule/Model/Rule/Condition/Product +Magento/CmsStaging/Controller/Adminhtml/Block/Update +Magento/Customer/Block/Widget +Magento/Persistent/Observer +Magento/Elasticsearch/Model/Adapter/Container +Magento/Elasticsearch/SearchAdapter +Magento/Staging/Model/Entity/DataProvider +Magento/CatalogStaging/Model/Update/Grid +Magento/Eav/Model/Api/SearchCriteria/CollectionProcessor +Magento/Framework/App/AreaList +Magento/Framework/App/Route/ConfigInterface +Magento/Framework/DataObject/Copy/Config/Data +Magento/Framework/Backup/Filesystem/Iterator +Magento/Theme/Model/Indexer/Design +Magento/Framework/EntityManager/Db +Magento/Framework/Mview/Config/Data +Magento/Framework/View/File/Collector/Override +Magento/Framework/MessageQueue/Consumer/Config/ConsumerConfigItem +Magento/Framework/MessageQueue/Publisher/Config/PublisherConfigItem +Magento/Framework/MessageQueue/Topology/Config/ExchangeConfigItem \ No newline at end of file