Skip to content

Commit

Permalink
refactored CancelOrdersInOrderSalesReportTest
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaAPak committed Jan 4, 2021
1 parent 24cb7ac commit 3bc048d
Show file tree
Hide file tree
Showing 104 changed files with 3,810 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* getPagerVisibility()
* getVarNamePage()
*/
$numColumns = count($block->getColumns());

/**
* @var \Magento\Backend\Block\Widget\Grid\Extended $block
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
*/
$numColumns = count($block->getColumns());

?>
<?php if ($block->getCollection()): ?>
<?php if ($block->canDisplayContainer()): ?>
Expand Down Expand Up @@ -285,7 +286,9 @@ $numColumns = count($block->getColumns());
</table>

</div>
<?php if ($block->canDisplayContainer()): ?>
</div>
<?php endif; ?>
<?php
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public function create(
$quantity,
array $arguments = []
) {
$quantity = $quantity ? (float)$quantity : 1.;
$selection->setQty($quantity);

$arguments['bundleProduct'] = $bundleProduct;
$arguments['saleableItem'] = $selection;
$arguments['quantity'] = $quantity ? (float)$quantity : 1.;
$arguments['quantity'] = $quantity;

return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier;

use Magento\Bundle\Model\Product\Attribute\Source\Shipment\Type as ShipmentType;
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel;
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\UrlInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test for bundle panel
*/
class BundlePanelTest extends TestCase
{
/**
* @var UrlInterface|MockObject
*/
private $urlBuilder;

/**
* @var ShipmentType|MockObject
*/
private $shipmentType;

/**
* @var LocatorInterface|MockObject
*/
private $locatorMock;

/**
* @var ProductInterface|MockObject
*/
private $productMock;

/**
* @var ArrayManager|MockObject
*/
private $arrayManagerMock;

/**
* @var BundlePanel
*/
private $bundlePanelModel;

/**
* @return void
*/
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
->disableOriginalConstructor()
->getMock();
$this->arrayManagerMock->expects($this->any())
->method('get')
->willReturn([]);
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
->getMockForAbstractClass();
$this->shipmentType = $this->getMockBuilder(ShipmentType::class)
->getMockForAbstractClass();
$this->productMock = $this->getMockBuilder(ProductInterface::class)
->addMethods(['getStoreId'])
->getMockForAbstractClass();
$this->productMock->method('getId')
->willReturn(true);
$this->productMock->method('getStoreId')
->willReturn(0);
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
->onlyMethods(['getProduct'])
->getMockForAbstractClass();
$this->locatorMock->method('getProduct')
->willReturn($this->productMock);

$this->bundlePanelModel = $this->objectManager->getObject(
BundlePanel::class,
[
'locator' => $this->locatorMock,
'urlBuilder' => $this->urlBuilder,
'shipmentType' => $this->shipmentType,
'arrayManager' => $this->arrayManagerMock,
]
);
}

/**
* Test for modify meta
*
* @param string $shipmentTypePath
* @param string $dataScope
*
* @return void
* @dataProvider getDataModifyMeta
*/
public function testModifyMeta(string $shipmentTypePath, string $dataScope): void
{
$sourceMeta = [
'bundle-items' => [
'children' => [
BundlePrice::CODE_PRICE_TYPE => []
]
]
];
$this->arrayManagerMock->method('findPath')
->willReturnMap(
[
[
BundlePanel::CODE_SHIPMENT_TYPE,
[],
null,
'children',
ArrayManager::DEFAULT_PATH_DELIMITER,
$shipmentTypePath
],
]
);
$this->arrayManagerMock->method('merge')
->willReturn([]);
$this->arrayManagerMock->method('remove')
->willReturn([]);
$this->arrayManagerMock->method('set')
->willReturn([]);
$this->arrayManagerMock->expects($this->at(12))
->method('merge')
->with(
$shipmentTypePath . BundlePanel::META_CONFIG_PATH,
[],
[
'dataScope' => $dataScope,
'validation' => [
'required-entry' => false
]
]
);
$this->bundlePanelModel->modifyMeta($sourceMeta);
}

/**
* Data provider for modify meta test
*
* @return string[][]
*/
public function getDataModifyMeta(): array
{
return [
[
'bundle-items/children',
'data.product.shipment_type'
],
[
'someAttrGroup/children',
'shipment_type'
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,19 @@ public function modifyData(array $data)
*/
private function modifyShipmentType(array $meta)
{
$actualPath = $this->arrayManager->findPath(
static::CODE_SHIPMENT_TYPE,
$meta,
null,
'children'
);

$meta = $this->arrayManager->merge(
$this->arrayManager->findPath(
static::CODE_SHIPMENT_TYPE,
$meta,
null,
'children'
) . static::META_CONFIG_PATH,
$actualPath . static::META_CONFIG_PATH,
$meta,
[
'dataScope' => 'data.product.shipment_type',
'dataScope' => stripos($actualPath, self::CODE_BUNDLE_DATA) === 0
? 'data.product.shipment_type' : 'shipment_type',
'validation' => [
'required-entry' => false
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ $scriptString .= <<<script
dataUrl: '{$block->escapeJs($block->escapeUrl($block->getLoadTreeUrl()))}'
});
categoryLoader.processResponse = function (response, parent, callback) {
var config = JSON.parse(response.responseText);
this.buildCategoryTree(parent, config);
if (typeof callback == "function") {
callback(this, parent);
}
};
categoryLoader.buildCategoryTree = function(parent, config)
{
if (!config) return null;
Expand Down Expand Up @@ -164,8 +174,10 @@ $scriptString .= <<<script
};
categoryLoader.on("beforeload", function(treeLoader, node) {
$('{$block->escapeJs($_divId)}').fire('category:beforeLoad', {treeLoader:treeLoader});
treeLoader.baseParams.id = node.attributes.id;
treeLoader.baseParams.store = node.attributes.store;
treeLoader.baseParams.form_key = FORM_KEY;
$('{$block->escapeJs($_divId)}').fire('category:beforeLoad', {treeLoader:treeLoader});
});
tree{$block->escapeJs($block->getId())} = new Ext.tree.TreePanel.Enhanced('{$block->escapeJs($_divId)}', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public function isValid($value)
]
);
$valid = false;
break;
}
break;
}
}
return $valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,17 @@ public function validate(Observer $observer)
if ($stockStatus->getStockStatus() === Stock::STOCK_OUT_OF_STOCK
|| $parentStockStatus && $parentStockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
) {
$quoteItem->addErrorInfo(
'cataloginventory',
Data::ERROR_QTY,
__('This product is out of stock.')
);
$hasError = $quoteItem->getStockStateResult()
? $quoteItem->getStockStateResult()->getHasError() : false;
if (!$hasError) {
$quoteItem->addErrorInfo(
'cataloginventory',
Data::ERROR_QTY,
__('This product is out of stock.')
);
} else {
$quoteItem->addErrorInfo(null, Data::ERROR_QTY);
}
$quoteItem->getQuote()->addErrorInfo(
'stock',
'cataloginventory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function setUp(): void
->getMock();
$this->storeMock = $this->createMock(Store::class);
$this->quoteItemMock = $this->getMockBuilder(Item::class)
->addMethods(['getProductId', 'getHasError'])
->addMethods(['getProductId', 'getHasError', 'getStockStateResult'])
->onlyMethods(
[
'getQuote',
Expand Down Expand Up @@ -460,6 +460,53 @@ public function testException()
$this->quantityValidator->validate($this->observerMock);
}

/**
* This tests the scenario when the error is in the quote item already
*
* @return void
*/
public function testValidateOutStockWithAlreadyErrorInQuoteItem(): void
{
$this->createInitialStub(1);
$resultMock = $this->getMockBuilder(DataObject::class)
->addMethods(['checkQtyIncrements', 'getMessage', 'getQuoteMessage', 'getHasError'])
->getMock();
$resultMock->method('getHasError')
->willReturn(true);
$this->stockRegistryMock->method('getStockItem')
->willReturn($this->stockItemMock);
$this->stockRegistryMock->expects($this->at(1))
->method('getStockStatus')
->willReturn($this->stockStatusMock);
$this->quoteItemMock->method('getParentItem')
->willReturn($this->parentItemMock);
$this->quoteItemMock->method('getStockStateResult')
->willReturn($resultMock);
$this->stockRegistryMock->expects($this->at(2))
->method('getStockStatus')
->willReturn($this->parentStockItemMock);
$this->parentStockItemMock->method('getStockStatus')
->willReturn(0);
$this->stockStatusMock->expects($this->atLeastOnce())
->method('getStockStatus')
->willReturn(1);
$this->quoteItemMock->expects($this->once())
->method('addErrorInfo')
->with(
null,
Data::ERROR_QTY,
);
$this->quoteMock->expects($this->once())
->method('addErrorInfo')
->with(
'stock',
'cataloginventory',
Data::ERROR_QTY,
__('Some of the products are out of stock.')
);
$this->quantityValidator->validate($this->observerMock);
}

/**
* @param $qty
* @param $hasError
Expand Down
Loading

0 comments on commit 3bc048d

Please sign in to comment.