diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php index 93c3b50024624..d105822ecb997 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php @@ -56,6 +56,7 @@ protected function setUp() $this->productMock = $this->getMockBuilder(ProductInterface::class) ->setMethods([ 'getId', + 'getTypeId', 'getStoreId', 'getResource', 'getData', diff --git a/app/code/Magento/CatalogInventory/Model/Stock.php b/app/code/Magento/CatalogInventory/Model/Stock.php index 75c5d27b972d6..d4568429e3a52 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock.php +++ b/app/code/Magento/CatalogInventory/Model/Stock.php @@ -32,7 +32,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface * * @var string */ - protected $eventObject = 'stock'; + protected $_eventObject = 'stock'; const BACKORDERS_NO = 0; diff --git a/app/code/Magento/CatalogInventory/Model/Stock/Item.php b/app/code/Magento/CatalogInventory/Model/Stock/Item.php index e4cd70f71c647..b4b70041ce148 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock/Item.php +++ b/app/code/Magento/CatalogInventory/Model/Stock/Item.php @@ -43,7 +43,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface * * @var string */ - protected $eventObject = 'item'; + protected $_eventObject = 'item'; /** * Store model manager diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php index 643e2f3b53288..65a7f5fc6c40e 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php @@ -477,33 +477,37 @@ public function getQtyIncrementsDataProvider() * * @param $eventName * @param $methodName + * @param $objectName * * @dataProvider eventsDataProvider */ - public function testDispatchEvents($eventName, $methodName) + public function testDispatchEvents($eventName, $methodName, $objectName) { $isCalledWithRightPrefix = 0; + $isObjectNameRight = 0; $this->eventDispatcher->expects($this->any())->method('dispatch')->with( $this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) { $isCalledWithRightPrefix |= ($arg === $eventName); return true; }), - $this->anything() + $this->callback(function ($data) use (&$isObjectNameRight, $objectName) { + $isObjectNameRight |= isset($data[$objectName]); + return true; + }) ); $this->item->$methodName(); - $this->assertEquals( - 1, - (int) $isCalledWithRightPrefix, - sprintf("Event %s doesn't dispatched", $eventName) + $this->assertTrue( + ($isCalledWithRightPrefix && $isObjectNameRight), + sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName) ); } public function eventsDataProvider() { return [ - ['cataloginventory_stock_item_save_before', 'beforeSave'], - ['cataloginventory_stock_item_save_after', 'afterSave'], + ['cataloginventory_stock_item_save_before', 'beforeSave', 'item'], + ['cataloginventory_stock_item_save_after', 'afterSave', 'item'], ]; } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php index 1c3d9d05f5ae0..b1eca1fdc7549 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php @@ -100,33 +100,37 @@ public function setUp() * * @param $eventName * @param $methodName + * @param $objectName * * @dataProvider eventsDataProvider */ - public function testDispatchEvents($eventName, $methodName) + public function testDispatchEvents($eventName, $methodName, $objectName) { $isCalledWithRightPrefix = 0; + $isObjectNameRight = 0; $this->eventDispatcher->expects($this->any())->method('dispatch')->with( $this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) { $isCalledWithRightPrefix |= ($arg === $eventName); return true; }), - $this->anything() + $this->callback(function ($data) use (&$isObjectNameRight, $objectName) { + $isObjectNameRight |= isset($data[$objectName]); + return true; + }) ); $this->stockModel->$methodName(); - $this->assertEquals( - 1, - (int) $isCalledWithRightPrefix, - sprintf("Event %s doesn't dispatched", $eventName) + $this->assertTrue( + ($isCalledWithRightPrefix && $isObjectNameRight), + sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName) ); } public function eventsDataProvider() { return [ - ['cataloginventory_stock_save_before', 'beforeSave'], - ['cataloginventory_stock_save_after', 'afterSave'], + ['cataloginventory_stock_save_before', 'beforeSave', 'stock'], + ['cataloginventory_stock_save_after', 'afterSave', 'stock'], ]; } } diff --git a/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php b/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php index 498a7cac77e56..727598160ea1d 100644 --- a/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php +++ b/app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php @@ -63,7 +63,7 @@ public function getProducts(ProductInterface $product) ); $this->linkedProductMap[$product->getId()] = $this->collectionFactory->create() - ->addAttributeToSelect(['price', 'special_price']) + ->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date']) ->addIdFilter($productIds) ->getItems(); } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php new file mode 100644 index 0000000000000..65b80eceefc89 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php @@ -0,0 +1,100 @@ +connection = $this + ->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) + ->getMock(); + $this->resourceConnection = $this + ->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + ->disableOriginalConstructor() + ->setMethods(['getConnection']) + ->getMock(); + $this->resourceConnection->expects($this->once())->method('getConnection')->willReturn($this->connection); + $this->linkedProductSelectBuilder = $this + ->getMockBuilder(LinkedProductSelectBuilderInterface::class) + ->setMethods(['build']) + ->getMock(); + $this->productCollection = $this + ->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class) + ->disableOriginalConstructor() + ->setMethods(['addAttributeToSelect', 'addIdFilter', 'getItems']) + ->getMock(); + $this->collectionFactory = $this + ->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->collectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection); + + $objectManager = new ObjectManager($this); + $this->model = $objectManager->getObject( + \Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider::class, + [ + 'resourceConnection' => $this->resourceConnection, + 'linkedProductSelectBuilder' => $this->linkedProductSelectBuilder, + 'collectionFactory' => $this->collectionFactory, + ] + ); + } + + public function testGetProducts() + { + $productId = 1; + $linkedProducts = ['some', 'linked', 'products', 'dataobjects']; + $product = $this->getMockBuilder(ProductInterface::class)->disableOriginalConstructor()->getMock(); + $product->expects($this->any())->method('getId')->willReturn($productId); + $this->linkedProductSelectBuilder->expects($this->any())->method('build')->with($productId)->willReturn([]); + $this->productCollection + ->expects($this->once()) + ->method('addAttributeToSelect') + ->with(['price', 'special_price', 'special_from_date', 'special_to_date']) + ->willReturnSelf(); + $this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf(); + $this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts); + + $this->assertEquals($linkedProducts, $this->model->getProducts($product)); + } +} diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ConfigurablePriceTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ConfigurablePriceTest.php index 79102ddefbd6a..794f421f99cbd 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ConfigurablePriceTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ConfigurablePriceTest.php @@ -15,13 +15,106 @@ class ConfigurablePriceTest extends AbstractModifierTest */ protected function createModel() { - return $this->objectManager->getObject(ConfigurablePriceModifier::class); + return $this->objectManager->getObject(ConfigurablePriceModifier::class, ['locator' => $this->locatorMock]); } - public function testModifyMeta() + /** + * @param array $metaInput + * @param array $metaOutput + * @dataProvider metaDataProvider + */ + public function testModifyMeta($metaInput, $metaOutput) { - $meta = ['initial' => 'meta']; + $this->productMock->expects($this->any()) + ->method('getTypeId') + ->willReturn(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE); + + $metaResult = $this->getModel()->modifyMeta($metaInput); + $this->assertEquals($metaResult, $metaOutput); + } - $this->assertArrayHasKey('initial', $this->getModel()->modifyMeta($meta)); + /** + * @return array + */ + public function metaDataProvider() + { + return [ + [ + 'metaInput' => [ + 'pruduct-details' => [ + 'children' => [ + 'container_price' => [ + 'children' => [ + 'advanced_pricing_button' => [ + 'arguments' => [] + ] + ] + ] + ] + ] + ], + 'metaOutput' => [ + 'pruduct-details' => [ + 'children' => [ + 'container_price' => [ + 'children' => [ + 'advanced_pricing_button' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'visible' => 0, + 'disabled' => 1, + 'componentType' => 'container' + ], + ], + ], + ], + 'price' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'component' => + 'Magento_ConfigurableProduct/js/components/price-configurable' + ], + ], + ], + ], + ], + ], + ], + ] + ] + ], [ + 'metaInput' => [ + 'pruduct-details' => [ + 'children' => [ + 'container_price' => [ + 'children' => [] + ] + ] + ] + ], + 'metaOutput' => [ + 'pruduct-details' => [ + 'children' => [ + 'container_price' => [ + 'children' => [ + 'price' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'component' => + 'Magento_ConfigurableProduct/js/components/price-configurable' + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ]; } } diff --git a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/ConfigurablePrice.php b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/ConfigurablePrice.php index f294cb14da4f0..e3e1ef2ff87bb 100644 --- a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/ConfigurablePrice.php +++ b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/ConfigurablePrice.php @@ -49,9 +49,10 @@ public function modifyData(array $data) */ public function modifyMeta(array $meta) { - if ($groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_PRICE) - ?: $this->getGroupCodeByField($meta, self::CODE_GROUP_PRICE) - ) { + $groupCode = $this->getGroupCodeByField($meta, ProductAttributeInterface::CODE_PRICE) + ?: $this->getGroupCodeByField($meta, self::CODE_GROUP_PRICE); + + if ($groupCode && !empty($meta[$groupCode]['children'][self::CODE_GROUP_PRICE])) { if (!empty($meta[$groupCode]['children'][self::CODE_GROUP_PRICE])) { $meta[$groupCode]['children'][self::CODE_GROUP_PRICE] = array_replace_recursive( $meta[$groupCode]['children'][self::CODE_GROUP_PRICE], @@ -71,7 +72,9 @@ public function modifyMeta(array $meta) ] ); } - if (!empty($meta[$groupCode]['children'][self::CODE_GROUP_PRICE])) { + if ( + !empty($meta[$groupCode]['children'][self::CODE_GROUP_PRICE]['children'][self::$advancedPricingButton]) + ) { $productTypeId = $this->locator->getProduct()->getTypeId(); $visibilityConfig = ($productTypeId === ConfigurableType::TYPE_CODE) ? ['visible' => 0, 'disabled' => 1] @@ -81,6 +84,8 @@ public function modifyMeta(array $meta) . ConfigurablePanel::CONFIGURABLE_MATRIX . ':isEmpty', ] ]; + $config = $visibilityConfig; + $config['componentType'] = 'container'; $meta[$groupCode]['children'][self::CODE_GROUP_PRICE] = array_replace_recursive( $meta[$groupCode]['children'][self::CODE_GROUP_PRICE], [ @@ -88,10 +93,7 @@ public function modifyMeta(array $meta) self::$advancedPricingButton => [ 'arguments' => [ 'data' => [ - 'config' => [ - 'componentType' => 'container', - $visibilityConfig - ], + 'config' => $config, ], ], ], diff --git a/app/code/Magento/Shipping/Model/Shipping/Labels.php b/app/code/Magento/Shipping/Model/Shipping/Labels.php index 77ec66b74fa28..b1709b0a16998 100644 --- a/app/code/Magento/Shipping/Model/Shipping/Labels.php +++ b/app/code/Magento/Shipping/Model/Shipping/Labels.php @@ -122,7 +122,6 @@ public function requestToShipment(Shipment $orderShipment) || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 - || !$shipperRegionCode || !$this->_scopeConfig->getValue( Shipment::XML_PATH_STORE_CITY, ScopeInterface::SCOPE_STORE, diff --git a/app/code/Magento/Shipping/Test/Unit/Model/Shipping/LabelsTest.php b/app/code/Magento/Shipping/Test/Unit/Model/Shipping/LabelsTest.php index c6272fa6c9d34..8269da7c7fa0c 100644 --- a/app/code/Magento/Shipping/Test/Unit/Model/Shipping/LabelsTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Model/Shipping/LabelsTest.php @@ -5,8 +5,7 @@ */ namespace Magento\Shipping\Test\Unit\Model\Shipping; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Framework\DataObject; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Sales\Model\Order\Shipment; use Magento\Store\Model\ScopeInterface; @@ -39,6 +38,16 @@ class LabelsTest extends \PHPUnit_Framework_TestCase */ protected $region; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $carrierFactory; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $user; + protected function setUp() { $this->request = $this->getMockBuilder(\Magento\Shipping\Model\Shipment\Request::class) @@ -49,32 +58,32 @@ protected function setUp() ->setMethods(['create']) ->getMock(); $requestFactory->expects(static::any())->method('create')->willReturn($this->request); - - $carrier = $this->getMockBuilder(\Magento\Shipping\Model\Carrier\AbstractCarrier::class) + $this->carrierFactory = $this->getMockBuilder(\Magento\Shipping\Model\CarrierFactory::class) ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); - - $carrierFactory = $this->getMockBuilder(\Magento\Shipping\Model\CarrierFactory::class) + $storeManager = $this->getStoreManager(); + $this->user = $this->getMockBuilder(\Magento\User\Model\User::class) ->disableOriginalConstructor() - ->setMethods(['create']) + ->setMethods(['getFirstname', 'getLastname', 'getEmail', 'getName']) ->getMock(); - $carrierFactory->expects(static::any())->method('create')->willReturn($carrier); - $storeManager = $this->getStoreManager(); - $authSession = $this->getAuthSession(); + $authSession = $this->getMockBuilder(\Magento\Backend\Model\Auth\Session::class) + ->disableOriginalConstructor() + ->setMethods(['getUser']) + ->getMock(); + $authSession->expects(static::any())->method('getUser')->willReturn($this->user); $regionFactory = $this->getRegionFactory(); - $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class) ->disableOriginalConstructor() ->setMethods(['getValue']) ->getMock(); - - $objectManagerHelper = new ObjectManager($this); + $objectManagerHelper = new ObjectManagerHelper($this); $this->labels = $objectManagerHelper->getObject( \Magento\Shipping\Model\Shipping\Labels::class, [ 'shipmentRequestFactory' => $requestFactory, - 'carrierFactory' => $carrierFactory, + 'carrierFactory' => $this->carrierFactory, 'storeManager' => $storeManager, 'scopeConfig' => $this->scopeConfig, 'authSession' => $authSession, @@ -84,14 +93,21 @@ protected function setUp() } /** - * @covers \Magento\Shipping\Model\Shipping\Labels + * @dataProvider requestToShipmentDataProvider */ - public function testRequestToShipment() + public function testRequestToShipment($regionId) { + $carrier = $this->getMockBuilder(\Magento\Shipping\Model\Carrier\AbstractCarrier::class) + ->disableOriginalConstructor() + ->getMock(); + $this->carrierFactory->expects(static::any())->method('create')->willReturn($carrier); $order = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() ->getMock(); - + $this->user->expects($this->atLeastOnce())->method('getFirstname')->willReturn('John'); + $this->user->expects($this->atLeastOnce())->method('getLastname')->willReturn('Doe'); + $this->user->expects($this->once())->method('getName')->willReturn('John Doe'); + $this->user->expects($this->once())->method('getEmail')->willReturn('admin@admin.test.com'); $shippingMethod = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() ->setMethods(['getCarrierCode']) @@ -125,7 +141,7 @@ public function testRequestToShipment() $this->scopeConfig->expects(static::any()) ->method('getValue') ->willReturnMap([ - [Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $storeId, 'CA'], + [Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $storeId, $regionId], [Shipment::XML_PATH_STORE_ADDRESS1, ScopeInterface::SCOPE_STORE, $storeId, 'Beverly Heals'], ['general/store_information', ScopeInterface::SCOPE_STORE, $storeId, [ 'name' => 'General Store', 'phone' => '(244)1500301' @@ -135,38 +151,35 @@ public function testRequestToShipment() [Shipment::XML_PATH_STORE_COUNTRY_ID, ScopeInterface::SCOPE_STORE, $storeId, 'US'], [Shipment::XML_PATH_STORE_ADDRESS2, ScopeInterface::SCOPE_STORE, $storeId, '1st Park Avenue'], ]); - $this->labels->requestToShipment($shipment); } /** - * @return \PHPUnit_Framework_MockObject_MockObject + * @expectedException \Magento\Framework\Exception\LocalizedException + * @dataProvider requestToShipmentLocalizedExceptionDataProvider */ - protected function getAuthSession() + public function testRequestToShipmentLocalizedException($isShipmentCarrierNotNull) { - $user = $this->getMockBuilder(\Magento\User\Model\User::class) + $order = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() - ->setMethods(['getFirstname', 'getLastname', 'getEmail', 'getName']) ->getMock(); - $user->expects(static::exactly(2)) - ->method('getFirstname') - ->willReturn('John'); - $user->expects(static::exactly(2)) - ->method('getLastname') - ->willReturn('Doe'); - $user->expects(static::once()) - ->method('getName') - ->willReturn('John Doe'); - $user->expects(static::once()) - ->method('getEmail') - ->willReturn('admin@admin.test.com'); - - $authSession = $this->getMockBuilder(\Magento\Backend\Model\Auth\Session::class) + $shipment = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipment::class) ->disableOriginalConstructor() - ->setMethods(['getUser']) ->getMock(); - $authSession->expects(static::any())->method('getUser')->willReturn($user); - return $authSession; + $shippingMethod = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->disableOriginalConstructor() + ->setMethods(['getCarrierCode']) + ->getMock(); + $order->expects($this->atLeastOnce()) + ->method('getShippingMethod') + ->with(true) + ->willReturn($shippingMethod); + $this->carrierFactory + ->expects(static::any()) + ->method('create') + ->willReturn($isShipmentCarrierNotNull ? $shippingMethod : null); + $shipment->expects($this->once())->method('getOrder')->willReturn($order); + $this->labels->requestToShipment($shipment); } /** @@ -246,4 +259,36 @@ protected function getRecipientAddress() ->willReturn(1); return $address; } + + /** + * Data provider to testRequestToShipment + * @return array + */ + public function requestToShipmentDataProvider() + { + return [ + [ + 'CA' + ], + [ + null + ] + ]; + } + + /** + * Data provider to testRequestToShipmentLocalizedException + * @return array + */ + public function requestToShipmentLocalizedExceptionDataProvider() + { + return [ + [ + true + ], + [ + false + ] + ]; + } }