diff --git a/app/code/Magento/Customer/view/frontend/web/js/validation.js b/app/code/Magento/Customer/view/frontend/web/js/validation.js
index 1f7f24d5ac031..9ffc8137135da 100644
--- a/app/code/Magento/Customer/view/frontend/web/js/validation.js
+++ b/app/code/Magento/Customer/view/frontend/web/js/validation.js
@@ -8,6 +8,20 @@ define([
], function ($, moment, utils) {
'use strict';
+ $.validator.addMethod(
+ 'validate-date',
+ function (value, element, params) {
+ var dateFormat = utils.convertToMomentFormat(params.dateFormat);
+
+ if (value === '') {
+ return true;
+ }
+
+ return moment(value, dateFormat, true).isValid();
+ },
+ $.mage.__('Invalid date')
+ );
+
$.validator.addMethod(
'validate-dob',
function (value, element, params) {
diff --git a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php
index d219aefe81d45..16df2d30db40d 100644
--- a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php
+++ b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php
@@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
namespace Magento\Reports\Model\ResourceModel\Quote\Item;
@@ -17,6 +18,8 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
+ private const PREPARED_FLAG_NAME = 'reports_collection_prepared';
+
/**
* Join fields
*
@@ -99,6 +102,11 @@ protected function _construct()
public function prepareActiveCartItems()
{
$quoteItemsSelect = $this->getSelect();
+
+ if ($this->getFlag(self::PREPARED_FLAG_NAME)) {
+ return $quoteItemsSelect;
+ }
+
$quoteItemsSelect->reset()
->from(['main_table' => $this->getTable('quote_item')], '')
->columns('main_table.product_id')
@@ -114,6 +122,7 @@ public function prepareActiveCartItems()
)->group(
'main_table.product_id'
);
+ $this->setFlag(self::PREPARED_FLAG_NAME, true);
return $quoteItemsSelect;
}
diff --git a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php
index ea8fcfbb77132..6e7d5bdce16f5 100644
--- a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php
+++ b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php
@@ -15,6 +15,7 @@
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Model\ResourceModel\Quote;
+use Magento\Reports\Model\ResourceModel\Quote\Collection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -42,7 +43,7 @@ protected function setUp(): void
public function testGetSelectCountSql()
{
/** @var MockObject $collection */
- $collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Collection::class)
+ $collection = $this->getMockBuilder(Collection::class)
->setMethods(['getSelect'])
->disableOriginalConstructor()
->getMock();
@@ -62,12 +63,12 @@ public function testPrepareActiveCartItems()
$constructArgs = $this->objectManager
->getConstructArguments(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class);
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class)
- ->setMethods(['getSelect', 'getTable'])
+ ->setMethods(['getSelect', 'getTable', 'getFlag', 'setFlag'])
->disableOriginalConstructor()
->setConstructorArgs($constructArgs)
->getMock();
- $collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
+ $collection->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
$this->selectMock->expects($this->once())->method('reset')->willReturnSelf();
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
$this->selectMock->expects($this->atLeastOnce())->method('columns')->willReturnSelf();
@@ -75,7 +76,12 @@ public function testPrepareActiveCartItems()
$this->selectMock->expects($this->once())->method('where')->willReturnSelf();
$this->selectMock->expects($this->once())->method('group')->willReturnSelf();
$collection->expects($this->exactly(2))->method('getTable')->willReturn('table');
+ $collection->expects($this->once())->method('setFlag')
+ ->with('reports_collection_prepared')->willReturnSelf();
$collection->prepareActiveCartItems();
+ $collection->method('getFlag')
+ ->with('reports_collection_prepared')->willReturn(true);
+ $this->assertEquals($this->selectMock, $collection->prepareActiveCartItems());
}
public function testLoadWithFilter()
diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php
index de15a627583ff..47395b17afee8 100644
--- a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php
+++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php
@@ -9,7 +9,7 @@
use Magento\Sales\Model\Order;
/**
- * Class State
+ * Checking order status and adjusting order status before saving
*/
class State
{
@@ -34,6 +34,7 @@ public function check(Order $order)
if (in_array($currentState, [Order::STATE_PROCESSING, Order::STATE_COMPLETE])
&& !$order->canCreditmemo()
&& !$order->canShip()
+ && $order->getIsNotVirtual()
) {
$order->setState(Order::STATE_CLOSED)
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CLOSED));
diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php
index ea655bb32f05f..a48f0702f5a4b 100644
--- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php
+++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php
@@ -41,7 +41,8 @@ protected function setUp(): void
'getBaseGrandTotal',
'canCreditmemo',
'getTotalRefunded',
- 'getConfig'
+ 'getConfig',
+ 'getIsNotVirtual'
]
)
->disableOriginalConstructor()
@@ -49,24 +50,21 @@ protected function setUp(): void
$this->orderMock->expects($this->any())
->method('getConfig')
->willReturnSelf();
- $this->addressMock = $this->createMock(Address::class);
- $this->addressCollectionMock = $this->createMock(
- Collection::class
- );
$this->state = new State();
}
/**
- * @param bool $isCanceled
- * @param bool $canUnhold
- * @param bool $canInvoice
- * @param bool $canShip
- * @param int $callCanSkipNum
* @param bool $canCreditmemo
* @param int $callCanCreditmemoNum
+ * @param bool $canShip
+ * @param int $callCanSkipNum
* @param string $currentState
* @param string $expectedState
- * @param int $callSetStateNum
+ * @param bool $isInProcess
+ * @param int $callGetIsInProcessNum
+ * @param bool $isCanceled
+ * @param bool $canUnhold
+ * @param bool $isNotVirtual
* @dataProvider stateCheckDataProvider
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
@@ -76,12 +74,12 @@ public function testCheck(
bool $canShip,
int $callCanSkipNum,
string $currentState,
- string $expectedState = '',
- bool $isInProcess = false,
- int $callGetIsInProcessNum = 0,
- bool $isCanceled = false,
- bool $canUnhold = false,
- bool $canInvoice = false
+ string $expectedState,
+ bool $isInProcess,
+ int $callGetIsInProcessNum,
+ bool $isCanceled,
+ bool $canUnhold,
+ bool $isNotVirtual
) {
$this->orderMock->setState($currentState);
$this->orderMock->expects($this->any())
@@ -92,7 +90,7 @@ public function testCheck(
->willReturn($canUnhold);
$this->orderMock->expects($this->any())
->method('canInvoice')
- ->willReturn($canInvoice);
+ ->willReturn(false);
$this->orderMock->expects($this->exactly($callCanSkipNum))
->method('canShip')
->willReturn($canShip);
@@ -102,11 +100,16 @@ public function testCheck(
$this->orderMock->expects($this->exactly($callGetIsInProcessNum))
->method('getIsInProcess')
->willReturn($isInProcess);
+ $this->orderMock->method('getIsNotVirtual')
+ ->willReturn($isNotVirtual);
$this->state->check($this->orderMock);
$this->assertEquals($expectedState, $this->orderMock->getState());
}
/**
+ * Data provider for testCheck
+ *
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @return array
*/
public function stateCheckDataProvider()
@@ -118,7 +121,12 @@ public function stateCheckDataProvider()
'can_ship' => false,
'call_can_skip_num' => 1,
'current_state' => Order::STATE_PROCESSING,
- 'expected_state' => Order::STATE_CLOSED
+ 'expected_state' => Order::STATE_CLOSED,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'complete - !canCreditmemo,!canShip -> closed' => [
'can_credit_memo' => false,
@@ -126,7 +134,12 @@ public function stateCheckDataProvider()
'can_ship' => false,
'call_can_skip_num' => 1,
'current_state' => Order::STATE_COMPLETE,
- 'expected_state' => Order::STATE_CLOSED
+ 'expected_state' => Order::STATE_CLOSED,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'processing - !canCreditmemo,canShip -> processing' => [
'can_credit_memo' => false,
@@ -134,7 +147,12 @@ public function stateCheckDataProvider()
'can_ship' => true,
'call_can_skip_num' => 2,
'current_state' => Order::STATE_PROCESSING,
- 'expected_state' => Order::STATE_PROCESSING
+ 'expected_state' => Order::STATE_PROCESSING,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'complete - !canCreditmemo,canShip -> complete' => [
'can_credit_memo' => false,
@@ -142,7 +160,12 @@ public function stateCheckDataProvider()
'can_ship' => true,
'call_can_skip_num' => 1,
'current_state' => Order::STATE_COMPLETE,
- 'expected_state' => Order::STATE_COMPLETE
+ 'expected_state' => Order::STATE_COMPLETE,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'processing - canCreditmemo,!canShip -> complete' => [
'can_credit_memo' => true,
@@ -150,7 +173,12 @@ public function stateCheckDataProvider()
'can_ship' => false,
'call_can_skip_num' => 1,
'current_state' => Order::STATE_PROCESSING,
- 'expected_state' => Order::STATE_COMPLETE
+ 'expected_state' => Order::STATE_COMPLETE,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'complete - canCreditmemo,!canShip -> complete' => [
'can_credit_memo' => true,
@@ -158,7 +186,12 @@ public function stateCheckDataProvider()
'can_ship' => false,
'call_can_skip_num' => 0,
'current_state' => Order::STATE_COMPLETE,
- 'expected_state' => Order::STATE_COMPLETE
+ 'expected_state' => Order::STATE_COMPLETE,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'processing - canCreditmemo, canShip -> processing' => [
'can_credit_memo' => true,
@@ -166,7 +199,12 @@ public function stateCheckDataProvider()
'can_ship' => true,
'call_can_skip_num' => 1,
'current_state' => Order::STATE_PROCESSING,
- 'expected_state' => Order::STATE_PROCESSING
+ 'expected_state' => Order::STATE_PROCESSING,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'complete - canCreditmemo, canShip -> complete' => [
'can_credit_memo' => true,
@@ -174,7 +212,12 @@ public function stateCheckDataProvider()
'can_ship' => true,
'call_can_skip_num' => 0,
'current_state' => Order::STATE_COMPLETE,
- 'expected_state' => Order::STATE_COMPLETE
+ 'expected_state' => Order::STATE_COMPLETE,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'new - canCreditmemo, canShip, IsInProcess -> processing' => [
'can_credit_memo' => true,
@@ -183,8 +226,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 1,
'current_state' => Order::STATE_NEW,
'expected_state' => Order::STATE_PROCESSING,
- true,
- 1
+ 'is_in_process' => true,
+ 'get_is_in_process_invoke_count' => 1,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'new - canCreditmemo, !canShip, IsInProcess -> processing' => [
'can_credit_memo' => true,
@@ -193,8 +239,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 1,
'current_state' => Order::STATE_NEW,
'expected_state' => Order::STATE_COMPLETE,
- true,
- 1
+ 'is_in_process' => true,
+ 'get_is_in_process_invoke_count' => 1,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'new - canCreditmemo, canShip, !IsInProcess -> new' => [
'can_credit_memo' => true,
@@ -203,8 +252,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 0,
'current_state' => Order::STATE_NEW,
'expected_state' => Order::STATE_NEW,
- false,
- 1
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 1,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
],
'hold - canUnhold -> hold' => [
'can_credit_memo' => true,
@@ -213,10 +265,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 0,
'current_state' => Order::STATE_HOLDED,
'expected_state' => Order::STATE_HOLDED,
- false,
- 0,
- false,
- true
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => true,
+ 'is_not_virtual' => true
],
'payment_review - canUnhold -> payment_review' => [
'can_credit_memo' => true,
@@ -225,10 +278,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 0,
'current_state' => Order::STATE_PAYMENT_REVIEW,
'expected_state' => Order::STATE_PAYMENT_REVIEW,
- false,
- 0,
- false,
- true
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => true,
+ 'is_not_virtual' => true
],
'pending_payment - canUnhold -> pending_payment' => [
'can_credit_memo' => true,
@@ -237,10 +291,11 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 0,
'current_state' => Order::STATE_PENDING_PAYMENT,
'expected_state' => Order::STATE_PENDING_PAYMENT,
- false,
- 0,
- false,
- true
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => true,
+ 'is_not_virtual' => true
],
'cancelled - isCanceled -> cancelled' => [
'can_credit_memo' => true,
@@ -249,9 +304,24 @@ public function stateCheckDataProvider()
'call_can_skip_num' => 0,
'current_state' => Order::STATE_HOLDED,
'expected_state' => Order::STATE_HOLDED,
- false,
- 0,
- true
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => true,
+ 'can_unhold' => false,
+ 'is_not_virtual' => true
+ ],
+ 'processing - !canCreditmemo!canShip -> complete(virtual product)' => [
+ 'can_credit_memo' => false,
+ 'can_credit_memo_invoke_count' => 1,
+ 'can_ship' => false,
+ 'call_can_skip_num' => 2,
+ 'current_state' => Order::STATE_PROCESSING,
+ 'expected_state' => Order::STATE_COMPLETE,
+ 'is_in_process' => false,
+ 'get_is_in_process_invoke_count' => 0,
+ 'is_canceled' => false,
+ 'can_unhold' => false,
+ 'is_not_virtual' => false
],
];
}
diff --git a/lib/internal/Magento/Framework/App/ResourceConnection.php b/lib/internal/Magento/Framework/App/ResourceConnection.php
index 00dc88dcd7b17..3ba50fb396a4c 100644
--- a/lib/internal/Magento/Framework/App/ResourceConnection.php
+++ b/lib/internal/Magento/Framework/App/ResourceConnection.php
@@ -178,7 +178,7 @@ public function getTableName($modelEntity, $connectionName = self::DEFAULT_CONNE
list($modelEntity, $tableSuffix) = $modelEntity;
}
- $tableName = $modelEntity;
+ $tableName = (string)$modelEntity;
$mappedTableName = $this->getMappedTableName($tableName);
if ($mappedTableName) {
diff --git a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
index 1b12d68e683a3..67d5e303c6896 100644
--- a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
+++ b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
@@ -84,7 +84,7 @@ public function testGetTablePrefixWithInjectedPrefix()
public function testGetTablePrefix()
{
- $this->deploymentConfigMock->expects(self::once())
+ $this->deploymentConfigMock->expects($this->once())
->method('get')
->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX)
->willReturn('pref_');
@@ -93,10 +93,10 @@ public function testGetTablePrefix()
public function testGetConnectionByName()
{
- $this->deploymentConfigMock->expects(self::once())->method('get')
+ $this->deploymentConfigMock->expects($this->once())->method('get')
->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/default')
->willReturn(['config']);
- $this->connectionFactoryMock->expects(self::once())->method('create')
+ $this->connectionFactoryMock->expects($this->once())->method('create')
->with(['config'])
->willReturn('connection');
@@ -112,15 +112,38 @@ public function testGetExistingConnectionByName()
'connections' => ['default_process_' . getmypid() => 'existing_connection']
]
);
- $this->deploymentConfigMock->expects(self::never())->method('get');
+ $this->deploymentConfigMock->expects($this->never())->method('get');
self::assertEquals('existing_connection', $unit->getConnectionByName('default'));
}
public function testCloseConnection()
{
- $this->configMock->expects(self::once())->method('getConnectionName')->with('default');
+ $this->configMock->expects($this->once())->method('getConnectionName')->with('default');
$this->unit->closeConnection('default');
}
+
+ public function testGetTableNameWithBoolParam()
+ {
+ $this->deploymentConfigMock->expects($this->at(0))
+ ->method('get')
+ ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX)
+ ->willReturn('pref_');
+ $this->deploymentConfigMock->expects($this->at(1))->method('get')
+ ->with('db/connection/default')
+ ->willReturn(['config']);
+ $this->configMock->expects($this->atLeastOnce())
+ ->method('getConnectionName')
+ ->with('default')
+ ->willReturn('default');
+
+ $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock();
+ $connection->expects($this->once())->method('getTableName')->with('pref_1');
+ $this->connectionFactoryMock->expects($this->once())->method('create')
+ ->with(['config'])
+ ->willReturn($connection);
+
+ $this->unit->getTableName(true);
+ }
}
diff --git a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php
index 0a8db80cae349..cdbce9d102a89 100644
--- a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php
+++ b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php
@@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
namespace Magento\Framework\View\Template\Html;
@@ -140,7 +141,7 @@ function ($match) use (&$heredocs) {
. '(?:<(?>textarea|pre|script)\b|\z))#',
' ',
preg_replace(
- '#(?)[^\n\r]*#',
+ '#(?)[^\n\r]*#',
'',
preg_replace(
'#(?)#',
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php
index 6aafa5a46cf63..3b13a2f723617 100644
--- a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php
@@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
+
namespace Magento\Framework\View\Test\Unit\Template\Html;
use PHPUnit\Framework\TestCase;
@@ -139,6 +141,7 @@ public function testMinify()
someMethod(); ?>