Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into MAGETWO-69848-PR…
Browse files Browse the repository at this point in the history
…-9925
  • Loading branch information
Oleksii Korshenko committed Jun 15, 2017
2 parents c0994b4 + 04b3b52 commit 5186c90
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function setUp()
$this->productMock = $this->getMockBuilder(ProductInterface::class)
->setMethods([
'getId',
'getTypeId',
'getStoreId',
'getResource',
'getData',
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface
*
* @var string
*/
protected $eventObject = 'stock';
protected $_eventObject = 'stock';

const BACKORDERS_NO = 0;

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface
*
* @var string
*/
protected $eventObject = 'item';
protected $_eventObject = 'item';

/**
* Store model manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
20 changes: 12 additions & 8 deletions app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;

class LowestPriceOptionsProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider
*/
private $model;

/**
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
*/
private $resourceConnection;

/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $connection;

/**
* @var LinkedProductSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $linkedProductSelectBuilder;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $collectionFactory;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\Collection|\PHPUnit_Framework_MockObject_MockObject
*/
private $productCollection;

protected function setUp()
{
$this->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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
]
]
]
]
]
]
]
]
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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]
Expand All @@ -81,17 +84,16 @@ 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],
[
'children' => [
self::$advancedPricingButton => [
'arguments' => [
'data' => [
'config' => [
'componentType' => 'container',
$visibilityConfig
],
'config' => $config,
],
],
],
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Shipping/Model/Shipping/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 5186c90

Please sign in to comment.