Skip to content

Commit

Permalink
Merge branch '2.4-develop' into lac-sticky-banner--task-29354
Browse files Browse the repository at this point in the history
  • Loading branch information
konarshankar07 authored Aug 20, 2020
2 parents 2aca78a + eb50002 commit c3d57cd
Show file tree
Hide file tree
Showing 622 changed files with 22,220 additions and 3,584 deletions.
36 changes: 24 additions & 12 deletions app/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,48 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Autoload\AutoloaderRegistry;
use Magento\Framework\Autoload\ClassLoaderWrapper;

/**
* Shortcut constant for the root directory
*/
define('BP', dirname(__DIR__));
\define('BP', \dirname(__DIR__));

define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');
\define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');

if (!file_exists(VENDOR_PATH)) {
if (!\is_readable(VENDOR_PATH)) {
throw new \Exception(
'We can\'t read some files that are required to run the Magento application. '
. 'This usually means file permissions are set incorrectly.'
);
}

$vendorDir = require VENDOR_PATH;
$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
$vendorAutoload = (
static function (): ?string {
$vendorDir = require VENDOR_PATH;

$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
if (\is_readable($vendorAutoload)) {
return $vendorAutoload;
}

$vendorAutoload = "{$vendorDir}/autoload.php";
if (\is_readable($vendorAutoload)) {
return $vendorAutoload;
}

return null;
}
)();

/* 'composer install' validation */
if (file_exists($vendorAutoload)) {
$composerAutoloader = include $vendorAutoload;
} else if (file_exists("{$vendorDir}/autoload.php")) {
$vendorAutoload = "{$vendorDir}/autoload.php";
$composerAutoloader = include $vendorAutoload;
} else {
if ($vendorAutoload === null) {
throw new \Exception(
'Vendor autoload is not found. Please run \'composer install\' under application root directory.'
);
}

$composerAutoloader = include $vendorAutoload;
AutoloaderRegistry::registerAutoloader(new ClassLoaderWrapper($composerAutoloader));
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function _getCurrencyList()
/**
* Retrieve filter value
*
* @param null $index
* @param string|null $index
* @return array|null
*/
public function getValue($index = null)
Expand Down Expand Up @@ -194,11 +194,11 @@ public function getCondition()
$rate = $this->_getRate($displayCurrency, $this->_getColumnCurrencyCode());

if (isset($value['from'])) {
$value['from'] *= $rate;
$value['from'] = (float) $value['from'] * $rate;
}

if (isset($value['to'])) {
$value['to'] *= $rate;
$value['to'] = (float) $value['to'] * $rate;
}

$this->prepareRates($displayCurrency);
Expand Down
20 changes: 16 additions & 4 deletions app/code/Magento/Backend/Block/Widget/Grid/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
*
* @api
* @deprecated 100.2.0 in favour of UI component implementation
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -69,6 +71,8 @@ public function __construct(
}

/**
* Internal constructor, that is called from real constructor
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand Down Expand Up @@ -242,6 +246,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)

$collection = $this->_getRowCollection($originalCollection);
foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -307,7 +317,7 @@ protected function _exportCsvItem(
*/
public function getCsvFile()
{
$name = md5(microtime());
$name = hash('sha256', microtime());
$file = $this->_path . '/' . $name . '.csv';

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
*/
public function getExcelFile($sheetName = '')
{
$collection = $this->_getRowCollection();
$collection = $this->_getPreparedCollection();

$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);

$name = md5(microtime());
$name = hash('sha256', microtime());
$file = $this->_path . '/' . $name . '.xml';

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -551,6 +561,8 @@ public function _getPreparedCollection()
}

/**
* Get export page size
*
* @return int
*/
public function getExportPageSize()
Expand Down
24 changes: 18 additions & 6 deletions app/code/Magento/Backend/Block/Widget/Grid/Extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Extended Grid Widget
*
* @api
* @deprecated 100.2.0 in favour of UI component implementation
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
Expand Down Expand Up @@ -177,7 +179,10 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
protected $_path = 'export';

/**
* Initialization
*
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
*/
protected function _construct()
{
Expand Down Expand Up @@ -297,6 +302,7 @@ public function addColumn($columnId, $column)
);
$this->getColumnSet()->getChildBlock($columnId)->setGrid($this);
} else {
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(__('Please correct the column format and try again.'));
}

Expand Down Expand Up @@ -471,10 +477,6 @@ protected function _prepareMassactionColumn()
protected function _prepareCollection()
{
if ($this->getCollection()) {
if ($this->getCollection()->isLoaded()) {
$this->getCollection()->clear();
}

parent::_prepareCollection();

if (!$this->_isExport) {
Expand Down Expand Up @@ -663,6 +665,7 @@ public function setEmptyCellLabel($label)
*/
public function getRowUrl($item)
{
// phpstan:ignore "Call to an undefined static method"
$res = parent::getRowUrl($item);
return $res ? $res : '#';
}
Expand All @@ -680,6 +683,7 @@ public function getMultipleRows($item)

/**
* Retrieve columns for multiple rows
*
* @return array
*/
public function getMultipleRowColumns()
Expand Down Expand Up @@ -943,6 +947,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -972,7 +977,12 @@ public function _exportIterateCollection($callback, array $args)
$page++;

foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -1009,6 +1019,7 @@ public function getCsvFile()
$this->_isExport = true;
$this->_prepareGrid();

// phpcs:ignore Magento2.Security.InsecureFunction
$name = md5(microtime());
$file = $this->_path . '/' . $name . '.csv';

Expand Down Expand Up @@ -1153,6 +1164,7 @@ public function getExcelFile($sheetName = '')
[$this, 'getRowRecord']
);

// phpcs:ignore Magento2.Security.InsecureFunction
$name = md5(microtime());
$file = $this->_path . '/' . $name . '.xml';

Expand Down Expand Up @@ -1244,7 +1256,7 @@ public function setCollection($collection)
}

/**
* get collection object
* Get collection object
*
* @return \Magento\Framework\Data\Collection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoadingCheckoutPageWithShippingMethod"/>
<click selector="{{CheckoutShippingMethodsSection.firstShippingMethod}}" stepKey="selectFirstShippingMethod"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask1"/>
<waitForElement selector="{{CheckoutShippingMethodsSection.next}}" time="30" stepKey="waitForNextButton"/>
<click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/>
<actionGroup ref="StorefrontCheckoutClickNextButtonActionGroup" stepKey="clickNext"/>
<!-- Checkout select Check/Money Order payment -->
<comment userInput="Select Check/Money payment" stepKey="checkoutSelectCheckMoneyPayment"/>
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;

use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column;
use Magento\Backend\Block\Widget\Grid\Column\Filter\Price;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\DB\Helper;
use Magento\Directory\Model\Currency;
use Magento\Directory\Model\Currency\DefaultLocator;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class PriceTest extends TestCase
{
/** @var RequestInterface|MockObject */
private $requestMock;

/** @var Context|MockObject */
private $context;

/** @var Helper|MockObject */
private $helper;

/** @var Currency|MockObject */
private $currency;

/** @var DefaultLocator|MockObject */
private $currencyLocator;

/** @var Column|MockObject */
private $columnMock;

/** @var Price */
private $blockPrice;

protected function setUp(): void
{
$this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);

$this->context = $this->createMock(Context::class);
$this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);

$this->helper = $this->createMock(Helper::class);

$this->currency = $this->getMockBuilder(Currency::class)
->disableOriginalConstructor()
->setMethods(['getAnyRate'])
->getMock();

$this->currencyLocator = $this->createMock(DefaultLocator::class);

$this->columnMock = $this->getMockBuilder(Column::class)
->disableOriginalConstructor()
->setMethods(['getCurrencyCode'])
->getMock();

$helper = new ObjectManager($this);

$this->blockPrice = $helper->getObject(Price::class, [
'context' => $this->context,
'resourceHelper' => $this->helper,
'currencyModel' => $this->currency,
'currencyLocator' => $this->currencyLocator
]);
$this->blockPrice->setColumn($this->columnMock);
}

public function testGetCondition()
{
$this->currencyLocator->expects(
$this->any()
)->method(
'getDefaultCurrency'
)->with(
$this->requestMock
)->willReturn(
'defaultCurrency'
);

$this->currency->expects($this->at(0))
->method('getAnyRate')
->with('defaultCurrency')
->willReturn(1.0);

$testValue = [
'value' => [
'from' => '1234a',
]
];

$this->blockPrice->addData($testValue);
$this->assertEquals(['from' => 1234], $this->blockPrice->getCondition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testPrepareLoadedCollection()
$layout->expects($this->any())->method('getBlock')->willReturn($columnSet);

$collection = $this->createMock(Collection::class);
$collection->expects($this->atLeastOnce())->method('isLoaded')->willReturn(true);
$collection->expects($this->atLeastOnce())->method('clear');
$collection->expects($this->never())->method('isLoaded');
$collection->expects($this->never())->method('clear');
$collection->expects($this->atLeastOnce())->method('load');

/** @var Extended $block */
Expand Down
Loading

0 comments on commit c3d57cd

Please sign in to comment.