diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Index.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Index.php index 125dba405b108..22eb3b30722f4 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Index.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\AdminNotification\Controller\Adminhtml\Notification; -class Index extends \Magento\AdminNotification\Controller\Adminhtml\Notification +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\AdminNotification\Controller\Adminhtml\Notification implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php b/app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php index 818bcda1da65f..d78266ab75311 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php +++ b/app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php @@ -5,12 +5,14 @@ */ namespace Magento\AdvancedPricingImportExport\Controller\Adminhtml\Export; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\ImportExport\Controller\Adminhtml\Export as ExportController; use Magento\Framework\Controller\ResultFactory; use Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing as ExportAdvancedPricing; use Magento\Catalog\Model\Product as CatalogProduct; -class GetFilter extends ExportController +class GetFilter extends ExportController implements HttpGetActionInterface, HttpPostActionInterface { /** * Get grid-filter of entity attributes action. diff --git a/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php b/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php index ff9126a83d59f..87666cb880e54 100644 --- a/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php +++ b/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php @@ -5,6 +5,7 @@ */ namespace Magento\Analytics\Controller\Adminhtml\BIEssentials; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -12,7 +13,7 @@ /** * Provides link to BI Essentials signup */ -class SignUp extends Action +class SignUp extends Action implements HttpGetActionInterface { /** * Path to config value with URL to BI Essentials sign-up page. diff --git a/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php b/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php index cec09377770b0..9068654fa944f 100644 --- a/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php +++ b/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php @@ -5,6 +5,7 @@ */ namespace Magento\Analytics\Controller\Adminhtml\Reports; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Analytics\Model\Exception\State\SubscriptionUpdateException; use Magento\Analytics\Model\ReportUrlProvider; use Magento\Backend\App\Action; @@ -16,7 +17,7 @@ /** * Provide redirect to resource with reports. */ -class Show extends Action +class Show extends Action implements HttpGetActionInterface { /** * @var ReportUrlProvider diff --git a/app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php b/app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php index 92957481b9290..3c1cb90e0c0a5 100644 --- a/app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php +++ b/app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php @@ -6,6 +6,7 @@ namespace Magento\Authorizenet\Controller\Directpost\Payment; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Authorizenet\Controller\Directpost\Payment; use Magento\Authorizenet\Helper\DataFactory; use Magento\Checkout\Model\Type\Onepage; @@ -25,7 +26,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Place extends Payment +class Place extends Payment implements HttpPostActionInterface { /** * @var \Magento\Quote\Api\CartManagementInterface diff --git a/app/code/Magento/Backend/Block/Widget/Form/Container.php b/app/code/Magento/Backend/Block/Widget/Form/Container.php index 8b7babc1bb9b6..97116de6db79b 100644 --- a/app/code/Magento/Backend/Block/Widget/Form/Container.php +++ b/app/code/Magento/Backend/Block/Widget/Form/Container.php @@ -93,7 +93,7 @@ protected function _construct() 'class' => 'delete', 'onclick' => 'deleteConfirm(\'' . __( 'Are you sure you want to do this?' - ) . '\', \'' . $this->getDeleteUrl() . '\')' + ) . '\', \'' . $this->getDeleteUrl() . '\', {data: {}})' ] ); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Auth/DeniedJson.php b/app/code/Magento/Backend/Controller/Adminhtml/Auth/DeniedJson.php index ad4546097768a..23731e29f0df4 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Auth/DeniedJson.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Auth/DeniedJson.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\Auth; -class DeniedJson extends \Magento\Backend\Controller\Adminhtml\Auth +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class DeniedJson extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGetActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php index e1ea57f63035e..1de77c810f316 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php @@ -6,11 +6,14 @@ */ namespace Magento\Backend\Controller\Adminhtml\Auth; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGet; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPost; + /** * @api * @since 100.0.2 */ -class Login extends \Magento\Backend\Controller\Adminhtml\Auth +class Login extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGet, HttpPost { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php index e55c449a0e5bb..d7ad080395e29 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php @@ -6,7 +6,10 @@ */ namespace Magento\Backend\Controller\Adminhtml\Auth; -class Logout extends \Magento\Backend\Controller\Adminhtml\Auth +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGet; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPost; + +class Logout extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGet, HttpPost { /** * Administrator logout action diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php index 888ce11313b8a..79bc19256d270 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php @@ -6,10 +6,11 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Controller\ResultFactory; -class CleanImages extends \Magento\Backend\Controller\Adminhtml\Cache +class CleanImages extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php index 5df0a7779c4c1..36aca1afcc480 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php @@ -6,10 +6,11 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Controller\ResultFactory; -class CleanMedia extends \Magento\Backend\Controller\Adminhtml\Cache +class CleanMedia extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php index 489eb5799a5e7..a3a26c5cf6242 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php @@ -6,9 +6,10 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; -class CleanStaticFiles extends \Magento\Backend\Controller\Adminhtml\Cache +class CleanStaticFiles extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php index a2f18b4baf53d..daf424d14c55b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; -class FlushAll extends \Magento\Backend\Controller\Adminhtml\Cache +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class FlushAll extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php index 90ed3432fa87b..f3474bf43872b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; -class FlushSystem extends \Magento\Backend\Controller\Adminhtml\Cache +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class FlushSystem extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/Index.php index 05bd309ca620e..f1e908bb842ee 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; -class Index extends \Magento\Backend\Controller\Adminhtml\Cache +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface { /** * Display cache management grid diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/Index.php index d8c52f6c50bba..decca6837fa00 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/Index.php @@ -6,7 +6,11 @@ */ namespace Magento\Backend\Controller\Adminhtml\Dashboard; -class Index extends \Magento\Backend\Controller\Adminhtml\Dashboard +use Magento\Backend\Controller\Adminhtml\Dashboard as DashboardAction; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Index extends DashboardAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Index/GlobalSearch.php b/app/code/Magento/Backend/Controller/Adminhtml/Index/GlobalSearch.php index 9ca4021d08356..37f3064aeaa38 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Index/GlobalSearch.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Index/GlobalSearch.php @@ -6,11 +6,15 @@ */ namespace Magento\Backend\Controller\Adminhtml\Index; +use Magento\Backend\Controller\Adminhtml\Index as IndexAction; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + /** * @api * @since 100.0.2 */ -class GlobalSearch extends \Magento\Backend\Controller\Adminhtml\Index +class GlobalSearch extends IndexAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php index a5c71fb2dbc5c..afb1b4573271d 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php @@ -6,7 +6,10 @@ */ namespace Magento\Backend\Controller\Adminhtml\Index; -class Index extends \Magento\Backend\Controller\Adminhtml\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGet; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPost; + +class Index extends \Magento\Backend\Controller\Adminhtml\Index implements HttpGet, HttpPost { /** * Admin area entry point diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php index ce59d2fd48e5a..e84987d8e1d70 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php @@ -6,6 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\Noroute; +/** + * @SuppressWarnings(PHPMD.AllPurposeAction) + */ class Index extends \Magento\Backend\App\Action { /** diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Index.php index 54771bfdc1a7d..648f1be86f56c 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Account; -class Index extends \Magento\Backend\Controller\Adminhtml\System\Account +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Backend\Controller\Adminhtml\System\Account implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Index.php index 30b26f2294193..c6a05b5a71d0c 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Design; -class Index extends \Magento\Backend\Controller\Adminhtml\System\Design +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Backend\Controller\Adminhtml\System\Design implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsite.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsite.php index d86f57daa396c..9e8664b8ecd11 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsite.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsite.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; -class DeleteWebsite extends \Magento\Backend\Controller\Adminhtml\System\Store +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class DeleteWebsite extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpGetActionInterface { /** * @return \Magento\Framework\Controller\ResultInterface diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php index 1fca5a896e050..460b44c4f480e 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php @@ -6,9 +6,10 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store +class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php index a8651984cfa63..e5cd43b521fd1 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; -class EditStore extends \Magento\Backend\Controller\Adminhtml\System\Store +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class EditStore extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpGetActionInterface { /** * @return \Magento\Framework\Controller\ResultInterface diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditWebsite.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditWebsite.php index bfdf7cdbeb8fb..74ed7951e6214 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditWebsite.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditWebsite.php @@ -6,7 +6,9 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; -class EditWebsite extends \Magento\Backend\Controller\Adminhtml\System\Store +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class EditWebsite extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Forward diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Index.php index b104704f41bdb..54da065c4af91 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Index.php @@ -6,12 +6,13 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; /** * Class Index returns Stores page */ -class Index extends \Magento\Backend\Controller\Adminhtml\System\Store +class Index extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpGetActionInterface { /** * Returns Stores page diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php index 910511c2b275e..b67f1f23f16ba 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php @@ -6,12 +6,14 @@ */ namespace Magento\Backend\Controller\Adminhtml\System\Store; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + /** * Class Save * * Save controller for system entities such as: Store, StoreGroup, Website */ -class Save extends \Magento\Backend\Controller\Adminhtml\System\Store +class Save extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface { /** * Process Website model save diff --git a/app/code/Magento/Backend/etc/adminhtml/di.xml b/app/code/Magento/Backend/etc/adminhtml/di.xml index d8e9674d2b4cb..3384384343fe9 100644 --- a/app/code/Magento/Backend/etc/adminhtml/di.xml +++ b/app/code/Magento/Backend/etc/adminhtml/di.xml @@ -14,8 +14,6 @@ - Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT @@ -169,4 +167,5 @@ Magento\Backend\Block\Template + diff --git a/app/code/Magento/Backup/Controller/Adminhtml/Index/Index.php b/app/code/Magento/Backup/Controller/Adminhtml/Index/Index.php index 3bbda65cb4cf6..271e3713034d0 100644 --- a/app/code/Magento/Backup/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/Backup/Controller/Adminhtml/Index/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Backup\Controller\Adminhtml\Index; -class Index extends \Magento\Backup\Controller\Adminhtml\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Backup\Controller\Adminhtml\Index implements HttpGetActionInterface { /** * Backup list action diff --git a/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php b/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php index e06b913db8ef4..e6c5ee22c62b4 100644 --- a/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php +++ b/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php @@ -47,6 +47,8 @@ public function __construct(Config $config, ResolverInterface $resolver) */ public function getConfig() { + $requireBillingAddressAll = \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL; + return [ 'payment' => [ self::PAYPAL_CODE => [ @@ -60,6 +62,8 @@ public function getConfig() 'vaultCode' => self::PAYPAL_VAULT_CODE, 'skipOrderReview' => $this->config->isSkipOrderReview(), 'paymentIcon' => $this->config->getPayPalIcon(), + 'isRequiredBillingAddress' => + (int)$this->config->isRequiredBillingAddress() === $requireBillingAddressAll ] ] ]; diff --git a/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php b/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php index 22f7f46bd98f1..42469fe0faf45 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php @@ -77,6 +77,9 @@ public function testGetConfig($expected) 'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url' ]); + $this->config->method('isRequiredBillingAddress') + ->willReturn(1); + self::assertEquals($expected, $this->configProvider->getConfig()); } @@ -101,7 +104,8 @@ public function getConfigDataProvider() 'skipOrderReview' => false, 'paymentIcon' => [ 'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url' - ] + ], + 'isRequiredBillingAddress' => true ] ] ] diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js index 7c75cc3e594ee..abf434bc6da26 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js @@ -206,7 +206,9 @@ define([ beforePlaceOrder: function (data) { this.setPaymentMethodNonce(data.nonce); - if (quote.billingAddress() === null && typeof data.details.billingAddress !== 'undefined') { + if ((this.isRequiredBillingAddress() || quote.billingAddress() === null) && + typeof data.details.billingAddress !== 'undefined' + ) { this.setBillingAddress(data.details, data.details.billingAddress); } @@ -264,6 +266,14 @@ define([ return window.checkoutConfig.payment[this.getCode()].isAllowShippingAddressOverride; }, + /** + * Is billing address required from PayPal side + * @returns {Boolean} + */ + isRequiredBillingAddress: function () { + return window.checkoutConfig.payment[this.getCode()].isRequiredBillingAddress; + }, + /** * Get configuration for PayPal * @returns {Object} diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index a2a02cbd715bd..d25f856e0b40d 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -6,13 +6,13 @@ namespace Magento\Bundle\Model\Product; -use Magento\Framework\App\ObjectManager; +use Magento\Bundle\Model\ResourceModel\Selection\Collection as Selections; +use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier as SelectionCollectionFilterApplier; use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Serialize\Serializer\Json; -use Magento\Framework\EntityManager\MetadataPool; -use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier as SelectionCollectionFilterApplier; -use Magento\Bundle\Model\ResourceModel\Selection\Collection as Selections; /** * Bundle Type Model @@ -537,7 +537,7 @@ public function updateQtyOption($options, \Magento\Framework\DataObject $option, foreach ($options as $quoteItemOption) { if ($quoteItemOption->getCode() == 'selection_qty_' . $selection->getSelectionId()) { if ($optionUpdateFlag) { - $quoteItemOption->setValue(intval($quoteItemOption->getValue())); + $quoteItemOption->setValue((int) $quoteItemOption->getValue()); } else { $quoteItemOption->setValue($value); } @@ -625,6 +625,7 @@ public function isSalable($product) /** * Prepare product and its configuration to be added to some products list. + * * Perform standard preparation process and then prepare of bundle selections options. * * @param \Magento\Framework\DataObject $buyRequest @@ -790,6 +791,8 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p } /** + * Cast array values to int + * * @param array $array * @return int[]|int[][] */ @@ -809,6 +812,8 @@ private function recursiveIntval(array $array) } /** + * Convert multi dimensional array to flat + * * @param array $array * @return int[] */ @@ -920,8 +925,7 @@ public function getOptionsByIds($optionIds, $product) } /** - * Prepare additional options/information for order item which will be - * created from this product + * Prepare additional options/information for order item which will be created from this product * * @param \Magento\Catalog\Model\Product $product * @return array @@ -987,6 +991,7 @@ public function getOrderOptions($product) /** * Sort selections method for usort function + * * Sort selections by option position, selection position and selection id * * @param \Magento\Catalog\Model\Product $firstItem @@ -1050,6 +1055,7 @@ public function getForceChildItemQtyChanges($product) /** * Retrieve additional searchable data from type instance + * * Using based on product id and store_id data * * @param \Magento\Catalog\Model\Product $product @@ -1118,6 +1124,7 @@ public function checkProductBuyState($product) /** * Retrieve products divided into groups required to purchase + * * At least one product in each group has to be purchased * * @param \Magento\Catalog\Model\Product $product @@ -1214,6 +1221,8 @@ public function getIdentities(\Magento\Catalog\Model\Product $product) } /** + * Returns selection qty + * * @param \Magento\Framework\DataObject $selection * @param int[] $qtys * @param int $selectionOptionId @@ -1232,6 +1241,8 @@ protected function getQty($selection, $qtys, $selectionOptionId) } /** + * Returns qty + * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\DataObject $selection * @return float|int @@ -1249,6 +1260,8 @@ protected function getBeforeQty($product, $selection) } /** + * Validate required options + * * @param \Magento\Catalog\Model\Product $product * @param bool $isStrictProcessMode * @param \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection @@ -1270,6 +1283,8 @@ protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $op } /** + * Check if selection is salable + * * @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selections * @param bool $skipSaleableCheck * @param \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection @@ -1300,6 +1315,8 @@ protected function checkSelectionsIsSale($selections, $skipSaleableCheck, $optio } /** + * Validate result + * * @param array $_result * @return void * @throws \Magento\Framework\Exception\LocalizedException @@ -1318,6 +1335,8 @@ protected function checkIsResult($_result) } /** + * Merge selections with options + * * @param \Magento\Catalog\Model\Product\Option[] $options * @param \Magento\Framework\DataObject[] $selections * @return \Magento\Framework\DataObject[] diff --git a/app/code/Magento/Bundle/Test/Mftf/ActionGroup/CreateBundleProductActionGroup.xml b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/CreateBundleProductActionGroup.xml index 6e889ea2432e7..72e729111948f 100644 --- a/app/code/Magento/Bundle/Test/Mftf/ActionGroup/CreateBundleProductActionGroup.xml +++ b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/CreateBundleProductActionGroup.xml @@ -15,11 +15,12 @@ - - + + + - + diff --git a/app/code/Magento/Captcha/Controller/Refresh/Index.php b/app/code/Magento/Captcha/Controller/Refresh/Index.php index e89a80646ed8e..e401e03e9551f 100644 --- a/app/code/Magento/Captcha/Controller/Refresh/Index.php +++ b/app/code/Magento/Captcha/Controller/Refresh/Index.php @@ -8,9 +8,10 @@ */ namespace Magento\Captcha\Controller\Refresh; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\Action\Context; -class Index extends \Magento\Framework\App\Action\Action +class Index extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface { /** * @var \Magento\Captcha\Helper\Data diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/DeleteButton.php b/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/DeleteButton.php index 20411a4c4d767..2eef1188e3910 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/DeleteButton.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/DeleteButton.php @@ -27,7 +27,8 @@ public function getButtonData() return [ 'id' => 'delete', 'label' => __('Delete'), - 'on_click' => "categoryDelete('" . $this->getDeleteUrl() . "')", + 'on_click' => "deleteConfirm('" .__('Are you sure you want to delete this category?') ."', '" + . $this->getDeleteUrl() . "', {data: {}})", 'class' => 'delete', 'sort_order' => 10 ]; diff --git a/app/code/Magento/Catalog/Block/Product/View/Gallery.php b/app/code/Magento/Catalog/Block/Product/View/Gallery.php index 8de765afd80a4..706d9b83b9711 100644 --- a/app/code/Magento/Catalog/Block/Product/View/Gallery.php +++ b/app/code/Magento/Catalog/Block/Product/View/Gallery.php @@ -23,6 +23,8 @@ use Magento\Framework\Stdlib\ArrayUtils; /** + * Product gallery block + * * @api * @since 100.0.2 */ @@ -139,7 +141,7 @@ public function getGalleryImagesJson() 'thumb' => $image->getData('small_image_url'), 'img' => $image->getData('medium_image_url'), 'full' => $image->getData('large_image_url'), - 'caption' => $image->getData('label'), + 'caption' => ($image->getLabel() ?: $this->getProduct()->getName()), 'position' => $image->getData('position'), 'isMain' => $this->isMainImage($image), 'type' => str_replace('external-', '', $image->getMediaType()), @@ -196,6 +198,8 @@ public function isMainImage($image) } /** + * Returns image attribute + * * @param string $imageId * @param string $attributeName * @param string $default @@ -222,6 +226,8 @@ private function getConfigView() } /** + * Returns image gallery config object + * * @return Collection */ private function getGalleryImagesConfig() diff --git a/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php b/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php index 704271b58f483..b4c24231a7415 100644 --- a/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php +++ b/app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php @@ -139,7 +139,7 @@ public function getCacheKeyInfo() [ $this->getDisplayType(), $this->getProductsPerPage(), - intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)), + (int) $this->getRequest()->getParam($this->getData('page_var_name'), 1), $this->serializer->serialize($this->getRequest()->getParams()) ] ); diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php index 6456b6d578bbb..733e270174e4c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php @@ -6,12 +6,14 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + /** * Class Add Category * * @package Magento\Catalog\Controller\Adminhtml\Category */ -class Add extends \Magento\Catalog\Controller\Adminhtml\Category +class Add extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpGetActionInterface { /** * Forward factory for result diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php index b8865f2de8d1e..752257f5b9009 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class CategoriesJson extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class CategoriesJson extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php index 0a54475b15f9c..39122d139c90b 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class Delete extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpPostActionInterface { /** * @var \Magento\Catalog\Api\CategoryRepositoryInterface diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php index 6ff478e49a30c..0450ff1607a09 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class Edit extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpGetActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php index 902d71775a3d8..5089b37f90c58 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class Index extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpGetActionInterface { /** * @var \Magento\Backend\Model\View\Result\ForwardFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php index df2c80eda141c..ba6bfddca9c6c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class Move extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Move extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory @@ -26,7 +28,7 @@ class Move extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory - * @param \Magento\Framework\View\LayoutFactory $layoutFactory, + * @param \Magento\Framework\View\LayoutFactory $layoutFactory * @param \Psr\Log\LoggerInterface $logger */ public function __construct( diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php index 9384397b67f93..046ebbb119e5b 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; -class RefreshPath extends \Magento\Catalog\Controller\Adminhtml\Category +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class RefreshPath extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpGetActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index aa9ae88754b6a..11c0a73a73708 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -6,6 +6,7 @@ namespace Magento\Catalog\Controller\Adminhtml\Category; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Catalog\Api\Data\CategoryAttributeInterface; use Magento\Store\Model\StoreManagerInterface; @@ -14,7 +15,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Catalog\Controller\Adminhtml\Category +class Save extends \Magento\Catalog\Controller\Adminhtml\Category implements HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\RawFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Validate.php index 4eda49068ac3a..66a5fb1008a78 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Validate.php @@ -5,10 +5,14 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Category; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\Catalog\Controller\Adminhtml\Category as CategoryAction; + /** * Catalog category validate */ -class Validate extends \Magento\Catalog\Controller\Adminhtml\Category +class Validate extends CategoryAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php index 7eb391dedf81c..3cba09b1e8e9a 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php @@ -6,10 +6,18 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Ui\Component\MassAction\Filter; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute as AttributeAction; -class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute +/** + * Form for mass updatings products' attributes. + * Can be accessed by GET since it's a form, + * can be accessed by POST since it's used as a processor of a mass-action button. + */ +class Edit extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php index 0fbf9054ef1bd..0730e7a7c5dc1 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php @@ -6,13 +6,14 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; /** * Class Save * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute +class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute implements HttpPostActionInterface { /** * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php index a873f08d082d7..30a6629dd1c29 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php @@ -6,7 +6,11 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute; -class Validate extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute as AttributeAction; + +class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\JsonFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php index bef6aee0e2afd..faa9e4ddf49b4 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; -class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php index a99cbdbade181..a41cd71aea463 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; -class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute implements HttpGetActionInterface { /** * @return \Magento\Framework\Controller\ResultInterface diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Index.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Index.php index 9bdc54b289c20..34267121f9b8b 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Index.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; -class Index extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/NewAction.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/NewAction.php index e954d9730591c..fdfde7e806096 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/NewAction.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; -class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute implements HttpGetActionInterface { /** * @var \Magento\Backend\Model\View\Result\ForwardFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 817de6828e48d..84ad6d2116726 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -7,6 +7,7 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\Redirect; use Magento\Catalog\Api\Data\ProductAttributeInterface; @@ -33,7 +34,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends Attribute +class Save extends Attribute implements HttpPostActionInterface { /** * @var BuildFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php index db452113ada06..dac92f9b2eb9e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -7,9 +7,12 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\DataObject; +use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction; -class Validate extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute +class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { const DEFAULT_MESSAGE_KEY = 'message'; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php index 1b9316a95ad59..c31ceabcda655 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; -class Edit extends \Magento\Catalog\Controller\Adminhtml\Product +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface { /** * Array of actions which can be processed without secret key validation diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php index b5660ea87934c..ff7311e931755 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php @@ -6,9 +6,10 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Gallery; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; -class Upload extends \Magento\Backend\App\Action +class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Index.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Index.php index ea66ecf6b1622..7755a512eb9b4 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Index.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; -class Index extends \Magento\Catalog\Controller\Adminhtml\Product +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index f32c6edd57394..8fceba3c45e2c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -6,13 +6,14 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Backend\App\Action\Context; use Magento\Ui\Component\MassAction\Filter; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; use Magento\Catalog\Api\ProductRepositoryInterface; -class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product +class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface { /** * Massactions filter diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php index e3623aabfa1a3..b7655f7ee2862 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php @@ -6,6 +6,7 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Catalog\Controller\Adminhtml\Product; use Magento\Framework\Controller\ResultFactory; @@ -15,7 +16,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product +class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface { /** * @var \Magento\Catalog\Model\Indexer\Product\Price\Processor diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php index 0b027105cd7d4..0b1ef98c386c4 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php @@ -6,11 +6,12 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Catalog\Controller\Adminhtml\Product; use Magento\Framework\App\ObjectManager; -class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product +class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface { /** * @var Initialization\StockDataFilter diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Reload.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Reload.php index ff87e7f57413f..a0963e60d888d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Reload.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Reload.php @@ -5,12 +5,13 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; /** * Backend reload of product create/edit form */ -class Reload extends \Magento\Catalog\Controller\Adminhtml\Product +class Reload extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface { /** * {@inheritdoc} diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php index 562fe9278e8a9..e84d9ff12906e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php @@ -7,6 +7,7 @@ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Controller\Adminhtml\Product; @@ -17,7 +18,7 @@ * Class Save * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Catalog\Controller\Adminhtml\Product +class Save extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface { /** * @var Initialization\Helper diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Add.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Add.php index 480c30322a073..bfe474abba1b8 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Add.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Add.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; -class Add extends \Magento\Catalog\Controller\Adminhtml\Product\Set +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Add extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php index f2695311732f0..771cc83f79e80 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; -class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Set +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpPostActionInterface { /** * @var \Magento\Eav\Api\AttributeSetRepositoryInterface diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php index ec540180b0345..6f6870cb0849f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; -class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Set +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Index.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Index.php index 29f7dff4f0d47..aadf724f6006e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Index.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; -class Index extends \Magento\Catalog\Controller\Adminhtml\Product\Set +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php index c5dd9ce6d8e77..83620de25b012 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php @@ -6,12 +6,13 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\ObjectManager; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set +class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpPostActionInterface { /** * @var \Magento\Framework\View\LayoutFactory diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php index e131bfe38c546..77c9cfcd40f05 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php @@ -6,6 +6,8 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Catalog\Controller\Adminhtml\Product; use Magento\Framework\App\ObjectManager; @@ -16,7 +18,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Validate extends \Magento\Catalog\Controller\Adminhtml\Product +class Validate extends Product implements HttpPostActionInterface, HttpGetActionInterface { /** * @var \Magento\Framework\Stdlib\DateTime\Filter\Date diff --git a/app/code/Magento/Catalog/Controller/Category/View.php b/app/code/Magento/Catalog/Controller/Category/View.php index 226e572505076..19243aabb1b71 100644 --- a/app/code/Magento/Catalog/Controller/Category/View.php +++ b/app/code/Magento/Catalog/Controller/Category/View.php @@ -6,15 +6,20 @@ */ namespace Magento\Catalog\Controller\Category; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Model\Layer\Resolver; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\App\Action\Action; /** + * View a category on storefront. Needs to be accessible by POST because of the store switching. + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class View extends \Magento\Framework\App\Action\Action +class View extends Action implements HttpGetActionInterface, HttpPostActionInterface { /** * Core registry diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Add.php b/app/code/Magento/Catalog/Controller/Product/Compare/Add.php index eb9cc83125541..d99901c915a10 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Add.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Add.php @@ -6,9 +6,10 @@ */ namespace Magento\Catalog\Controller\Product\Compare; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\NoSuchEntityException; -class Add extends \Magento\Catalog\Controller\Product\Compare +class Add extends \Magento\Catalog\Controller\Product\Compare implements HttpPostActionInterface { /** * Add item to compare list diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php index 568fbf1d05677..2703e9869bd47 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php @@ -6,9 +6,10 @@ */ namespace Magento\Catalog\Controller\Product\Compare; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class Clear extends \Magento\Catalog\Controller\Product\Compare +class Clear extends \Magento\Catalog\Controller\Product\Compare implements HttpPostActionInterface { /** * Remove all items from comparison list diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Index.php b/app/code/Magento/Catalog/Controller/Product/Compare/Index.php index 3eba058318a7d..c0aa32a56ed17 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Index.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Index.php @@ -6,6 +6,7 @@ */ namespace Magento\Catalog\Controller\Product\Compare; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Framework\View\Result\PageFactory; @@ -13,7 +14,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Index extends \Magento\Catalog\Controller\Product\Compare +class Index extends \Magento\Catalog\Controller\Product\Compare implements HttpGetActionInterface { /** * @var \Magento\Framework\Url\DecoderInterface diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php b/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php index 2acbe5ce4d582..eac0ddf94af20 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php @@ -6,9 +6,10 @@ */ namespace Magento\Catalog\Controller\Product\Compare; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\NoSuchEntityException; -class Remove extends \Magento\Catalog\Controller\Product\Compare +class Remove extends \Magento\Catalog\Controller\Product\Compare implements HttpPostActionInterface { /** * Remove item from compare list diff --git a/app/code/Magento/Catalog/Controller/Product/View.php b/app/code/Magento/Catalog/Controller/Product/View.php index ed437361fddd3..024123e15150d 100644 --- a/app/code/Magento/Catalog/Controller/Product/View.php +++ b/app/code/Magento/Catalog/Controller/Product/View.php @@ -6,10 +6,16 @@ */ namespace Magento\Catalog\Controller\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; +use Magento\Catalog\Controller\Product as ProductAction; -class View extends \Magento\Catalog\Controller\Product +/** + * View a product on storefront. Needs to be accessible by POST because of the store switching. + */ +class View extends ProductAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Catalog\Helper\Product\View diff --git a/app/code/Magento/Catalog/Model/Category.php b/app/code/Magento/Catalog/Model/Category.php index cf79ff01d3157..999f08aa1ea6e 100644 --- a/app/code/Magento/Catalog/Model/Category.php +++ b/app/code/Magento/Catalog/Model/Category.php @@ -300,7 +300,7 @@ protected function _construct() } /** - * {@inheritdoc} + * @inheritdoc */ protected function getCustomAttributesCodes() { @@ -312,6 +312,8 @@ protected function getCustomAttributesCodes() } /** + * Returns model resource + * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Catalog\Model\ResourceModel\Category * @deprecated because resource models should be used directly @@ -648,6 +650,8 @@ public function formatUrlKey($str) } /** + * Returns image url + * * @param string $attributeCode * @return bool|string * @throws \Magento\Framework\Exception\LocalizedException @@ -708,7 +712,7 @@ public function getParentId() return $parentId; } $parentIds = $this->getParentIds(); - return intval(array_pop($parentIds)); + return (int) array_pop($parentIds); } /** @@ -796,6 +800,7 @@ public function getChildren($recursive = false, $isActive = true, $sortByPositio /** * Retrieve Stores where isset category Path + * * Return comma separated string * * @return string @@ -826,6 +831,7 @@ public function checkId($id) /** * Get array categories ids which are part of category path + * * Result array contain id of current category because it is part of the path * * @return array @@ -1029,7 +1035,8 @@ public function getAvailableSortBy() /** * Retrieve Available Product Listing Sort By - * code as key, value - name + * + * Code as key, value - name * * @return array */ @@ -1150,6 +1157,8 @@ public function getIdentities() } /** + * Returns path + * * @codeCoverageIgnoreStart * @return string|null */ @@ -1159,6 +1168,8 @@ public function getPath() } /** + * Returns position + * * @return int|null */ public function getPosition() @@ -1167,6 +1178,8 @@ public function getPosition() } /** + * Returns children count + * * @return int */ public function getChildrenCount() @@ -1175,6 +1188,8 @@ public function getChildrenCount() } /** + * Returns created at + * * @return string|null */ public function getCreatedAt() @@ -1183,6 +1198,8 @@ public function getCreatedAt() } /** + * Returns updated at + * * @return string|null */ public function getUpdatedAt() @@ -1191,6 +1208,8 @@ public function getUpdatedAt() } /** + * Returns is active + * * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ @@ -1200,6 +1219,8 @@ public function getIsActive() } /** + * Returns category id + * * @return int|null */ public function getCategoryId() @@ -1208,6 +1229,8 @@ public function getCategoryId() } /** + * Returns display mode + * * @return string|null */ public function getDisplayMode() @@ -1216,6 +1239,8 @@ public function getDisplayMode() } /** + * Returns is include in menu + * * @return bool|null */ public function getIncludeInMenu() @@ -1224,6 +1249,8 @@ public function getIncludeInMenu() } /** + * Returns url key + * * @return string|null */ public function getUrlKey() @@ -1232,6 +1259,8 @@ public function getUrlKey() } /** + * Returns children data + * * @return \Magento\Catalog\Api\Data\CategoryTreeInterface[]|null */ public function getChildrenData() @@ -1347,6 +1376,8 @@ public function setLevel($level) } /** + * Set updated at + * * @param string $updatedAt * @return $this */ @@ -1356,6 +1387,8 @@ public function setUpdatedAt($updatedAt) } /** + * Set created at + * * @param string $createdAt * @return $this */ @@ -1365,6 +1398,8 @@ public function setCreatedAt($createdAt) } /** + * Set path + * * @param string $path * @return $this */ @@ -1374,6 +1409,8 @@ public function setPath($path) } /** + * Set available sort by + * * @param string[]|string $availableSortBy * @return $this */ @@ -1383,6 +1420,8 @@ public function setAvailableSortBy($availableSortBy) } /** + * Set include in menu + * * @param bool $includeInMenu * @return $this */ @@ -1403,6 +1442,8 @@ public function setProductCount($productCount) } /** + * Set children data + * * @param \Magento\Catalog\Api\Data\CategoryTreeInterface[] $childrenData * @return $this */ @@ -1412,7 +1453,7 @@ public function setChildrenData(array $childrenData = null) } /** - * {@inheritdoc} + * @inheritdoc * * @return \Magento\Catalog\Api\Data\CategoryExtensionInterface|null */ @@ -1422,7 +1463,7 @@ public function getExtensionAttributes() } /** - * {@inheritdoc} + * @inheritdoc * * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes * @return $this diff --git a/app/code/Magento/Catalog/Model/ImageExtractor.php b/app/code/Magento/Catalog/Model/ImageExtractor.php index 1c20608670672..dcc70cbcd2a1a 100644 --- a/app/code/Magento/Catalog/Model/ImageExtractor.php +++ b/app/code/Magento/Catalog/Model/ImageExtractor.php @@ -9,6 +9,9 @@ use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter; use Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface; +/** + * Image extractor from xml configuration + */ class ImageExtractor implements TypeDataExtractorInterface { /** @@ -36,7 +39,7 @@ public function process(\DOMElement $mediaNode, $mediaParentTag) if ($attributeTagName === 'background') { $nodeValue = $this->processImageBackground($attribute->nodeValue); } elseif ($attributeTagName === 'width' || $attributeTagName === 'height') { - $nodeValue = intval($attribute->nodeValue); + $nodeValue = (int) $attribute->nodeValue; } else { $nodeValue = $attribute->nodeValue; } diff --git a/app/code/Magento/Catalog/Model/Product/Compare/Item.php b/app/code/Magento/Catalog/Model/Product/Compare/Item.php index 3b7e47a46a0a3..fd07380bebd7a 100644 --- a/app/code/Magento/Catalog/Model/Product/Compare/Item.php +++ b/app/code/Magento/Catalog/Model/Product/Compare/Item.php @@ -158,8 +158,8 @@ public function addProductData($product) { if ($product instanceof Product) { $this->setProductId($product->getId()); - } elseif (intval($product)) { - $this->setProductId(intval($product)); + } elseif ((int) $product) { + $this->setProductId((int) $product); } return $this; diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php b/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php index bd28b65bb7982..65111979c5d3a 100644 --- a/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php @@ -102,6 +102,8 @@ public function __construct( } /** + * Execute create handler + * * @param object $product * @param array $arguments * @return object @@ -167,23 +169,19 @@ public function execute($product, $arguments = []) if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) { continue; } - if (in_array($attrData, $clearImages)) { - $product->setData($mediaAttrCode, 'no_selection'); - } - - if (in_array($attrData, array_keys($newImages))) { - $product->setData($mediaAttrCode, $newImages[$attrData]['new_file']); - $product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']); - } - - if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) { - $product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']); - } - if (!empty($product->getData($mediaAttrCode))) { - $product->addAttributeUpdate( + $this->processMediaAttribute( + $product, + $mediaAttrCode, + $clearImages, + $newImages + ); + if (in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])) { + $this->processMediaAttributeLabel( + $product, $mediaAttrCode, - $product->getData($mediaAttrCode), - $product->getStoreId() + $clearImages, + $newImages, + $existImages ); } } @@ -208,6 +206,8 @@ public function execute($product, $arguments = []) } /** + * Returns media gallery atribute instance + * * @return \Magento\Catalog\Api\Data\ProductAttributeInterface * @since 101.0.0 */ @@ -223,6 +223,8 @@ public function getAttribute() } /** + * Process delete images + * * @param \Magento\Catalog\Model\Product $product * @param array $images * @return void @@ -234,6 +236,8 @@ protected function processDeletedImages($product, array &$images) } /** + * Process images + * * @param \Magento\Catalog\Model\Product $product * @param array $images * @return void @@ -296,6 +300,8 @@ protected function processNewImage($product, array &$image) } /** + * Duplicate attribute + * * @param \Magento\Catalog\Model\Product $product * @return $this * @since 101.0.0 @@ -364,6 +370,8 @@ private function getSafeFilename($file) } /** + * Returns file name according to tmp name + * * @param string $file * @return string * @since 101.0.0 @@ -449,4 +457,81 @@ private function getMediaAttributeCodes() } return $this->mediaAttributeCodes; } + + /** + * Process media attribute + * + * @param \Magento\Catalog\Model\Product $product + * @param string $mediaAttrCode + * @param array $clearImages + * @param array $newImages + */ + private function processMediaAttribute( + \Magento\Catalog\Model\Product $product, + $mediaAttrCode, + array $clearImages, + array $newImages + ) { + $attrData = $product->getData($mediaAttrCode); + if (in_array($attrData, $clearImages)) { + $product->setData($mediaAttrCode, 'no_selection'); + } + + if (in_array($attrData, array_keys($newImages))) { + $product->setData($mediaAttrCode, $newImages[$attrData]['new_file']); + } + if (!empty($product->getData($mediaAttrCode))) { + $product->addAttributeUpdate( + $mediaAttrCode, + $product->getData($mediaAttrCode), + $product->getStoreId() + ); + } + } + + /** + * Process media attribute label + * + * @param \Magento\Catalog\Model\Product $product + * @param string $mediaAttrCode + * @param array $clearImages + * @param array $newImages + * @param array $existImages + */ + private function processMediaAttributeLabel( + \Magento\Catalog\Model\Product $product, + $mediaAttrCode, + array $clearImages, + array $newImages, + array $existImages + ) { + $resetLabel = false; + $attrData = $product->getData($mediaAttrCode); + if (in_array($attrData, $clearImages)) { + $product->setData($mediaAttrCode . '_label', null); + $resetLabel = true; + } + + if (in_array($attrData, array_keys($newImages))) { + $product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']); + } + + if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) { + $product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']); + } + + if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) { + $product->setData($mediaAttrCode . '_label', null); + $resetLabel = true; + } + if (!empty($product->getData($mediaAttrCode . '_label')) + || $resetLabel === true + ) { + $product->addAttributeUpdate( + $mediaAttrCode . '_label', + $product->getData($mediaAttrCode . '_label'), + $product->getStoreId() + ); + } + } } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index 7517459da650f..b19906ecd6cc9 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -102,11 +102,11 @@ public function validateUserValue($values) $this->setUserValue( [ 'date' => isset($value['date']) ? $value['date'] : '', - 'year' => isset($value['year']) ? intval($value['year']) : 0, - 'month' => isset($value['month']) ? intval($value['month']) : 0, - 'day' => isset($value['day']) ? intval($value['day']) : 0, - 'hour' => isset($value['hour']) ? intval($value['hour']) : 0, - 'minute' => isset($value['minute']) ? intval($value['minute']) : 0, + 'year' => isset($value['year']) ? (int) $value['year'] : 0, + 'month' => isset($value['month']) ? (int) $value['month'] : 0, + 'day' => isset($value['day']) ? (int) $value['day'] : 0, + 'hour' => isset($value['hour']) ? (int) $value['hour'] : 0, + 'minute' => isset($value['minute']) ? (int) $value['minute'] : 0, 'day_part' => isset($value['day_part']) ? $value['day_part'] : '', 'date_internal' => isset($value['date_internal']) ? $value['date_internal'] : '', ] diff --git a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php index ee508e30cc93e..99d5016f5cdb9 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Validator/DefaultValidator.php @@ -9,6 +9,9 @@ use Magento\Catalog\Model\Product\Option; use Zend_Validate_Exception; +/** + * Product option default validator + */ class DefaultValidator extends \Magento\Framework\Validator\AbstractValidator { /** @@ -168,6 +171,6 @@ protected function isInRange($value, array $range) */ protected function isNegative($value) { - return intval($value) < 0; + return (int) $value < 0; } } diff --git a/app/code/Magento/Catalog/Model/Product/PriceModifier.php b/app/code/Magento/Catalog/Model/Product/PriceModifier.php index 48d53b4614527..c4d5bdfedcd5f 100644 --- a/app/code/Magento/Catalog/Model/Product/PriceModifier.php +++ b/app/code/Magento/Catalog/Model/Product/PriceModifier.php @@ -9,6 +9,9 @@ use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; +/** + * Product form price modifier + */ class PriceModifier { /** @@ -26,6 +29,8 @@ public function __construct( } /** + * Remove tier price + * * @param \Magento\Catalog\Model\Product $product * @param int|string $customerGroupId * @param int $qty @@ -46,11 +51,11 @@ public function removeTierPrice(\Magento\Catalog\Model\Product $product, $custom foreach ($prices as $key => $tierPrice) { if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty - && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId) + && $tierPrice['all_groups'] == 1 && (int) $tierPrice['website_id'] === (int) $websiteId ) { unset($prices[$key]); } elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId - && intval($tierPrice['website_id']) === intval($websiteId) + && (int) $tierPrice['website_id'] === (int) $websiteId ) { unset($prices[$key]); } diff --git a/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php b/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php index 822959bfc8519..f2da1e770279e 100644 --- a/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php +++ b/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php @@ -15,6 +15,8 @@ use Magento\Framework\Exception\TemporaryStateExceptionInterface; /** + * Product tier price management + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class TierPriceManagement implements \Magento\Catalog\Api\ProductTierPriceManagementInterface @@ -82,7 +84,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -148,7 +150,7 @@ public function add($sku, $customerGroupId, $price, $qty) } /** - * {@inheritdoc} + * @inheritdoc */ public function remove($sku, $customerGroupId, $qty) { @@ -163,7 +165,7 @@ public function remove($sku, $customerGroupId, $qty) } /** - * {@inheritdoc} + * @inheritdoc */ public function getList($sku, $customerGroupId) { @@ -181,7 +183,7 @@ public function getList($sku, $customerGroupId) $prices = []; foreach ($product->getData('tier_price') as $price) { - if ((is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId)) + if ((is_numeric($customerGroupId) && (int) $price['cust_group'] === (int) $customerGroupId) || ($customerGroupId === 'all' && $price['all_groups']) ) { /** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */ diff --git a/app/code/Magento/Catalog/Model/Product/Type.php b/app/code/Magento/Catalog/Model/Product/Type.php index 7be199884be1f..4c973be20dee5 100644 --- a/app/code/Magento/Catalog/Model/Product/Type.php +++ b/app/code/Magento/Catalog/Model/Product/Type.php @@ -285,7 +285,7 @@ public function getTypesByPriority() $types = $this->getTypes(); foreach ($types as $typeId => $typeInfo) { - $priority = isset($typeInfo['index_priority']) ? abs(intval($typeInfo['index_priority'])) : 0; + $priority = isset($typeInfo['index_priority']) ? abs((int) $typeInfo['index_priority']) : 0; if (!empty($typeInfo['composite'])) { $compositePriority[$typeId] = $priority; } else { @@ -307,7 +307,7 @@ public function getTypesByPriority() } /** - * {@inheritdoc} + * @inheritdoc */ public function toOptionArray() { diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index 9de0e8a849046..1523809d9cc33 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -16,6 +16,8 @@ use Magento\Framework\EntityManager\EntityManager; /** + * Resource model for category entity + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Category extends AbstractResource @@ -249,7 +251,8 @@ public function deleteChildren(\Magento\Framework\DataObject $object) /** * Process category data before saving - * prepare path and increment children count for parent categories + * + * Prepare path and increment children count for parent categories * * @param \Magento\Framework\DataObject $object * @return $this @@ -298,7 +301,8 @@ protected function _beforeSave(\Magento\Framework\DataObject $object) /** * Process category data after save category object - * save related products ids and update path value + * + * Save related products ids and update path value * * @param \Magento\Framework\DataObject $object * @return $this @@ -664,7 +668,7 @@ public function getProductCount($category) $bind = ['category_id' => (int)$category->getId()]; $counts = $this->getConnection()->fetchOne($select, $bind); - return intval($counts); + return (int) $counts; } /** @@ -862,6 +866,7 @@ public function isInRootCategoryList($category) /** * Check category is forbidden to delete. + * * If category is root and assigned to store group return false * * @param integer $categoryId @@ -982,6 +987,7 @@ public function changeParent( /** * Process positions of old parent category children and new parent category children. + * * Get position for moved category * * @param \Magento\Catalog\Model\Category $category @@ -1062,7 +1068,7 @@ public function load($object, $entityId, $attributes = []) } /** - * {@inheritdoc} + * @inheritdoc */ public function delete($object) { @@ -1088,6 +1094,8 @@ public function save(\Magento\Framework\Model\AbstractModel $object) } /** + * Returns EntityManager object + * * @return EntityManager */ private function getEntityManager() @@ -1100,6 +1108,8 @@ private function getEntityManager() } /** + * Returns AggregateCount object + * * @return Category\AggregateCount */ private function getAggregateCount() diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php b/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php index 01e4b072b0367..9db2c8248ce52 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php @@ -173,7 +173,7 @@ public function getMainTable() public function getMainStoreTable($storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID) { if (is_string($storeId)) { - $storeId = intval($storeId); + $storeId = (int) $storeId; } if ($storeId) { diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/BaseSelectProcessorInterface.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/BaseSelectProcessorInterface.php index d97f6bebf4e91..da3c4fb4417f2 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/BaseSelectProcessorInterface.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/BaseSelectProcessorInterface.php @@ -9,6 +9,7 @@ /** * Interface BaseSelectProcessorInterface + * * @api * @since 101.0.3 */ @@ -20,6 +21,8 @@ interface BaseSelectProcessorInterface const PRODUCT_TABLE_ALIAS = 'child'; /** + * Process the select statement + * * @param Select $select * @return Select * @since 101.0.3 diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php index c7829ab3a31d2..c5c656b726528 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php @@ -13,6 +13,7 @@ use Magento\Framework\EntityManager\MetadataPool; use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; /** * Class StatusBaseSelectProcessor @@ -30,28 +31,32 @@ class StatusBaseSelectProcessor implements BaseSelectProcessorInterface private $metadataPool; /** - * @var StoreResolverInterface + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @param Config $eavConfig * @param MetadataPool $metadataPool * @param StoreResolverInterface $storeResolver + * @param StoreManagerInterface $storeManager + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( Config $eavConfig, MetadataPool $metadataPool, - StoreResolverInterface $storeResolver + StoreResolverInterface $storeResolver, + StoreManagerInterface $storeManager = null ) { $this->eavConfig = $eavConfig; $this->metadataPool = $metadataPool; - $this->storeResolver = $storeResolver; + $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(StoreManagerInterface::class); } /** - * @param Select $select - * @return Select + * @inheritdoc */ public function process(Select $select) { @@ -70,7 +75,7 @@ public function process(Select $select) ['status_attr' => $statusAttribute->getBackendTable()], "status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}" . ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId() - . ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(), + . ' AND status_attr.store_id = ' . $this->storeManager->getStore()->getId(), [] ); diff --git a/app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php b/app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php index 597a1466a125e..eca4d468950e1 100644 --- a/app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php +++ b/app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php @@ -7,6 +7,9 @@ use Magento\Store\Model\Store; +/** + * Attribute validation + */ class AttributeValidation { /** @@ -14,6 +17,11 @@ class AttributeValidation */ private $storeManager; + /** + * @var array + */ + private $allowedEntityTypes; + /** * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param array $allowedEntityTypes @@ -27,9 +35,12 @@ public function __construct( } /** + * Around validate + * * @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject * @param \Closure $proceed * @param \Magento\Framework\DataObject $entity + * @throws \Magento\Framework\Exception\NoSuchEntityException * @return bool */ public function aroundValidate( @@ -41,7 +52,7 @@ public function aroundValidate( return $entity instanceof $allowedEntity; }, $this->allowedEntityTypes))); - if ($isAllowedType && $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) { + if ($isAllowedType && (int) $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) { $attrCode = $subject->getAttribute()->getAttributeCode(); // Null is meaning "no value" which should be overridden by value from default scope if (array_key_exists($attrCode, $entity->getData()) && $entity->getData($attrCode) === null) { diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php index c9b7dc50beb9e..a81d8b1c9fc3c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php @@ -91,6 +91,94 @@ protected function setUp() ]); } + public function testGetGalleryImagesJsonWithLabel() + { + $this->prepareGetGalleryImagesJsonMocks(); + $json = $this->model->getGalleryImagesJson(); + $decodedJson = json_decode($json, true); + $this->assertEquals('product_page_image_small_url', $decodedJson[0]['thumb']); + $this->assertEquals('product_page_image_medium_url', $decodedJson[0]['img']); + $this->assertEquals('product_page_image_large_url', $decodedJson[0]['full']); + $this->assertEquals('test_label', $decodedJson[0]['caption']); + $this->assertEquals('2', $decodedJson[0]['position']); + $this->assertEquals(false, $decodedJson[0]['isMain']); + $this->assertEquals('test_media_type', $decodedJson[0]['type']); + $this->assertEquals('test_video_url', $decodedJson[0]['videoUrl']); + } + + public function testGetGalleryImagesJsonWithoutLabel() + { + $this->prepareGetGalleryImagesJsonMocks(false); + $json = $this->model->getGalleryImagesJson(); + $decodedJson = json_decode($json, true); + $this->assertEquals('test_product_name', $decodedJson[0]['caption']); + } + + private function prepareGetGalleryImagesJsonMocks($hasLabel = true) + { + $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->disableOriginalConstructor() + ->getMock(); + + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + + $productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\AbstractType::class) + ->disableOriginalConstructor() + ->getMock(); + $productTypeMock->expects($this->any()) + ->method('getStoreFilter') + ->with($productMock) + ->willReturn($storeMock); + + $productMock->expects($this->any()) + ->method('getTypeInstance') + ->willReturn($productTypeMock); + $productMock->expects($this->any()) + ->method('getMediaGalleryImages') + ->willReturn($this->getImagesCollectionWithPopulatedDataObject($hasLabel)); + $productMock->expects($this->any()) + ->method('getName') + ->willReturn('test_product_name'); + + $this->registry->expects($this->any()) + ->method('registry') + ->with('product') + ->willReturn($productMock); + + $this->imageHelper = $this->getMockBuilder(\Magento\Catalog\Helper\Image::class) + ->setMethods(['init', 'setImageFile', 'getUrl']) + ->disableOriginalConstructor() + ->getMock(); + + $this->imageHelper->expects($this->any()) + ->method('init') + ->willReturnMap([ + [$productMock, 'product_page_image_small', [], $this->imageHelper], + [$productMock, 'product_page_image_medium_no_frame', [], $this->imageHelper], + [$productMock, 'product_page_image_large_no_frame', [], $this->imageHelper], + ]) + ->willReturnSelf(); + $this->imageHelper->expects($this->any()) + ->method('setImageFile') + ->with('test_file') + ->willReturnSelf(); + $this->urlBuilder->expects($this->at(0)) + ->method('getUrl') + ->willReturn('product_page_image_small_url'); + $this->urlBuilder->expects($this->at(1)) + ->method('getUrl') + ->willReturn('product_page_image_medium_url'); + $this->urlBuilder->expects($this->at(2)) + ->method('getUrl') + ->willReturn('product_page_image_large_url'); + + $this->galleryImagesConfigMock->expects($this->exactly(2)) + ->method('getItems') + ->willReturn($this->getGalleryImagesConfigItems()); + } + public function testGetGalleryImages() { $productMock = $this->createMock(Product::class); @@ -163,4 +251,30 @@ private function getGalleryImagesConfigItems() ]) ]; } + + /** + * @return \Magento\Framework\Data\Collection + */ + private function getImagesCollectionWithPopulatedDataObject($hasLabel) + { + $collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + + $items = [ + new \Magento\Framework\DataObject([ + 'file' => 'test_file', + 'label' => ($hasLabel ? 'test_label' : ''), + 'position' => '2', + 'media_type' => 'external-test_media_type', + "video_url" => 'test_video_url' + ]), + ]; + + $collectionMock->expects($this->any()) + ->method('getIterator') + ->willReturn(new \ArrayIterator($items)); + + return $collectionMock; + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php index a21883eb4a18e..ee487041600b5 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php @@ -16,7 +16,7 @@ use Magento\Framework\EntityManager\EntityMetadataInterface; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Store\Api\StoreResolverInterface; +use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\Store; /** @@ -35,9 +35,9 @@ class StatusBaseSelectProcessorTest extends \PHPUnit\Framework\TestCase private $metadataPool; /** - * @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $storeResolver; + private $storeManager; /** * @var Select|\PHPUnit_Framework_MockObject_MockObject @@ -53,13 +53,13 @@ protected function setUp() { $this->eavConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); $this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock(); - $this->storeResolver = $this->getMockBuilder(StoreResolverInterface::class)->getMock(); + $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)->getMock(); $this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); $this->statusBaseSelectProcessor = (new ObjectManager($this))->getObject(StatusBaseSelectProcessor::class, [ 'eavConfig' => $this->eavConfig, 'metadataPool' => $this->metadataPool, - 'storeResolver' => $this->storeResolver, + 'storeManager' => $this->storeManager, ]); } @@ -94,8 +94,14 @@ public function testProcess() ->with(Product::ENTITY, ProductInterface::STATUS) ->willReturn($statusAttribute); - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') + $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock(); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->willReturn($storeMock); + + $storeMock->expects($this->once()) + ->method('getId') ->willReturn($currentStoreId); $this->select->expects($this->at(0)) diff --git a/app/code/Magento/Catalog/Test/Unit/Plugin/Model/Attribute/Backend/AttributeValidationTest.php b/app/code/Magento/Catalog/Test/Unit/Plugin/Model/Attribute/Backend/AttributeValidationTest.php new file mode 100644 index 0000000000000..463ecf881977e --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Plugin/Model/Attribute/Backend/AttributeValidationTest.php @@ -0,0 +1,154 @@ +attributeMock = $this->getMockBuilder(AbstractBackend::class) + ->setMethods(['getAttributeCode']) + ->getMockForAbstractClass(); + $this->subjectMock = $this->getMockBuilder(AbstractBackend::class) + ->setMethods(['getAttribute']) + ->getMockForAbstractClass(); + $this->subjectMock->expects($this->any()) + ->method('getAttribute') + ->willReturn($this->attributeMock); + + $this->storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods(['getId']) + ->getMockForAbstractClass(); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->setMethods(['getStore']) + ->getMockForAbstractClass(); + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->entityMock = $this->getMockBuilder(DataObject::class) + ->setMethods(['getData']) + ->getMock(); + + $this->allowedEntityTypes = [$this->entityMock]; + + $this->proceedMock = function () { + $this->isProceedMockCalled = true; + }; + + $this->attributeValidation = $objectManager->getObject( + AttributeValidation::class, + [ + 'storeManager' => $this->storeManagerMock, + 'allowedEntityTypes' => $this->allowedEntityTypes, + ] + ); + } + + /** + * @param bool $shouldProceedRun + * @param bool $defaultStoreUsed + * @param null|int|string $storeId + * @dataProvider aroundValidateDataProvider + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @return void + */ + public function testAroundValidate(bool $shouldProceedRun, bool $defaultStoreUsed, $storeId) + { + $this->isProceedMockCalled = false; + $attributeCode = 'code'; + + $this->storeMock->expects($this->once()) + ->method('getId') + ->willReturn($storeId); + if ($defaultStoreUsed) { + $this->attributeMock->expects($this->once()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $this->entityMock->expects($this->at(0)) + ->method('getData') + ->willReturn([$attributeCode => null]); + $this->entityMock->expects($this->at(1)) + ->method('getData') + ->with($attributeCode) + ->willReturn(null); + } + + $this->attributeValidation->aroundValidate($this->subjectMock, $this->proceedMock, $this->entityMock); + $this->assertSame($shouldProceedRun, $this->isProceedMockCalled); + } + + /** + * Data provider for testAroundValidate + * @return array + */ + public function aroundValidateDataProvider(): array + { + return [ + [true, false, '0'], + [true, false, 0], + [true, false, null], + [false, true, 1], + ]; + } +} diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/edit-tree.js b/app/code/Magento/Catalog/view/adminhtml/web/js/edit-tree.js index 3544767b8d77f..7c947195f3313 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/edit-tree.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/edit-tree.js @@ -18,7 +18,10 @@ require([ /** * Delete some category * This routine get categoryId explicitly, so even if currently selected tree node is out of sync - * with this form, we surely delete same category in the tree and at backend + * with this form, we surely delete same category in the tree and at backend. + * + * @deprecated + * @see deleteConfirm */ function categoryDelete(url) { confirm({ diff --git a/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js b/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js index 3fb641733eb22..7434678d1694b 100644 --- a/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js +++ b/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js @@ -6,8 +6,10 @@ define([ 'jquery', 'mage/translate', + 'underscore', + 'Magento_Catalog/js/product/view/product-ids-resolver', 'jquery/ui' -], function ($, $t) { +], function ($, $t, _, idsResolver) { 'use strict'; $.widget('mage.catalogAddToCart', { @@ -76,17 +78,18 @@ define([ /** * Handler for the form 'submit' event * - * @param {Object} form + * @param {jQuery} form */ submitForm: function (form) { this.ajaxSubmit(form); }, /** - * @param {String} form + * @param {jQuery} form */ ajaxSubmit: function (form) { var self = this, + productIds = idsResolver(form), formData; $(self.options.minicartSelector).trigger('contentLoading'); @@ -115,6 +118,7 @@ define([ $(document).trigger('ajax:addToCart', { 'sku': form.data().productSku, + 'productIds': productIds, 'form': form, 'response': res }); diff --git a/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids-resolver.js b/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids-resolver.js new file mode 100644 index 0000000000000..f13e8f84a1b13 --- /dev/null +++ b/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids-resolver.js @@ -0,0 +1,29 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + 'underscore', + 'Magento_Catalog/js/product/view/product-ids' +], function (_, productIds) { + 'use strict'; + + /** + * Returns id's of products in form. + * + * @param {jQuery} $form + * @return {Array} + */ + return function ($form) { + var idSet = productIds(), + product = _.findWhere($form.serializeArray(), { + name: 'product' + }); + + if (!_.isUndefined(product)) { + idSet.push(product.value); + } + + return _.uniq(idSet); + }; +}); diff --git a/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids.js b/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids.js new file mode 100644 index 0000000000000..2198b7b8e48b0 --- /dev/null +++ b/app/code/Magento/Catalog/view/frontend/web/js/product/view/product-ids.js @@ -0,0 +1,12 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'ko' +], function (ko) { + 'use strict'; + + return ko.observableArray([]); +}); diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute.php similarity index 100% rename from app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute.php rename to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute.php diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatInterface.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatInterface.php similarity index 100% rename from app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatInterface.php rename to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatInterface.php diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatFactory.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatList.php similarity index 98% rename from app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatFactory.php rename to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatList.php index 2aab2d5816083..97e0be3763f1d 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/FormatFactory.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatList.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextareaAttribute; +namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute; use Magento\Framework\ObjectManagerInterface; diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/Html.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/Html.php similarity index 100% rename from app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextareaAttribute/Html.php rename to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/Html.php diff --git a/app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php b/app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php index 6595aec78f57f..a48b9ae5f0808 100644 --- a/app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php +++ b/app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php @@ -120,7 +120,7 @@ public function initialize( /** * if option's qty was updates we also need to update quote item qty */ - $quoteItem->setData('qty', intval($qty)); + $quoteItem->setData('qty', (int) $qty); } if ($result->getMessage() !== null) { $option->setMessage($result->getMessage()); diff --git a/app/code/Magento/CatalogInventory/Model/Stock/Status.php b/app/code/Magento/CatalogInventory/Model/Stock/Status.php index 899056d8f0835..4941d5d333bdb 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock/Status.php +++ b/app/code/Magento/CatalogInventory/Model/Stock/Status.php @@ -72,6 +72,8 @@ protected function _construct() //@codeCoverageIgnoreStart /** + * Retrieve product ID + * * @return int */ public function getProductId() @@ -80,6 +82,8 @@ public function getProductId() } /** + * Retrieve website ID + * * @return int */ public function getWebsiteId() @@ -88,6 +92,8 @@ public function getWebsiteId() } /** + * Retrieve stock ID + * * @return int */ public function getStockId() @@ -96,6 +102,8 @@ public function getStockId() } /** + * Retrieve qty + * * @return int */ public function getQty() @@ -104,16 +112,20 @@ public function getQty() } /** + * Retrieve stock status + * * @return int */ - public function getStockStatus() + public function getStockStatus(): int { - return $this->getData(self::KEY_STOCK_STATUS); + return (int)$this->getData(self::KEY_STOCK_STATUS); } //@codeCoverageIgnoreEnd /** + * Retrieve stock item + * * @return StockItemInterface */ public function getStockItem() @@ -124,6 +136,8 @@ public function getStockItem() //@codeCoverageIgnoreStart /** + * Set product ID + * * @param int $productId * @return $this */ @@ -133,6 +147,8 @@ public function setProductId($productId) } /** + * Set web website ID + * * @param int $websiteId * @return $this */ @@ -142,6 +158,8 @@ public function setWebsiteId($websiteId) } /** + * Set stock ID + * * @param int $stockId * @return $this */ @@ -151,6 +169,8 @@ public function setStockId($stockId) } /** + * Set qty + * * @param int $qty * @return $this */ @@ -160,6 +180,8 @@ public function setQty($qty) } /** + * Set stock status + * * @param int $stockStatus * @return $this */ @@ -169,7 +191,7 @@ public function setStockStatus($stockStatus) } /** - * {@inheritdoc} + * Retrieve existing extension attributes object or create a new one. * * @return \Magento\CatalogInventory\Api\Data\StockStatusExtensionInterface|null */ @@ -179,7 +201,7 @@ public function getExtensionAttributes() } /** - * {@inheritdoc} + * Set an extension attributes object. * * @param \Magento\CatalogInventory\Api\Data\StockStatusExtensionInterface $extensionAttributes * @return $this diff --git a/app/code/Magento/CatalogInventory/Model/StockStateProvider.php b/app/code/Magento/CatalogInventory/Model/StockStateProvider.php index fb6fc3be61375..31fd5606a9849 100644 --- a/app/code/Magento/CatalogInventory/Model/StockStateProvider.php +++ b/app/code/Magento/CatalogInventory/Model/StockStateProvider.php @@ -9,9 +9,9 @@ use Magento\Catalog\Model\ProductFactory; use Magento\CatalogInventory\Api\Data\StockItemInterface; use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface; +use Magento\Framework\DataObject\Factory as ObjectFactory; use Magento\Framework\Locale\FormatInterface; use Magento\Framework\Math\Division as MathDivision; -use Magento\Framework\DataObject\Factory as ObjectFactory; /** * Interface StockStateProvider @@ -65,6 +65,8 @@ public function __construct( } /** + * Validate stock + * * @param StockItemInterface $stockItem * @return bool */ @@ -82,6 +84,8 @@ public function verifyStock(StockItemInterface $stockItem) } /** + * Verify notification + * * @param StockItemInterface $stockItem * @return bool */ @@ -91,6 +95,8 @@ public function verifyNotification(StockItemInterface $stockItem) } /** + * Validate quote qty + * * @param StockItemInterface $stockItem * @param int|float $qty * @param int|float $summaryQty @@ -113,13 +119,13 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ $result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal()); if (!$stockItem->getIsQtyDecimal()) { $result->setHasQtyOptionUpdate(true); - $qty = intval($qty); + $qty = (int) $qty; /** * Adding stock data to quote item */ $result->setItemQty($qty); $qty = $this->getNumber($qty); - $origQty = intval($origQty); + $origQty = (int) $origQty; $result->setOrigQty($origQty); } @@ -254,6 +260,8 @@ public function checkQty(StockItemInterface $stockItem, $qty) } /** + * Returns suggested qty + * * Returns suggested qty that satisfies qty increments and minQty/maxQty/minSaleQty/maxSaleQty conditions * or original qty if such value does not exist * @@ -294,6 +302,8 @@ public function suggestQty(StockItemInterface $stockItem, $qty) } /** + * Check Qty Increments + * * @param StockItemInterface $stockItem * @param float|int $qty * @return \Magento\Framework\DataObject @@ -369,6 +379,8 @@ public function getStockQty(StockItemInterface $stockItem) } /** + * Get numeric qty + * * @param string|float|int|null $qty * @return float|null */ diff --git a/app/code/Magento/CatalogRule/Block/Adminhtml/Edit/DeleteButton.php b/app/code/Magento/CatalogRule/Block/Adminhtml/Edit/DeleteButton.php index 6390822b58f4a..184cb6419294f 100644 --- a/app/code/Magento/CatalogRule/Block/Adminhtml/Edit/DeleteButton.php +++ b/app/code/Magento/CatalogRule/Block/Adminhtml/Edit/DeleteButton.php @@ -25,7 +25,7 @@ public function getButtonData() 'class' => 'delete', 'on_click' => 'deleteConfirm(\'' . __( 'Are you sure you want to do this?' - ) . '\', \'' . $this->urlBuilder->getUrl('*/*/delete', ['id' => $ruleId]) . '\')', + ) . '\', \'' . $this->urlBuilder->getUrl('*/*/delete', ['id' => $ruleId]) . '\', {data: {}})', 'sort_order' => 20, ]; } diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Delete.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Delete.php index 3500506d8d6c5..998d45b839c72 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Delete.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Delete.php @@ -6,9 +6,10 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Exception\LocalizedException; -class Delete extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +class Delete extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpPostActionInterface { /** * @return void diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Edit.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Edit.php index 945c28b2088f2..2c2abcef8b255 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Edit.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; -class Edit extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Index.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Index.php index 8c6a38819512f..a9dcd1f6383a3 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Index.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; -class Index extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewAction.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewAction.php index c677c75c59534..d86c56402d25a 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewAction.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; -class NewAction extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewConditionHtml.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewConditionHtml.php index b790d90d3804f..a845c104f943e 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewConditionHtml.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewConditionHtml.php @@ -6,9 +6,12 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Rule\Model\Condition\AbstractCondition; +use Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog as CatalogAction; -class NewConditionHtml extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +class NewConditionHtml extends CatalogAction implements HttpPostActionInterface, HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php index f3046c58a389b..bad1118e3ae72 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php @@ -6,6 +6,7 @@ */ namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; @@ -15,7 +16,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog +class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog implements HttpPostActionInterface { /** * @var DataPersistorInterface diff --git a/app/code/Magento/CatalogRule/Test/Unit/Block/Adminhtml/Edit/DeleteButtonTest.php b/app/code/Magento/CatalogRule/Test/Unit/Block/Adminhtml/Edit/DeleteButtonTest.php index 6178d51644fde..f969b342f826d 100644 --- a/app/code/Magento/CatalogRule/Test/Unit/Block/Adminhtml/Edit/DeleteButtonTest.php +++ b/app/code/Magento/CatalogRule/Test/Unit/Block/Adminhtml/Edit/DeleteButtonTest.php @@ -24,13 +24,16 @@ class DeleteButtonTest extends \PHPUnit\Framework\TestCase */ protected $registryMock; + /** + * @inheritDoc + */ protected function setUp() { $this->urlBuilderMock = $this->createMock(\Magento\Framework\UrlInterface::class); $this->registryMock = $this->createMock(\Magento\Framework\Registry::class); $contextMock = $this->createMock(\Magento\Backend\Block\Widget\Context::class); - $contextMock->expects($this->once())->method('getUrlBuilder')->willReturn($this->urlBuilderMock); + $contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock); $this->model = new \Magento\CatalogRule\Block\Adminhtml\Edit\DeleteButton( $contextMock, @@ -38,33 +41,9 @@ protected function setUp() ); } - public function testGetButtonData() - { - $ruleId = 42; - $deleteUrl = 'http://magento.com/rule/delete/' . $ruleId; - $ruleMock = new \Magento\Framework\DataObject(['id' => $ruleId]); - - $this->registryMock->expects($this->once()) - ->method('registry') - ->with(RegistryConstants::CURRENT_CATALOG_RULE_ID) - ->willReturn($ruleMock); - $this->urlBuilderMock->expects($this->once()) - ->method('getUrl') - ->with('*/*/delete', ['id' => $ruleId]) - ->willReturn($deleteUrl); - - $data = [ - 'label' => __('Delete Rule'), - 'class' => 'delete', - 'on_click' => 'deleteConfirm(\'' . __( - 'Are you sure you want to do this?' - ) . '\', \'' . $deleteUrl . '\')', - 'sort_order' => 20, - ]; - - $this->assertEquals($data, $this->model->getButtonData()); - } - + /** + * Test empty response without a present rule. + */ public function testGetButtonDataWithoutRule() { $this->assertEquals([], $this->model->getButtonData()); diff --git a/app/code/Magento/CatalogSearch/Controller/Advanced/Index.php b/app/code/Magento/CatalogSearch/Controller/Advanced/Index.php index c04593a549829..a669016eb6b1b 100644 --- a/app/code/Magento/CatalogSearch/Controller/Advanced/Index.php +++ b/app/code/Magento/CatalogSearch/Controller/Advanced/Index.php @@ -6,13 +6,15 @@ */ namespace Magento\CatalogSearch\Controller\Advanced; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; /** * @deprecated CatalogSearch will be removed in 2.4, and {@see \Magento\ElasticSearch} * will replace it as the default search engine. */ -class Index extends \Magento\Framework\App\Action\Action +class Index extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface, HttpPostActionInterface { /** * @return \Magento\Framework\Controller\ResultInterface diff --git a/app/code/Magento/CatalogSearch/Controller/Advanced/Result.php b/app/code/Magento/CatalogSearch/Controller/Advanced/Result.php index 2862efe4b4cd3..937175511b1fb 100644 --- a/app/code/Magento/CatalogSearch/Controller/Advanced/Result.php +++ b/app/code/Magento/CatalogSearch/Controller/Advanced/Result.php @@ -6,15 +6,17 @@ */ namespace Magento\CatalogSearch\Controller\Advanced; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\CatalogSearch\Model\Advanced as ModelAdvanced; use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\UrlFactory; /** * @deprecated CatalogSearch will be removed in 2.4, and {@see \Magento\ElasticSearch} * will replace it as the default search engine. */ -class Result extends \Magento\Framework\App\Action\Action +class Result extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface, HttpPostActionInterface { /** * Url factory diff --git a/app/code/Magento/CatalogSearch/Controller/Result/Index.php b/app/code/Magento/CatalogSearch/Controller/Result/Index.php index ab796e12d81d9..7c3577df452e4 100644 --- a/app/code/Magento/CatalogSearch/Controller/Result/Index.php +++ b/app/code/Magento/CatalogSearch/Controller/Result/Index.php @@ -6,9 +6,11 @@ */ namespace Magento\CatalogSearch\Controller\Result; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Catalog\Model\Layer\Resolver; use Magento\Catalog\Model\Session; use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Search\Model\QueryFactory; use Magento\Search\Model\PopularSearchTerms; @@ -17,7 +19,7 @@ * @deprecated CatalogSearch will be removed in 2.4, and {@see \Magento\ElasticSearch} * will replace it as the default search engine. */ -class Index extends \Magento\Framework\App\Action\Action +class Index extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface, HttpPostActionInterface { /** * Catalog session diff --git a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php index 9a55f981b7607..4765a54cf0f40 100644 --- a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php +++ b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php @@ -14,6 +14,7 @@ /** * Catalog Products List widget block + * * Class ProductsList * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -130,7 +131,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function _construct() { @@ -164,7 +165,7 @@ public function getCacheKeyInfo() $this->_storeManager->getStore()->getId(), $this->_design->getDesignTheme()->getId(), $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP), - intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)), + (int) $this->getRequest()->getParam($this->getData('page_var_name'), 1), $this->getProductsPerPage(), $conditions, $this->json->serialize($this->getRequest()->getParams()), @@ -174,7 +175,7 @@ public function getCacheKeyInfo() } /** - * {@inheritdoc} + * @inheritdoc * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getProductPriceHtml( @@ -211,7 +212,7 @@ public function getProductPriceHtml( } /** - * {@inheritdoc} + * @inheritdoc */ protected function _beforeToHtml() { @@ -249,6 +250,8 @@ public function createCollection() } /** + * Returns conditions + * * @return \Magento\Rule\Model\Condition\Combine */ protected function getConditions() @@ -386,6 +389,8 @@ public function getTitle() } /** + * Returns PriceCurrencyInterface instance + * * @return PriceCurrencyInterface * * @deprecated 100.2.0 diff --git a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php index f47e514948d69..3f6f638db5b82 100644 --- a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php +++ b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php @@ -7,7 +7,7 @@ use Magento\Checkout\Helper\Data; use Magento\Framework\App\ObjectManager; -use Magento\Store\Api\StoreResolverInterface; +use Magento\Store\Model\StoreManagerInterface; /** * Class LayoutProcessor @@ -40,9 +40,9 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso private $checkoutDataHelper; /** - * @var StoreResolverInterface + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @var \Magento\Shipping\Model\Config @@ -53,30 +53,36 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso * @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider * @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper * @param AttributeMerger $merger + * @param \Magento\Customer\Model\Options|null $options + * @param Data|null $checkoutDataHelper + * @param \Magento\Shipping\Model\Config|null $shippingConfig + * @param StoreManagerInterface|null $storeManager */ public function __construct( \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider, \Magento\Ui\Component\Form\AttributeMapper $attributeMapper, - AttributeMerger $merger + AttributeMerger $merger, + \Magento\Customer\Model\Options $options = null, + Data $checkoutDataHelper = null, + \Magento\Shipping\Model\Config $shippingConfig = null, + StoreManagerInterface $storeManager = null ) { $this->attributeMetadataDataProvider = $attributeMetadataDataProvider; $this->attributeMapper = $attributeMapper; $this->merger = $merger; + $this->options = $options ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Customer\Model\Options::class); + $this->checkoutDataHelper = $checkoutDataHelper ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(Data::class); + $this->shippingConfig = $shippingConfig ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Shipping\Model\Config::class); + $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(StoreManagerInterface::class); } /** - * @deprecated 100.0.11 - * @return \Magento\Customer\Model\Options - */ - private function getOptions() - { - if (!is_object($this->options)) { - $this->options = ObjectManager::getInstance()->get(\Magento\Customer\Model\Options::class); - } - return $this->options; - } - - /** + * Get address attributes. + * * @return array */ private function getAddressAttributes() @@ -143,8 +149,8 @@ private function convertElementsToSelect($elements, $attributesToConvert) public function process($jsLayout) { $attributesToConvert = [ - 'prefix' => [$this->getOptions(), 'getNamePrefixOptions'], - 'suffix' => [$this->getOptions(), 'getNameSuffixOptions'], + 'prefix' => [$this->options, 'getNamePrefixOptions'], + 'suffix' => [$this->options, 'getNameSuffixOptions'], ]; $elements = $this->getAddressAttributes(); @@ -192,8 +198,8 @@ public function process($jsLayout) */ private function processShippingChildrenComponents($shippingRatesLayout) { - $activeCarriers = $this->getShippingConfig()->getActiveCarriers( - $this->getStoreResolver()->getCurrentStoreId() + $activeCarriers = $this->shippingConfig->getActiveCarriers( + $this->storeManager->getStore()->getId() ); foreach (array_keys($shippingRatesLayout) as $carrierName) { $carrierKey = str_replace('-rates-validation', '', $carrierName); @@ -206,6 +212,7 @@ private function processShippingChildrenComponents($shippingRatesLayout) /** * Appends billing address form component to payment layout + * * @param array $paymentLayout * @param array $elements * @return array @@ -221,7 +228,7 @@ private function processPaymentChildrenComponents(array $paymentLayout, array $e } // The if billing address should be displayed on Payment method or page - if ($this->getCheckoutDataHelper()->isDisplayBillingOnPaymentMethodAvailable()) { + if ($this->checkoutDataHelper->isDisplayBillingOnPaymentMethodAvailable()) { $paymentLayout['payments-list']['children'] = array_merge_recursive( $paymentLayout['payments-list']['children'], @@ -340,49 +347,4 @@ private function getBillingAddressComponent($paymentCode, $elements) ], ]; } - - /** - * Get checkout data helper instance - * - * @return Data - * @deprecated 100.1.4 - */ - private function getCheckoutDataHelper() - { - if (!$this->checkoutDataHelper) { - $this->checkoutDataHelper = ObjectManager::getInstance()->get(Data::class); - } - - return $this->checkoutDataHelper; - } - - /** - * Retrieve Shipping Configuration. - * - * @return \Magento\Shipping\Model\Config - * @deprecated 100.2.0 - */ - private function getShippingConfig() - { - if (!$this->shippingConfig) { - $this->shippingConfig = ObjectManager::getInstance()->get(\Magento\Shipping\Model\Config::class); - } - - return $this->shippingConfig; - } - - /** - * Get store resolver. - * - * @return StoreResolverInterface - * @deprecated 100.2.0 - */ - private function getStoreResolver() - { - if (!$this->storeResolver) { - $this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class); - } - - return $this->storeResolver; - } } diff --git a/app/code/Magento/Checkout/Controller/Account/DelegateCreate.php b/app/code/Magento/Checkout/Controller/Account/DelegateCreate.php index 6c4c8b053e2ae..e4f909f9a8131 100644 --- a/app/code/Magento/Checkout/Controller/Account/DelegateCreate.php +++ b/app/code/Magento/Checkout/Controller/Account/DelegateCreate.php @@ -7,6 +7,7 @@ namespace Magento\Checkout\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Checkout\Model\Session; @@ -15,7 +16,7 @@ /** * Redirect guest customer for registration. */ -class DelegateCreate extends Action +class DelegateCreate extends Action implements HttpGetActionInterface { /** * @var OrderCustomerDelegateInterface diff --git a/app/code/Magento/Checkout/Controller/Cart.php b/app/code/Magento/Checkout/Controller/Cart.php index f244fe310af27..d7b09c17ee036 100644 --- a/app/code/Magento/Checkout/Controller/Cart.php +++ b/app/code/Magento/Checkout/Controller/Cart.php @@ -106,8 +106,7 @@ protected function _isInternalUrl($url) /** * Get resolved back url * - * @param null $defaultUrl - * + * @param string|null $defaultUrl * @return mixed|null|string */ protected function getBackUrl($defaultUrl = null) @@ -118,12 +117,7 @@ protected function getBackUrl($defaultUrl = null) return $returnUrl; } - $shouldRedirectToCart = $this->_scopeConfig->getValue( - 'checkout/cart/redirect_to_cart', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - if ($shouldRedirectToCart || $this->getRequest()->getParam('in_cart')) { + if ($this->shouldRedirectToCart() || $this->getRequest()->getParam('in_cart')) { if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) { $this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl()); } @@ -132,4 +126,17 @@ protected function getBackUrl($defaultUrl = null) return $defaultUrl; } + + /** + * Is redirect should be performed after the product was added to cart. + * + * @return bool + */ + private function shouldRedirectToCart() + { + return $this->_scopeConfig->isSetFlag( + 'checkout/cart/redirect_to_cart', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } } diff --git a/app/code/Magento/Checkout/Controller/Cart/Add.php b/app/code/Magento/Checkout/Controller/Cart/Add.php index 5f54ca3395646..739f71caeb804 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Add.php +++ b/app/code/Magento/Checkout/Controller/Cart/Add.php @@ -6,14 +6,17 @@ */ namespace Magento\Checkout\Controller\Cart; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Checkout\Model\Cart as CustomerCart; use Magento\Framework\Exception\NoSuchEntityException; /** + * Controller for processing add to cart action. + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Add extends \Magento\Checkout\Controller\Cart +class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface { /** * @var ProductRepositoryInterface @@ -125,11 +128,21 @@ public function execute() if (!$this->_checkoutSession->getNoCartRedirect(true)) { if (!$this->cart->getQuote()->getHasError()) { - $message = __( - 'You added %1 to your shopping cart.', - $product->getName() - ); - $this->messageManager->addSuccessMessage($message); + if ($this->shouldRedirectToCart()) { + $message = __( + 'You added %1 to your shopping cart.', + $product->getName() + ); + $this->messageManager->addSuccessMessage($message); + } else { + $this->messageManager->addComplexSuccessMessage( + 'addCartSuccessMessage', + [ + 'product_name' => $product->getName(), + 'cart_url' => $this->getCartUrl(), + ] + ); + } } return $this->goBack(null, $product); } @@ -150,8 +163,7 @@ public function execute() $url = $this->_checkoutSession->getRedirectUrl(true); if (!$url) { - $cartUrl = $this->_objectManager->get(\Magento\Checkout\Helper\Cart::class)->getCartUrl(); - $url = $this->_redirect->getRedirectUrl($cartUrl); + $url = $this->_redirect->getRedirectUrl($this->getCartUrl()); } return $this->goBack($url); @@ -194,4 +206,27 @@ protected function goBack($backUrl = null, $product = null) $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) ); } + + /** + * Returns cart url + * + * @return string + */ + private function getCartUrl() + { + return $this->_url->getUrl('checkout/cart', ['_secure' => true]); + } + + /** + * Is redirect should be performed after the product was added to cart. + * + * @return bool + */ + private function shouldRedirectToCart() + { + return $this->_scopeConfig->isSetFlag( + 'checkout/cart/redirect_to_cart', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } } diff --git a/app/code/Magento/Checkout/Controller/Cart/Configure.php b/app/code/Magento/Checkout/Controller/Cart/Configure.php index 19b2d2db345a1..aa4ae755d7940 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Configure.php +++ b/app/code/Magento/Checkout/Controller/Cart/Configure.php @@ -7,13 +7,14 @@ namespace Magento\Checkout\Controller\Cart; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework; use Magento\Framework\Controller\ResultFactory; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Configure extends \Magento\Checkout\Controller\Cart +class Configure extends \Magento\Checkout\Controller\Cart implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Checkout/Controller/Cart/CouponPost.php b/app/code/Magento/Checkout/Controller/Cart/CouponPost.php index 5f68335181174..fdfe817f354f4 100644 --- a/app/code/Magento/Checkout/Controller/Cart/CouponPost.php +++ b/app/code/Magento/Checkout/Controller/Cart/CouponPost.php @@ -5,10 +5,12 @@ */ namespace Magento\Checkout\Controller\Cart; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class CouponPost extends \Magento\Checkout\Controller\Cart +class CouponPost extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface { /** * Sales quote repository diff --git a/app/code/Magento/Checkout/Controller/Cart/Delete.php b/app/code/Magento/Checkout/Controller/Cart/Delete.php index 4a6174e83fd02..7e88a484f9f6c 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Delete.php +++ b/app/code/Magento/Checkout/Controller/Cart/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Checkout\Controller\Cart; -class Delete extends \Magento\Checkout\Controller\Cart +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Delete extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface { /** * Delete shopping cart item action diff --git a/app/code/Magento/Checkout/Controller/Cart/Index.php b/app/code/Magento/Checkout/Controller/Cart/Index.php index 3fb582d35e28a..182ab6777776a 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Index.php +++ b/app/code/Magento/Checkout/Controller/Cart/Index.php @@ -7,7 +7,9 @@ namespace Magento\Checkout\Controller\Cart; -class Index extends \Magento\Checkout\Controller\Cart +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Checkout\Controller\Cart implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php b/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php index 59bd6489bf926..40ce2252581cf 100644 --- a/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php +++ b/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php @@ -7,7 +7,9 @@ namespace Magento\Checkout\Controller\Cart; -class UpdateItemOptions extends \Magento\Checkout\Controller\Cart +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class UpdateItemOptions extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface { /** * Update product configuration for a cart item diff --git a/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php b/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php index 05ce48c9b46ce..9f0dcc6d9c18f 100644 --- a/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php +++ b/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php @@ -7,8 +7,9 @@ namespace Magento\Checkout\Controller\Cart; use Magento\Checkout\Model\Cart\RequestQuantityProcessor; +use Magento\Framework\App\Action\HttpPostActionInterface; -class UpdatePost extends \Magento\Checkout\Controller\Cart +class UpdatePost extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface { /** * @var RequestQuantityProcessor diff --git a/app/code/Magento/Checkout/Controller/Index/Index.php b/app/code/Magento/Checkout/Controller/Index/Index.php index 785c1f1473be6..5acfab435b512 100644 --- a/app/code/Magento/Checkout/Controller/Index/Index.php +++ b/app/code/Magento/Checkout/Controller/Index/Index.php @@ -9,7 +9,9 @@ namespace Magento\Checkout\Controller\Index; -class Index extends \Magento\Checkout\Controller\Onepage +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Checkout\Controller\Onepage implements HttpGetActionInterface { /** * Checkout page diff --git a/app/code/Magento/Checkout/Controller/Onepage/Success.php b/app/code/Magento/Checkout/Controller/Onepage/Success.php index ae9be42a89c86..7db5cd8f012c7 100644 --- a/app/code/Magento/Checkout/Controller/Onepage/Success.php +++ b/app/code/Magento/Checkout/Controller/Onepage/Success.php @@ -6,7 +6,9 @@ */ namespace Magento\Checkout\Controller\Onepage; -class Success extends \Magento\Checkout\Controller\Onepage +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Success extends \Magento\Checkout\Controller\Onepage implements HttpGetActionInterface { /** * Order success action diff --git a/app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php b/app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php index c84aec336a589..f589e702de950 100644 --- a/app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php +++ b/app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php @@ -5,7 +5,9 @@ */ namespace Magento\Checkout\Controller\Sidebar; -class RemoveItem extends \Magento\Framework\App\Action\Action +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class RemoveItem extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface { /** * @var \Magento\Checkout\Model\Sidebar diff --git a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/StorefrontProductCartActionGroup.xml b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/StorefrontProductCartActionGroup.xml index 29a76675fa52e..4b5b250078ad4 100644 --- a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/StorefrontProductCartActionGroup.xml +++ b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/StorefrontProductCartActionGroup.xml @@ -16,8 +16,9 @@ - - + + + @@ -30,8 +31,9 @@ - - + + + @@ -46,8 +48,9 @@ - - + + + diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontMessagesSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontMessagesSection.xml index e70ff2b445194..8bd6a59f5633b 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontMessagesSection.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Section/StorefrontMessagesSection.xml @@ -11,7 +11,7 @@
diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php index b3e55bb418d3d..31ca2a2033012 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php @@ -10,15 +10,12 @@ use Magento\Checkout\Helper\Data; use Magento\Customer\Model\AttributeMetadataDataProvider; use Magento\Customer\Model\Options; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + use Magento\Ui\Component\Form\AttributeMapper; use PHPUnit_Framework_MockObject_MockObject as MockObject; /** - * LayoutProcessorTest covers a list of variations for - * checkout layout processor - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * LayoutProcessorTest covers a list of variations for checkout layout processor */ class LayoutProcessorTest extends \PHPUnit\Framework\TestCase { @@ -50,12 +47,10 @@ class LayoutProcessorTest extends \PHPUnit\Framework\TestCase /** * @var MockObject */ - private $storeResolver; + private $storeManager; protected function setUp() { - $objectManager = new ObjectManager($this); - $this->attributeDataProvider = $this->getMockBuilder(AttributeMetadataDataProvider::class) ->disableOriginalConstructor() ->setMethods(['loadAttributesCollection']) @@ -80,17 +75,21 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $shippingConfig = $this->getMockBuilder(\Magento\Shipping\Model\Config::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->layoutProcessor = new LayoutProcessor( $this->attributeDataProvider, $this->attributeMapper, - $this->attributeMerger + $this->attributeMerger, + $options, + $this->dataHelper, + $shippingConfig, + $this->storeManager ); - - $this->storeResolver = $this->createMock(\Magento\Store\Api\StoreResolverInterface::class); - - $objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'checkoutDataHelper', $this->dataHelper); - $objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'options', $options); - $objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'storeResolver', $this->storeResolver); } /** @@ -277,7 +276,7 @@ private function getBillingComponent($paymentCode) 'telephone' => [ 'config' => [ 'tooltip' => [ - 'description' => __('For delivery questions.'), + 'description' => ('For delivery questions.'), ], ], ], diff --git a/app/code/Magento/Checkout/etc/frontend/di.xml b/app/code/Magento/Checkout/etc/frontend/di.xml index f2aced01b3942..d80f88786c87b 100644 --- a/app/code/Magento/Checkout/etc/frontend/di.xml +++ b/app/code/Magento/Checkout/etc/frontend/di.xml @@ -83,4 +83,16 @@
+ + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Checkout::messages/addCartSuccessMessage.phtml + + + + + diff --git a/app/code/Magento/Checkout/view/frontend/templates/messages/addCartSuccessMessage.phtml b/app/code/Magento/Checkout/view/frontend/templates/messages/addCartSuccessMessage.phtml new file mode 100644 index 0000000000000..e835037b5fcb4 --- /dev/null +++ b/app/code/Magento/Checkout/view/frontend/templates/messages/addCartSuccessMessage.phtml @@ -0,0 +1,14 @@ + + +escapeHtml(__( + 'You added %1 to your shopping cart.', + $block->getData('product_name'), + $block->getData('cart_url') +), ['a']); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js index 3b5168453e11a..dde1ad72ba15e 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js @@ -226,7 +226,7 @@ define([ var productData = this._getProductById(Number(elem.data('cart-item'))); if (!_.isUndefined(productData)) { - $(document).trigger('ajax:updateCartItemQty', productData['product_sku']); + $(document).trigger('ajax:updateCartItemQty'); } this._hideItemButton(elem); }, @@ -253,7 +253,9 @@ define([ var productData = this._getProductById(Number(elem.data('cart-item'))); if (!_.isUndefined(productData)) { - $(document).trigger('ajax:removeFromCart', productData['product_sku']); + $(document).trigger('ajax:removeFromCart', { + productIds: [productData['product_id']] + }); } }, diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php index f7b178df99624..d727107a86f49 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php @@ -12,8 +12,9 @@ use Magento\Framework\Registry; use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\App\Action\HttpPostActionInterface; -class Delete extends Agreement +class Delete extends Agreement implements HttpPostActionInterface { /** * @var CheckoutAgreementsRepositoryInterface diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Edit.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Edit.php index 8bec3b581cd54..1a82108a3da8d 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Edit.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Edit.php @@ -12,8 +12,9 @@ use Magento\Framework\Registry; use Magento\Framework\App\ObjectManager; use Magento\CheckoutAgreements\Block\Adminhtml\Agreement\Edit as BlockEdit; +use Magento\Framework\App\Action\HttpGetActionInterface; -class Edit extends Agreement +class Edit extends Agreement implements HttpGetActionInterface { /** * @var AgreementFactory diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Index.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Index.php index b1dfd8c304d79..d32ee7a4b7528 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Index.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\CheckoutAgreements\Controller\Adminhtml\Agreement; -class Index extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/NewAction.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/NewAction.php index 4d482ebfc206c..caa21c4682303 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/NewAction.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\CheckoutAgreements\Controller\Adminhtml\Agreement; -class NewAction extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Save.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Save.php index 05a16d3dd4264..4d4dd076ea163 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Save.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Save.php @@ -13,8 +13,9 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\App\Action\HttpPostActionInterface; -class Save extends Agreement +class Save extends Agreement implements HttpPostActionInterface { /** * @var AgreementFactory diff --git a/app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php b/app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php index 67ae137fb4d8e..a19e3846a8d89 100644 --- a/app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php +++ b/app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php @@ -5,8 +5,9 @@ */ namespace Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action; -use Magento\Store\Api\StoreResolverInterface; - +/** + * Url builder class used to compose dynamic urls. + */ class UrlBuilder { /** @@ -38,7 +39,7 @@ public function getUrl($routePath, $scope, $store) [ '_current' => false, '_nosid' => true, - '_query' => [StoreResolverInterface::PARAM_NAME => $store] + '_query' => [\Magento\Store\Model\StoreManagerInterface::PARAM_NAME => $store] ] ); diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php index 3aaf40e7d0ab2..4af6b684496ea 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; -class Delete extends \Magento\Cms\Controller\Adminhtml\Block +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\Cms\Controller\Adminhtml\Block implements HttpPostActionInterface { /** * Delete action diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php index 8756089063237..b5b035e0c67aa 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php @@ -5,7 +5,9 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; -class Edit extends \Magento\Cms\Controller\Adminhtml\Block +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Cms\Controller\Adminhtml\Block implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Index.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Index.php index a4096e4d1a447..f92d38c0d856d 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Index.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; -class Index extends \Magento\Cms\Controller\Adminhtml\Block +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Cms\Controller\Adminhtml\Block implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/NewAction.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/NewAction.php index cfac00915c97c..28db422fb51bc 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/NewAction.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; -class NewAction extends \Magento\Cms\Controller\Adminhtml\Block +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Cms\Controller\Adminhtml\Block implements HttpGetActionInterface { /** * @var \Magento\Backend\Model\View\Result\ForwardFactory diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php index 40974b7a4b5c1..7526f59ce368b 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php @@ -6,6 +6,7 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Cms\Api\BlockRepositoryInterface; use Magento\Cms\Model\Block; @@ -14,7 +15,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; -class Save extends \Magento\Cms\Controller\Adminhtml\Block +class Save extends \Magento\Cms\Controller\Adminhtml\Block implements HttpPostActionInterface { /** * @var DataPersistorInterface diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php index 6d51c28b6aca7..e7bdfe9ed0e7d 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php @@ -6,9 +6,10 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; -class Edit extends \Magento\Backend\App\Action +class Edit extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Index.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Index.php index 75f9ad70dc408..42fa4d62673c1 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Index.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Index.php @@ -6,10 +6,11 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class Index extends \Magento\Backend\App\Action +class Index extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php index a85b8ecd5e5a1..b07894e6a9de6 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -5,6 +5,7 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Backend\App\Action\Context; use Magento\Ui\Component\MassAction\Filter; @@ -13,7 +14,7 @@ /** * Class MassDisable */ -class MassDisable extends \Magento\Backend\App\Action +class MassDisable extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php index ef4fda60c0f81..5a7b900bf2d8b 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php @@ -6,12 +6,13 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Cms\Model\Page; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Exception\LocalizedException; -class Save extends \Magento\Backend\App\Action +class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session @@ -127,8 +128,8 @@ public function execute() /** * Process result redirect * - * @param \Magento\Cms\Api\Data\PageInterface $model - * @param \Magento\Backend\Model\View\Result\Redirect $resultRedirect + * @param \Magento\Cms\Api\Data\PageInterface $model + * @param \Magento\Backend\Model\View\Result\Redirect $resultRedirect * @param array $data * @return \Magento\Backend\Model\View\Result\Redirect * @throws LocalizedException diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Widget/Chooser.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Widget/Chooser.php index 1c46ac6807eef..b268bee4c60a7 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Widget/Chooser.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Widget/Chooser.php @@ -6,9 +6,11 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page\Widget; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; -class Chooser extends \Magento\Backend\App\Action +class Chooser extends Action implements HttpPostActionInterface, HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Cms/Controller/Index/Index.php b/app/code/Magento/Cms/Controller/Index/Index.php index c027bd1a2b717..59ed1a6248b7c 100644 --- a/app/code/Magento/Cms/Controller/Index/Index.php +++ b/app/code/Magento/Cms/Controller/Index/Index.php @@ -5,6 +5,8 @@ */ namespace Magento\Cms\Controller\Index; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ObjectManager; @@ -15,8 +17,12 @@ use Magento\Framework\View\Result\Page as ResultPage; use Magento\Cms\Helper\Page; use Magento\Store\Model\ScopeInterface; +use Magento\Framework\App\Action\Action; -class Index extends \Magento\Framework\App\Action\Action +/** + * Home page. Needs to be accessible by POST because of the store switching. + */ +class Index extends Action implements HttpGetActionInterface, HttpPostActionInterface { /** * @var ForwardFactory diff --git a/app/code/Magento/Cms/Controller/Noroute/Index.php b/app/code/Magento/Cms/Controller/Noroute/Index.php index db84ce9556dac..b30beae73dce1 100644 --- a/app/code/Magento/Cms/Controller/Noroute/Index.php +++ b/app/code/Magento/Cms/Controller/Noroute/Index.php @@ -6,6 +6,9 @@ */ namespace Magento\Cms\Controller\Noroute; +/** + * @SuppressWarnings(PHPMD.AllPurposeAction) + */ class Index extends \Magento\Framework\App\Action\Action { /** diff --git a/app/code/Magento/Cms/Controller/Page/View.php b/app/code/Magento/Cms/Controller/Page/View.php index ab02bc5e717a1..9d5785450ec71 100644 --- a/app/code/Magento/Cms/Controller/Page/View.php +++ b/app/code/Magento/Cms/Controller/Page/View.php @@ -6,7 +6,14 @@ */ namespace Magento\Cms\Controller\Page; -class View extends \Magento\Framework\App\Action\Action +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\Action; + +/** + * Custom page for storefront. Needs to be accessible by POST because of the store switching. + */ +class View extends Action implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\Controller\Result\ForwardFactory diff --git a/app/code/Magento/Config/App/Config/Type/System.php b/app/code/Magento/Config/App/Config/Type/System.php index 479b4f5c21732..f5d109b198d5a 100644 --- a/app/code/Magento/Config/App/Config/Type/System.php +++ b/app/code/Magento/Config/App/Config/Type/System.php @@ -5,58 +5,46 @@ */ namespace Magento\Config\App\Config\Type; +use Magento\Framework\App\Config\ConfigSourceInterface; use Magento\Framework\App\Config\ConfigTypeInterface; +use Magento\Framework\App\Config\Spi\PostProcessorInterface; +use Magento\Framework\App\Config\Spi\PreProcessorInterface; use Magento\Framework\App\ObjectManager; use Magento\Config\App\Config\Type\System\Reader; +use Magento\Framework\App\ScopeInterface; +use Magento\Framework\Cache\FrontendInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Store\Model\Config\Processor\Fallback; +use Magento\Store\Model\ScopeInterface as StoreScope; /** * System configuration type + * * @api * @since 100.1.2 */ class System implements ConfigTypeInterface { const CACHE_TAG = 'config_scopes'; - const CONFIG_TYPE = 'system'; - /** - * @var \Magento\Framework\App\Config\ConfigSourceInterface - */ - private $source; - /** * @var array */ private $data = []; /** - * @var \Magento\Framework\App\Config\Spi\PostProcessorInterface + * @var PostProcessorInterface */ private $postProcessor; /** - * @var \Magento\Framework\App\Config\Spi\PreProcessorInterface - */ - private $preProcessor; - - /** - * @var \Magento\Framework\Cache\FrontendInterface + * @var FrontendInterface */ private $cache; /** - * @var int - */ - private $cachingNestedLevel; - - /** - * @var \Magento\Store\Model\Config\Processor\Fallback - */ - private $fallback; - - /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var SerializerInterface */ private $serializer; @@ -79,36 +67,34 @@ class System implements ConfigTypeInterface * * @var array */ - private $availableDataScopes = null; + private $availableDataScopes; /** - * @param \Magento\Framework\App\Config\ConfigSourceInterface $source - * @param \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor - * @param \Magento\Store\Model\Config\Processor\Fallback $fallback - * @param \Magento\Framework\Cache\FrontendInterface $cache - * @param \Magento\Framework\Serialize\SerializerInterface $serializer - * @param \Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor + * @param ConfigSourceInterface $source + * @param PostProcessorInterface $postProcessor + * @param Fallback $fallback + * @param FrontendInterface $cache + * @param SerializerInterface $serializer + * @param PreProcessorInterface $preProcessor * @param int $cachingNestedLevel * @param string $configType * @param Reader $reader + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( - \Magento\Framework\App\Config\ConfigSourceInterface $source, - \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor, - \Magento\Store\Model\Config\Processor\Fallback $fallback, - \Magento\Framework\Cache\FrontendInterface $cache, - \Magento\Framework\Serialize\SerializerInterface $serializer, - \Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor, + ConfigSourceInterface $source, + PostProcessorInterface $postProcessor, + Fallback $fallback, + FrontendInterface $cache, + SerializerInterface $serializer, + PreProcessorInterface $preProcessor, $cachingNestedLevel = 1, $configType = self::CONFIG_TYPE, Reader $reader = null ) { - $this->source = $source; $this->postProcessor = $postProcessor; - $this->preProcessor = $preProcessor; $this->cache = $cache; - $this->cachingNestedLevel = $cachingNestedLevel; - $this->fallback = $fallback; $this->serializer = $serializer; $this->configType = $configType; $this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class); @@ -136,27 +122,52 @@ public function get($path = '') { if ($path === '') { $this->data = array_replace_recursive($this->loadAllData(), $this->data); + return $this->data; } + + return $this->getWithParts($path); + } + + /** + * Proceed with parts extraction from path. + * + * @param string $path + * @return array|int|string|boolean + */ + private function getWithParts($path) + { $pathParts = explode('/', $path); - if (count($pathParts) === 1 && $pathParts[0] !== 'default') { + + if (count($pathParts) === 1 && $pathParts[0] !== ScopeInterface::SCOPE_DEFAULT) { if (!isset($this->data[$pathParts[0]])) { $data = $this->readData(); $this->data = array_replace_recursive($data, $this->data); } + return $this->data[$pathParts[0]]; } + $scopeType = array_shift($pathParts); - if ($scopeType === 'default') { + + if ($scopeType === ScopeInterface::SCOPE_DEFAULT) { if (!isset($this->data[$scopeType])) { $this->data = array_replace_recursive($this->loadDefaultScopeData($scopeType), $this->data); } + return $this->getDataByPathParts($this->data[$scopeType], $pathParts); } + $scopeId = array_shift($pathParts); + if (!isset($this->data[$scopeType][$scopeId])) { - $this->data = array_replace_recursive($this->loadScopeData($scopeType, $scopeId), $this->data); + $scopeData = $this->loadScopeData($scopeType, $scopeId); + + if (!isset($this->data[$scopeType][$scopeId])) { + $this->data = array_replace_recursive($scopeData, $this->data); + } } + return isset($this->data[$scopeType][$scopeId]) ? $this->getDataByPathParts($this->data[$scopeType][$scopeId], $pathParts) : null; @@ -170,11 +181,13 @@ public function get($path = '') private function loadAllData() { $cachedData = $this->cache->load($this->configType); + if ($cachedData === false) { $data = $this->readData(); } else { $data = $this->serializer->unserialize($cachedData); } + return $data; } @@ -187,12 +200,14 @@ private function loadAllData() private function loadDefaultScopeData($scopeType) { $cachedData = $this->cache->load($this->configType . '_' . $scopeType); + if ($cachedData === false) { $data = $this->readData(); $this->cacheData($data); } else { $data = [$scopeType => $this->serializer->unserialize($cachedData)]; } + return $data; } @@ -206,6 +221,7 @@ private function loadDefaultScopeData($scopeType) private function loadScopeData($scopeType, $scopeId) { $cachedData = $this->cache->load($this->configType . '_' . $scopeType . '_' . $scopeId); + if ($cachedData === false) { if ($this->availableDataScopes === null) { $cachedScopeData = $this->cache->load($this->configType . '_scopes'); @@ -221,6 +237,7 @@ private function loadScopeData($scopeType, $scopeId) } else { $data = [$scopeType => [$scopeId => $this->serializer->unserialize($cachedData)]]; } + return $data; } @@ -244,7 +261,7 @@ private function cacheData(array $data) [self::CACHE_TAG] ); $scopes = []; - foreach (['websites', 'stores'] as $curScopeType) { + foreach ([StoreScope::SCOPE_WEBSITES, StoreScope::SCOPE_STORES] as $curScopeType) { foreach ($data[$curScopeType] ?? [] as $curScopeId => $curScopeData) { $scopes[$curScopeType][$curScopeId] = 1; $this->cache->save( @@ -256,7 +273,7 @@ private function cacheData(array $data) } $this->cache->save( $this->serializer->serialize($scopes), - $this->configType . "_scopes", + $this->configType . '_scopes', [self::CACHE_TAG] ); } @@ -279,6 +296,7 @@ private function getDataByPathParts($data, $pathParts) return null; } } + return $data; } diff --git a/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php b/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php index 63dbb2b80e334..16b18e020008d 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php @@ -33,6 +33,8 @@ public function __construct( } /** + * Returns element html + * * @param AbstractElement $element * @return string * @codeCoverageIgnore @@ -40,7 +42,7 @@ public function __construct( protected function _getElementHtml(AbstractElement $element) { return $this->dateTimeFormatter->formatObject( - $this->_localeDate->date(intval($element->getValue())), + $this->_localeDate->date((int) $element->getValue()), $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM) ); } diff --git a/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php b/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php index 7f21bf4b92bf4..2e79cec7088b9 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php @@ -10,6 +10,7 @@ /** * Backend system config datetime field renderer + * * @api * @since 100.0.2 */ @@ -35,6 +36,8 @@ public function __construct( } /** + * Returns element html + * * @param AbstractElement $element * @return string */ @@ -44,6 +47,6 @@ protected function _getElementHtml(AbstractElement $element) $format = $this->_localeDate->getDateTimeFormat( \IntlDateFormatter::MEDIUM ); - return $this->dateTimeFormatter->formatObject($this->_localeDate->date(intval($element->getValue())), $format); + return $this->dateTimeFormatter->formatObject($this->_localeDate->date((int) $element->getValue()), $format); } } diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php index b65f6e9d4e4c5..12c6ecbab9fd9 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Config\Controller\Adminhtml\System\Config; -class Edit extends AbstractScopeConfig +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends AbstractScopeConfig implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Index.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Index.php index 66290a7926121..03479085f3f6b 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Index.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Config\Controller\Adminhtml\System\Config; -class Index extends AbstractScopeConfig +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends AbstractScopeConfig implements HttpGetActionInterface { /** * @var \Magento\Backend\Model\View\Result\ForwardFactory diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php index 290a43c9cd62e..2d4b20033806e 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php @@ -5,6 +5,7 @@ */ namespace Magento\Config\Controller\Adminhtml\System\Config; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Config\Controller\Adminhtml\System\AbstractConfig; /** @@ -13,7 +14,7 @@ * @author Magento Core Team * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends AbstractConfig +class Save extends AbstractConfig implements HttpPostActionInterface { /** * Backend Config Model Factory diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/State.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/State.php index 75716fa380be3..5d74eb7ea4e27 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/State.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/State.php @@ -6,7 +6,13 @@ */ namespace Magento\Config\Controller\Adminhtml\System\Config; -class State extends AbstractScopeConfig +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; + +/** + * Save current state of open tabs. GET is allowed for legacy reasons. + */ +class State extends AbstractScopeConfig implements HttpPostActionInterface, HttpGetActionInterface { /** * @var \Magento\Framework\Controller\Result\RawFactory diff --git a/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Button/Save.php b/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Button/Save.php index 8848fc78dad6d..f2de5e72211ee 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Button/Save.php +++ b/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Button/Save.php @@ -8,7 +8,6 @@ use Magento\Ui\Component\Control\Container; use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic; use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableType; -use Magento\Catalog\Model\Product\Type; /** * Class Save @@ -16,16 +15,7 @@ class Save extends Generic { /** - * @var array - */ - private static $availableProductTypes = [ - ConfigurableType::TYPE_CODE, - Type::TYPE_SIMPLE, - Type::TYPE_VIRTUAL - ]; - - /** - * {@inheritdoc} + * @inheritdoc */ public function getButtonData() { @@ -135,7 +125,8 @@ protected function getOptions() } /** - * Retrieve target for button + * Retrieve target for button. + * * @return string */ protected function getSaveTarget() @@ -148,7 +139,8 @@ protected function getSaveTarget() } /** - * Retrieve action for button + * Retrieve action for button. + * * @return string */ protected function getSaveAction() @@ -161,10 +153,12 @@ protected function getSaveAction() } /** + * Is configurable product. + * * @return boolean */ protected function isConfigurableProduct() { - return in_array($this->getProduct()->getTypeId(), self::$availableProductTypes); + return !$this->getProduct()->isComposite() || $this->getProduct()->getTypeId() === ConfigurableType::TYPE_CODE; } } diff --git a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php index 5991097e456f2..34f10b59f3a98 100644 --- a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php +++ b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php @@ -6,10 +6,11 @@ */ namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; -class AddAttribute extends Action +class AddAttribute extends Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptions.php b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptions.php index 6f5f106a8bb24..cfa2562d974f4 100644 --- a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptions.php +++ b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptions.php @@ -6,10 +6,11 @@ */ namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product\Attribute; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory; -class CreateOptions extends Action +class CreateOptions extends Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/GetAttributes.php b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/GetAttributes.php index b6b34073db60d..9f5d5062b5366 100644 --- a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/GetAttributes.php +++ b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/GetAttributes.php @@ -6,10 +6,11 @@ */ namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product\Attribute; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\ConfigurableProduct\Model\AttributesListInterface; -class GetAttributes extends Action +class GetAttributes extends Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Wizard.php b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Wizard.php index 8adfdea96102c..104181aed4fc9 100644 --- a/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Wizard.php +++ b/app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Wizard.php @@ -5,6 +5,8 @@ */ namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; use Magento\Catalog\Controller\Adminhtml\Product\Builder; @@ -13,7 +15,7 @@ /** * Class Wizard */ -class Wizard extends Action +class Wizard extends Action implements HttpPostActionInterface, HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/ConfigurableProductPriceAdditionalStoreViewTest.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/ConfigurableProductPriceAdditionalStoreViewTest.xml index b06067a6d43e4..232dfe8391468 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/ConfigurableProductPriceAdditionalStoreViewTest.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/ConfigurableProductPriceAdditionalStoreViewTest.xml @@ -16,9 +16,7 @@ - - - + @@ -133,12 +131,13 @@ - - + + + @@ -151,7 +150,6 @@ - @@ -181,7 +179,6 @@ - @@ -201,7 +198,6 @@ - @@ -211,6 +207,6 @@ - + diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Adminhtml/Product/Edit/Button/SaveTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Adminhtml/Product/Edit/Button/SaveTest.php index 8df6df53cc065..2d73b61245a4b 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Adminhtml/Product/Edit/Button/SaveTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Adminhtml/Product/Edit/Button/SaveTest.php @@ -38,7 +38,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); $this->productMock = $this->getMockBuilder(ProductInterface::class) - ->setMethods(['isReadonly', 'isDuplicable']) + ->setMethods(['isReadonly', 'isDuplicable', 'isComposite']) ->getMockForAbstractClass(); $this->registryMock->expects(static::any()) diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/attributes_values.js b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/attributes_values.js index cc565cab6b260..1fa65e03f54e0 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/attributes_values.js +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/attributes_values.js @@ -233,7 +233,7 @@ define([ */ requestAttributes: function (attributeIds) { $.ajax({ - type: 'POST', + type: 'GET', url: this.optionsUrl, data: { attributes: attributeIds diff --git a/app/code/Magento/Contact/Controller/Index/Index.php b/app/code/Magento/Contact/Controller/Index/Index.php index 4b734c4f9b610..562b077087241 100644 --- a/app/code/Magento/Contact/Controller/Index/Index.php +++ b/app/code/Magento/Contact/Controller/Index/Index.php @@ -6,9 +6,10 @@ */ namespace Magento\Contact\Controller\Index; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; -class Index extends \Magento\Contact\Controller\Index +class Index extends \Magento\Contact\Controller\Index implements HttpGetActionInterface { /** * Show Contact Us page diff --git a/app/code/Magento/Contact/Controller/Index/Post.php b/app/code/Magento/Contact/Controller/Index/Post.php index bdc2fee088d9e..cbe49a767262c 100644 --- a/app/code/Magento/Contact/Controller/Index/Post.php +++ b/app/code/Magento/Contact/Controller/Index/Post.php @@ -7,6 +7,7 @@ namespace Magento\Contact\Controller\Index; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Contact\Model\ConfigInterface; use Magento\Contact\Model\MailInterface; use Magento\Framework\App\Action\Context; @@ -17,7 +18,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; -class Post extends \Magento\Contact\Controller\Index +class Post extends \Magento\Contact\Controller\Index implements HttpPostActionInterface { /** * @var DataPersistorInterface diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php index 38e20355b6699..34d24a8b0a7a8 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php @@ -7,10 +7,13 @@ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Controller\ResultFactory; +use Magento\CurrencySymbol\Controller\Adminhtml\System\Currency as CurrencyAction; -class FetchRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency +class FetchRates extends CurrencyAction implements HttpGetActionInterface, HttpPostActionInterface { /** * Fetch rates action diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/Index.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/Index.php index 9b07777a14dc7..a9b1b78cbc668 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/Index.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency; -class Index extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpGetActionInterface { /** * Currency management main page diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php index ae13c4d399e47..8dd6b5e6fac41 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php @@ -7,7 +7,9 @@ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency; -class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpPostActionInterface { /** * Save rates action diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Index.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Index.php index 808372bd3a697..1762a907a75a4 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Index.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol; -class Index extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol implements HttpGetActionInterface { /** * Show Currency Symbols Management dialog diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php index eee7961b02f4a..703117f34fce6 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php @@ -6,7 +6,9 @@ */ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol; -class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol implements HttpPostActionInterface { /** * Save custom Currency symbol diff --git a/app/code/Magento/Customer/Controller/Account/Create.php b/app/code/Magento/Customer/Controller/Account/Create.php index 8f1bc107547ea..450fe461534a6 100644 --- a/app/code/Magento/Customer/Controller/Account/Create.php +++ b/app/code/Magento/Customer/Controller/Account/Create.php @@ -6,12 +6,13 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Model\Registration; use Magento\Customer\Model\Session; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; -class Create extends \Magento\Customer\Controller\AbstractAccount +class Create extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface { /** * @var \Magento\Customer\Model\Registration diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index bb94063226f41..79a575add7347 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -5,6 +5,7 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Model\Account\Redirect as AccountRedirect; use Magento\Customer\Api\Data\AddressInterface; use Magento\Framework\Api\DataObjectHelper; @@ -40,7 +41,7 @@ * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class CreatePost extends AbstractAccount implements CsrfAwareActionInterface +class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface { /** * @var \Magento\Customer\Api\AccountManagementInterface diff --git a/app/code/Magento/Customer/Controller/Account/Edit.php b/app/code/Magento/Customer/Controller/Account/Edit.php index 3c1e60199399b..7c2b7215a05ef 100644 --- a/app/code/Magento/Customer/Controller/Account/Edit.php +++ b/app/code/Magento/Customer/Controller/Account/Edit.php @@ -6,13 +6,14 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Api\DataObjectHelper; use Magento\Customer\Model\Session; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; -class Edit extends \Magento\Customer\Controller\AbstractAccount +class Edit extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface { /** * @var \Magento\Customer\Api\CustomerRepositoryInterface diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index aa5e088f9c892..e3b3d8345224e 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -7,6 +7,7 @@ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Model\AuthenticationInterface; use Magento\Customer\Model\Customer\Mapper; use Magento\Customer\Model\EmailNotificationInterface; @@ -31,7 +32,7 @@ * Class EditPost * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class EditPost extends AbstractAccount implements CsrfAwareActionInterface +class EditPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface { /** * Form code for data extractor diff --git a/app/code/Magento/Customer/Controller/Account/ForgotPassword.php b/app/code/Magento/Customer/Controller/Account/ForgotPassword.php index f115b64efebdd..8b5d0612050c3 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPassword.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPassword.php @@ -6,11 +6,12 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class ForgotPassword extends \Magento\Customer\Controller\AbstractAccount +class ForgotPassword extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php index f302473873087..3c7fca99184d0 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php @@ -6,6 +6,7 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\Session; @@ -18,7 +19,7 @@ * ForgotPasswordPost controller * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class ForgotPasswordPost extends \Magento\Customer\Controller\AbstractAccount +class ForgotPasswordPost extends \Magento\Customer\Controller\AbstractAccount implements HttpPostActionInterface { /** * @var \Magento\Customer\Api\AccountManagementInterface diff --git a/app/code/Magento/Customer/Controller/Account/Index.php b/app/code/Magento/Customer/Controller/Account/Index.php index 2ecf79d35b11f..301fd584cfabe 100644 --- a/app/code/Magento/Customer/Controller/Account/Index.php +++ b/app/code/Magento/Customer/Controller/Account/Index.php @@ -6,10 +6,11 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class Index extends \Magento\Customer\Controller\AbstractAccount +class Index extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Customer/Controller/Account/Login.php b/app/code/Magento/Customer/Controller/Account/Login.php index d685191bf43b5..64cc24095f935 100644 --- a/app/code/Magento/Customer/Controller/Account/Login.php +++ b/app/code/Magento/Customer/Controller/Account/Login.php @@ -6,12 +6,17 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\View\Result\PageFactory; use Magento\Customer\Controller\AbstractAccount; -class Login extends AbstractAccount +/** + * Login form page. Accepts POST for backward compatibility reasons. + */ +class Login extends AbstractAccount implements HttpGetActionInterface, HttpPostActionInterface { /** * @var Session diff --git a/app/code/Magento/Customer/Controller/Account/LoginPost.php b/app/code/Magento/Customer/Controller/Account/LoginPost.php index 5c7eee78e5f4a..04051fbbf366b 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -6,6 +6,7 @@ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Model\Account\Redirect as AccountRedirect; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; @@ -27,7 +28,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class LoginPost extends AbstractAccount implements CsrfAwareActionInterface +class LoginPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface { /** * @var \Magento\Customer\Api\AccountManagementInterface diff --git a/app/code/Magento/Customer/Controller/Account/Logout.php b/app/code/Magento/Customer/Controller/Account/Logout.php index 19dabf9effa56..9344f482bd6e5 100644 --- a/app/code/Magento/Customer/Controller/Account/Logout.php +++ b/app/code/Magento/Customer/Controller/Account/Logout.php @@ -6,6 +6,8 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ObjectManager; @@ -13,7 +15,10 @@ use Magento\Framework\Stdlib\Cookie\PhpCookieManager; use Magento\Customer\Controller\AbstractAccount; -class Logout extends AbstractAccount +/** + * Sign out a customer. + */ +class Logout extends AbstractAccount implements HttpGetActionInterface, HttpPostActionInterface { /** * @var Session diff --git a/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php b/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php index c58416434c0b6..e00494d221d2c 100644 --- a/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php +++ b/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php @@ -6,10 +6,11 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class LogoutSuccess extends \Magento\Customer\Controller\AbstractAccount +class LogoutSuccess extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index ef92bd2ef533b..a4a0944137e1b 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Address; -class Delete extends \Magento\Customer\Controller\Address +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\Customer\Controller\Address implements HttpPostActionInterface { /** * @return \Magento\Framework\Controller\Result\Redirect diff --git a/app/code/Magento/Customer/Controller/Address/Edit.php b/app/code/Magento/Customer/Controller/Address/Edit.php index a30eb10b11524..0a5affefae349 100644 --- a/app/code/Magento/Customer/Controller/Address/Edit.php +++ b/app/code/Magento/Customer/Controller/Address/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Address; -class Edit extends \Magento\Customer\Controller\Address +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Customer\Controller\Address implements HttpGetActionInterface { /** * Customer address edit action diff --git a/app/code/Magento/Customer/Controller/Address/Form.php b/app/code/Magento/Customer/Controller/Address/Form.php index fc62a6c1a572d..9b3f4e36be0ed 100644 --- a/app/code/Magento/Customer/Controller/Address/Form.php +++ b/app/code/Magento/Customer/Controller/Address/Form.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Address; -class Form extends \Magento\Customer\Controller\Address +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Form extends \Magento\Customer\Controller\Address implements HttpGetActionInterface { /** * Address book form diff --git a/app/code/Magento/Customer/Controller/Address/FormPost.php b/app/code/Magento/Customer/Controller/Address/FormPost.php index 60e1f6eb172f5..217af0abd7592 100644 --- a/app/code/Magento/Customer/Controller/Address/FormPost.php +++ b/app/code/Magento/Customer/Controller/Address/FormPost.php @@ -6,6 +6,7 @@ namespace Magento\Customer\Controller\Address; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\AddressRepositoryInterface; use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\RegionInterface; @@ -27,7 +28,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class FormPost extends \Magento\Customer\Controller\Address +class FormPost extends \Magento\Customer\Controller\Address implements HttpPostActionInterface { /** * @var RegionFactory diff --git a/app/code/Magento/Customer/Controller/Address/Index.php b/app/code/Magento/Customer/Controller/Address/Index.php index ad04c7bd5c71b..92c6078349d6e 100644 --- a/app/code/Magento/Customer/Controller/Address/Index.php +++ b/app/code/Magento/Customer/Controller/Address/Index.php @@ -6,12 +6,13 @@ */ namespace Magento\Customer\Controller\Address; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Api\CustomerRepositoryInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Index extends \Magento\Customer\Controller\Address +class Index extends \Magento\Customer\Controller\Address implements HttpGetActionInterface { /** * @var CustomerRepositoryInterface @@ -28,9 +29,9 @@ class Index extends \Magento\Customer\Controller\Address * @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper - * @param CustomerRepositoryInterface $customerRepository * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param CustomerRepositoryInterface $customerRepository * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Customer/Controller/Address/NewAction.php b/app/code/Magento/Customer/Controller/Address/NewAction.php index e97c746057880..043c2b91db292 100644 --- a/app/code/Magento/Customer/Controller/Address/NewAction.php +++ b/app/code/Magento/Customer/Controller/Address/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Address; -class NewAction extends \Magento\Customer\Controller\Address +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Customer\Controller\Address implements HttpGetActionInterface { /** * @return \Magento\Framework\Controller\Result\Forward diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php index 571ef57702bc3..ab32ea08a44aa 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php @@ -6,9 +6,10 @@ */ namespace Magento\Customer\Controller\Adminhtml\Group; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Exception\NoSuchEntityException; -class Delete extends \Magento\Customer\Controller\Adminhtml\Group +class Delete extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface { /** * Delete customer group. diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php index 9da132078c9cb..221d01a112ea4 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Adminhtml\Group; -class Edit extends \Magento\Customer\Controller\Adminhtml\Group +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Customer\Controller\Adminhtml\Group implements HttpGetActionInterface { /** * Edit customer group action. Forward to new action. diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php index 1246b6a6d0bd2..6da79d2c40f31 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Customer\Controller\Adminhtml\Group; -class Index extends \Magento\Customer\Controller\Adminhtml\Group +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Customer\Controller\Adminhtml\Group implements HttpGetActionInterface { /** * Customer groups list. diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php index 2c230cd0b3f7b..a5c832bf0f1e4 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php @@ -6,9 +6,10 @@ */ namespace Magento\Customer\Controller\Adminhtml\Group; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Controller\RegistryConstants; -class NewAction extends \Magento\Customer\Controller\Adminhtml\Group +class NewAction extends \Magento\Customer\Controller\Adminhtml\Group implements HttpGetActionInterface { /** * Initialize current group and set it in the registry. diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index 936d9cdbc1704..7549315f9ffcd 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -6,11 +6,12 @@ */ namespace Magento\Customer\Controller\Adminhtml\Group; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\Data\GroupInterfaceFactory; use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Api\GroupRepositoryInterface; -class Save extends \Magento\Customer\Controller\Adminhtml\Group +class Save extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface { /** * @var \Magento\Framework\Reflection\DataObjectProcessor diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php index 7a981b82b7e1e..15da8b20adbca 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php @@ -5,9 +5,10 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class Delete extends \Magento\Customer\Controller\Adminhtml\Index +class Delete extends \Magento\Customer\Controller\Adminhtml\Index implements HttpPostActionInterface { /** * Delete customer action diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php index 90417c1ad5443..25b4ddd4e1732 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php @@ -5,10 +5,11 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\Exception\NoSuchEntityException; -class Edit extends \Magento\Customer\Controller\Adminhtml\Index +class Edit extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface { /** * Customer edit action diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php index 861ac93b262cb..b1986c8b6f08a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php @@ -5,7 +5,9 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; -class Index extends \Magento\Customer\Controller\Adminhtml\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface { /** * Customers list action diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php index 2d0ee3ae13da4..98db7be559cdf 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php @@ -11,11 +11,12 @@ use Magento\Customer\Ui\Component\Listing\AttributeRepository; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class InlineEdit extends \Magento\Backend\App\Action +class InlineEdit extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session @@ -139,7 +140,7 @@ public function execute() * Receive entity(customer|customer_address) data from request * * @param array $data - * @param null $isCustomerData + * @param mixed $isCustomerData * @return array */ protected function getData(array $data, $isCustomerData = null) diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php index 762b872b97b6d..a540ad9d7a70e 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php @@ -5,6 +5,7 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory; use Magento\Eav\Model\Entity\Collection\AbstractCollection; @@ -15,7 +16,7 @@ /** * Class MassAssignGroup */ -class MassAssignGroup extends AbstractMassAction +class MassAssignGroup extends AbstractMassAction implements HttpPostActionInterface { /** * @var CustomerRepositoryInterface diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php index 453585c881a05..334018a881f12 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php @@ -5,6 +5,7 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory; use Magento\Eav\Model\Entity\Collection\AbstractCollection; @@ -15,7 +16,7 @@ /** * Class MassDelete */ -class MassDelete extends AbstractMassAction +class MassDelete extends AbstractMassAction implements HttpPostActionInterface { /** * @var CustomerRepositoryInterface diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php index e6cf2aa234e09..19a16f01acfc2 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php @@ -5,7 +5,9 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; -class NewAction extends \Magento\Customer\Controller\Adminhtml\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface { /** * Create new customer action diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php index 37c8ed5a252f8..6ef6ddd0e732b 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php @@ -5,10 +5,11 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\SecurityViolationException; -class ResetPassword extends \Magento\Customer\Controller\Adminhtml\Index +class ResetPassword extends \Magento\Customer\Controller\Adminhtml\Index implements HttpPostActionInterface { /** * Reset password handler diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 12732f81f78a0..45a7c0182d41c 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -5,6 +5,7 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\AddressMetadataInterface; use Magento\Customer\Api\CustomerMetadataInterface; use Magento\Customer\Api\Data\CustomerInterface; @@ -16,7 +17,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Customer\Controller\Adminhtml\Index +class Save extends \Magento\Customer\Controller\Adminhtml\Index implements HttpPostActionInterface { /** * @var EmailNotificationInterface diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php index 8e098a3b7ee16..be09eb7daff76 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php @@ -5,10 +5,13 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\Message\Error; +use Magento\Customer\Controller\Adminhtml\Index as CustomerAction; -class Validate extends \Magento\Customer\Controller\Adminhtml\Index +class Validate extends CustomerAction implements HttpPostActionInterface, HttpGetActionInterface { /** * Customer validation diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Online/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Online/Index.php index 3cf9a82b8b876..0262513d029f0 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Online/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Online/Index.php @@ -6,10 +6,11 @@ */ namespace Magento\Customer\Controller\Adminhtml\Online; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class Index extends \Magento\Backend\App\Action +class Index extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Customer/Controller/Ajax/Login.php b/app/code/Magento/Customer/Controller/Ajax/Login.php index 73869bc3f2958..7d1e86c949792 100644 --- a/app/code/Magento/Customer/Controller/Ajax/Login.php +++ b/app/code/Magento/Customer/Controller/Ajax/Login.php @@ -6,6 +6,7 @@ namespace Magento\Customer\Controller\Ajax; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Api\AccountManagementInterface; use Magento\Framework\Exception\EmailNotConfirmedException; use Magento\Framework\Exception\InvalidEmailOrPasswordException; @@ -23,7 +24,7 @@ * @method \Magento\Framework\App\Response\Http getResponse() * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Login extends \Magento\Framework\App\Action\Action +class Login extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface { /** * @var \Magento\Framework\Session\Generic diff --git a/app/code/Magento/Customer/Controller/Section/Load.php b/app/code/Magento/Customer/Controller/Section/Load.php index 7a2345c91750c..e55b1d0df26c7 100644 --- a/app/code/Magento/Customer/Controller/Section/Load.php +++ b/app/code/Magento/Customer/Controller/Section/Load.php @@ -5,6 +5,7 @@ */ namespace Magento\Customer\Controller\Section; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Customer\CustomerData\Section\Identifier; use Magento\Customer\CustomerData\SectionPoolInterface; use Magento\Framework\App\Action\Context; @@ -13,7 +14,7 @@ /** * Customer section controller */ -class Load extends \Magento\Framework\App\Action\Action +class Load extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface { /** * @var JsonFactory diff --git a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/GroupActionsTest.php b/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/GroupActionsTest.php deleted file mode 100644 index fdd841ea88cf8..0000000000000 --- a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/GroupActionsTest.php +++ /dev/null @@ -1,141 +0,0 @@ -createMock(ContextInterface::class); - - $processor = $this->getMockBuilder(Processor::class) - ->disableOriginalConstructor() - ->getMock(); - $context->expects(static::never()) - ->method('getProcessor') - ->willReturn($processor); - - $this->urlBuilder = $this->createMock(UrlInterface::class); - - $this->escaper = $this->getMockBuilder(Escaper::class) - ->disableOriginalConstructor() - ->setMethods(['escapeHtml']) - ->getMock(); - - $this->groupActions = $objectManager->getObject(GroupActions::class, [ - 'context' => $context, - 'urlBuilder' => $this->urlBuilder, - 'escaper' => $this->escaper, - ]); - } - - /** - * @covers \Magento\Customer\Ui\Component\Listing\Column\GroupActions::prepareDataSource - */ - public function testPrepareDataSource() - { - $groupId = 1; - $groupCode = 'group code'; - $items = [ - 'data' => [ - 'items' => [ - [ - 'customer_group_id' => $groupId, - 'customer_group_code' => $groupCode - ] - ] - ] - ]; - $name = 'item_name'; - $expectedItems = [ - [ - 'customer_group_id' => $groupId, - 'customer_group_code' => $groupCode, - $name => [ - 'edit' => [ - 'href' => 'test/url/edit', - 'label' => __('Edit'), - ], - 'delete' => [ - 'href' => 'test/url/delete', - 'label' => __('Delete'), - 'confirm' => [ - 'title' => __('Delete %1', $groupCode), - 'message' => __('Are you sure you want to delete a %1 record?', $groupCode) - ], - ] - ], - ] - ]; - - $this->escaper->expects(static::once()) - ->method('escapeHtml') - ->with($groupCode) - ->willReturn($groupCode); - - $this->urlBuilder->expects(static::exactly(2)) - ->method('getUrl') - ->willReturnMap( - [ - [ - GroupActions::URL_PATH_EDIT, - [ - 'id' => $groupId - ], - 'test/url/edit', - ], - [ - GroupActions::URL_PATH_DELETE, - [ - 'id' => $groupId - ], - 'test/url/delete', - ], - ] - ); - - $this->groupActions->setData('name', $name); - - $actual = $this->groupActions->prepareDataSource($items); - static::assertEquals($expectedItems, $actual['data']['items']); - } -} diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Column/GroupActions.php b/app/code/Magento/Customer/Ui/Component/Listing/Column/GroupActions.php index a8a3429ebadb0..00c5f99fab46c 100644 --- a/app/code/Magento/Customer/Ui/Component/Listing/Column/GroupActions.php +++ b/app/code/Magento/Customer/Ui/Component/Listing/Column/GroupActions.php @@ -98,7 +98,8 @@ public function prepareDataSource(array $dataSource) 'confirm' => [ 'title' => __('Delete %1', $title), 'message' => __('Are you sure you want to delete a %1 record?', $title) - ] + ], + 'post' => true ]; } } diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/ChangePassword.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/ChangePassword.php new file mode 100644 index 0000000000000..84425df62a622 --- /dev/null +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/ChangePassword.php @@ -0,0 +1,88 @@ +userContext = $userContext; + $this->accountManagement = $accountManagement; + $this->customerResolver = $customerResolver; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + if (!isset($args['currentPassword'])) { + throw new GraphQlInputException(__('"currentPassword" value should be specified')); + } + + if (!isset($args['newPassword'])) { + throw new GraphQlInputException(__('"newPassword" value should be specified')); + } + + $customerId = (int)$this->userContext->getUserId(); + if ($customerId === 0) { + throw new GraphQlAuthorizationException( + __( + 'Current customer does not have access to the resource "%1"', + [Customer::ENTITY] + ) + ); + } + + $this->accountManagement->changePasswordById($customerId, $args['currentPassword'], $args['newPassword']); + $data = $this->customerResolver->getCustomerById($customerId); + + return $data; + } +} diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php new file mode 100644 index 0000000000000..b756a96411a44 --- /dev/null +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/GenerateCustomerToken.php @@ -0,0 +1,61 @@ +customerTokenService = $customerTokenService; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + try { + if (!isset($args['email'])) { + throw new GraphQlInputException(__('"email" value should be specified')); + } + if (!isset($args['password'])) { + throw new GraphQlInputException(__('"password" value should be specified')); + } + $token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']); + return ['token' => $token]; + } catch (AuthenticationException $e) { + throw new GraphQlAuthorizationException( + __($e->getMessage()) + ); + } + } +} diff --git a/app/code/Magento/CustomerGraphQl/composer.json b/app/code/Magento/CustomerGraphQl/composer.json index 290d925215ec2..c26c83c95be38 100644 --- a/app/code/Magento/CustomerGraphQl/composer.json +++ b/app/code/Magento/CustomerGraphQl/composer.json @@ -6,6 +6,7 @@ "php": "~7.1.3||~7.2.0", "magento/module-customer": "*", "magento/module-authorization": "*", + "magento/module-integration": "*", "magento/framework": "*" }, "suggest": { diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 91b7ef1f9be15..93c741adea87b 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -5,6 +5,15 @@ type Query { customer: Customer @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\Customer") @doc(description: "The customer query returns information about a customer account") } +type Mutation { + generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") + changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\ChangePassword") @doc(description:"Changes password for logged in customer") +} + +type CustomerToken { + token: String @doc(description: "The customer token") +} + type Customer @doc(description: "Customer defines the customer name and address and other details") { created_at: String @doc(description: "Timestamp indicating when the account was created") group_id: Int @doc(description: "The group assigned to the user. Default values are 0 (Not logged in), 1 (General), 2 (Wholesale), and 3 (Retailer)") diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Edit.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Edit.php index 240b688402b7e..998cf62a83abd 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Edit.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Email\Controller\Adminhtml\Email\Template; -class Edit extends \Magento\Email\Controller\Adminhtml\Email\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Email\Controller\Adminhtml\Email\Template implements HttpGetActionInterface { /** * Edit transactional email action diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Index.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Index.php index 11b38ae8e503a..013f97b9ad318 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Index.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Email\Controller\Adminhtml\Email\Template; -class Index extends \Magento\Email\Controller\Adminhtml\Email\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Email\Controller\Adminhtml\Email\Template implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/NewAction.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/NewAction.php index f5024943e833a..87f5470440db7 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/NewAction.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Email\Controller\Adminhtml\Email\Template; -class NewAction extends \Magento\Email\Controller\Adminhtml\Email\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Email\Controller\Adminhtml\Email\Template implements HttpGetActionInterface { /** * New transactional email action diff --git a/app/code/Magento/Email/view/frontend/email/header.html b/app/code/Magento/Email/view/frontend/email/header.html index a6895f629b641..c4f49698dc69b 100644 --- a/app/code/Magento/Email/view/frontend/email/header.html +++ b/app/code/Magento/Email/view/frontend/email/header.html @@ -43,8 +43,6 @@ {{if logo_height}} height="{{var logo_height}}" - {{else}} - height="52" {{/if}} src="{{var logo_url}}" diff --git a/app/code/Magento/Email/view/frontend/web/logo_email.png b/app/code/Magento/Email/view/frontend/web/logo_email.png index d01b530456e81..0cca183e08da2 100644 Binary files a/app/code/Magento/Email/view/frontend/web/logo_email.png and b/app/code/Magento/Email/view/frontend/web/logo_email.png differ diff --git a/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php b/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php index 8e42e0c1313c4..86fc0082f7a5a 100644 --- a/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php +++ b/app/code/Magento/EncryptionKey/Controller/Adminhtml/Crypt/Key/Index.php @@ -6,10 +6,12 @@ */ namespace Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + /** * Key Index action */ -class Index extends \Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key +class Index extends \Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key implements HttpGetActionInterface { /** * Render main page with form diff --git a/app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml b/app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml index 7fad5635f8690..900d4a1bd5bbc 100644 --- a/app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml +++ b/app/code/Magento/GroupedProduct/view/frontend/templates/product/view/type/grouped.phtml @@ -19,7 +19,9 @@ 0; ?>
- +
diff --git a/app/code/Magento/GroupedProduct/view/frontend/web/js/product-ids-resolver.js b/app/code/Magento/GroupedProduct/view/frontend/web/js/product-ids-resolver.js new file mode 100644 index 0000000000000..e6294d8043a50 --- /dev/null +++ b/app/code/Magento/GroupedProduct/view/frontend/web/js/product-ids-resolver.js @@ -0,0 +1,25 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + 'jquery', + 'Magento_Catalog/js/product/view/product-ids' +], function ($, productIds) { + 'use strict'; + + /** + * Returns id's of products in form. + * + * @param {Object} config + * @param {HTMLElement} element + * @return {Array} + */ + return function (config, element) { + $(element).find('div[data-product-id]').each(function () { + productIds.push($(this).data('productId').toString()); + }); + + return productIds(); + }; +}); diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php index 06d8610a247cc..38bfbd88b0c12 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php @@ -5,6 +5,7 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Export; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; use Magento\ImportExport\Controller\Adminhtml\Export as ExportController; use Magento\Backend\App\Action\Context; @@ -13,7 +14,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\LocalizedException; -class Export extends ExportController +class Export extends ExportController implements HttpPostActionInterface { /** * @var \Magento\Framework\App\Response\Http\FileFactory diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php index 05475b5161977..722d32c9eb21a 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php @@ -5,10 +5,12 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Export; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\ImportExport\Controller\Adminhtml\Export as ExportController; use Magento\Framework\Controller\ResultFactory; -class GetFilter extends ExportController +class GetFilter extends ExportController implements HttpGetActionInterface, HttpPostActionInterface { /** * Get grid-filter of entity attributes action. diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php index d2ca99f1a7973..3dd5bfd550a38 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php @@ -5,10 +5,11 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Export; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\ImportExport\Controller\Adminhtml\Export as ExportController; use Magento\Framework\Controller\ResultFactory; -class Index extends ExportController +class Index extends ExportController implements HttpGetActionInterface { /** * Index action. diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php index df32d61cceb7f..3cca7ae7ccce2 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php @@ -5,10 +5,11 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Import; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\ImportExport\Controller\Adminhtml\Import as ImportController; use Magento\Framework\Controller\ResultFactory; -class Index extends ImportController +class Index extends ImportController implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php index 695a0e61709f1..8896f84ce2471 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php @@ -5,10 +5,11 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Import; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\ImportExport\Controller\Adminhtml\ImportResult as ImportResultController; use Magento\Framework\Controller\ResultFactory; -class Start extends ImportResultController +class Start extends ImportResultController implements HttpPostActionInterface { /** * @var \Magento\ImportExport\Model\Import diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php index df9f63e79b75e..204e9b11085ed 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php @@ -5,15 +5,15 @@ */ namespace Magento\ImportExport\Controller\Adminhtml\Import; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\ImportExport\Controller\Adminhtml\ImportResult as ImportResultController; use Magento\ImportExport\Model\Import; use Magento\ImportExport\Block\Adminhtml\Import\Frame\Result; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\ImportExport\Model\Import\Adapter as ImportAdapter; -use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface; -class Validate extends ImportResultController +class Validate extends ImportResultController implements HttpPostActionInterface { /** * @var Import @@ -161,7 +161,7 @@ private function addMessageForValidResult(Result $resultBlock) /** * Collect errors and add error messages to Result block * - * Get all errors from ProcessingErrorAggregatorInterface and add appropriated error messages + * Get all errors from Error Aggregator and add appropriated error messages * to Result block. * * @param Result $resultBlock diff --git a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/ListAction.php b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/ListAction.php index 02e600dbd939f..35cefbcda43e7 100644 --- a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/ListAction.php +++ b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/ListAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Indexer\Controller\Adminhtml\Indexer; -class ListAction extends \Magento\Indexer\Controller\Adminhtml\Indexer +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class ListAction extends \Magento\Indexer\Controller\Adminhtml\Indexer implements HttpGetActionInterface { /** * Display processes grid action diff --git a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassChangelog.php b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassChangelog.php index b4a4d9f06ae48..3dffd514218d6 100644 --- a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassChangelog.php +++ b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassChangelog.php @@ -6,7 +6,9 @@ */ namespace Magento\Indexer\Controller\Adminhtml\Indexer; -class MassChangelog extends \Magento\Indexer\Controller\Adminhtml\Indexer +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class MassChangelog extends \Magento\Indexer\Controller\Adminhtml\Indexer implements HttpPostActionInterface { /** * Turn mview on for the given indexers diff --git a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassOnTheFly.php b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassOnTheFly.php index 7ace4a64d3829..9f7faff8843a3 100644 --- a/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassOnTheFly.php +++ b/app/code/Magento/Indexer/Controller/Adminhtml/Indexer/MassOnTheFly.php @@ -6,7 +6,9 @@ */ namespace Magento\Indexer\Controller\Adminhtml\Indexer; -class MassOnTheFly extends \Magento\Indexer\Controller\Adminhtml\Indexer +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class MassOnTheFly extends \Magento\Indexer\Controller\Adminhtml\Indexer implements HttpPostActionInterface { /** * Turn mview off for the given indexers diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php index 36073af56327a..4ce462bb44c89 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php @@ -6,11 +6,12 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info; use Magento\Framework\Exception\IntegrationException; use Magento\Framework\Controller\ResultFactory; -class Delete extends \Magento\Integration\Controller\Adminhtml\Integration +class Delete extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpPostActionInterface { /** * Delete the integration. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Edit.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Edit.php index 97cd7b46e086f..599b6017059e1 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Edit.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Edit.php @@ -6,11 +6,12 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info; use Magento\Framework\Exception\IntegrationException; -class Edit extends \Magento\Integration\Controller\Adminhtml\Integration +class Edit extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface { /** * Edit integration action. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Grid.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Grid.php index bd10873a59f3b..f3ad4306db5a5 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Grid.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Grid.php @@ -6,7 +6,11 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; -class Grid extends \Magento\Integration\Controller\Adminhtml\Integration +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Integration\Controller\Adminhtml\Integration as IntegrationAction; + +class Grid extends IntegrationAction implements HttpPostActionInterface, HttpGetActionInterface { /** * AJAX integrations grid. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Index.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Index.php index 2caf9054ce356..131e1e149473f 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Index.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; -class Index extends \Magento\Integration\Controller\Adminhtml\Integration +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface { /** * Integrations grid. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/NewAction.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/NewAction.php index e05d559aa1cd9..7354b22ccf469 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/NewAction.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; -class NewAction extends \Magento\Integration\Controller\Adminhtml\Integration +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface { /** * New integration action. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog.php index 8c2e10ebf1f32..8b2a94da01d70 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog.php @@ -6,9 +6,10 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Exception\IntegrationException; -class PermissionsDialog extends \Magento\Integration\Controller\Adminhtml\Integration +class PermissionsDialog extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface { /** * Show permissions popup. diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Save.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Save.php index cb2fcb2ba0e29..8bcbb45653494 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Save.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Save.php @@ -5,6 +5,7 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info; use Magento\Framework\Exception\IntegrationException; use Magento\Framework\Exception\LocalizedException; @@ -17,7 +18,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Integration\Controller\Adminhtml\Integration +class Save extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpPostActionInterface { /** * @var SecurityCookie diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensDialog.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensDialog.php index dcea6da321281..4c99dafb1d997 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensDialog.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensDialog.php @@ -6,9 +6,10 @@ */ namespace Magento\Integration\Controller\Adminhtml\Integration; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Integration\Model\Integration as IntegrationModel; -class TokensDialog extends \Magento\Integration\Controller\Adminhtml\Integration +class TokensDialog extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface { /** * Set success message based on Integration activation or re-authorization. diff --git a/app/code/Magento/Integration/view/adminhtml/templates/integration/popup_container.phtml b/app/code/Magento/Integration/view/adminhtml/templates/integration/popup_container.phtml index 8b7e787337e1a..ae16da1760f62 100644 --- a/app/code/Magento/Integration/view/adminhtml/templates/integration/popup_container.phtml +++ b/app/code/Magento/Integration/view/adminhtml/templates/integration/popup_container.phtml @@ -15,7 +15,8 @@ "jquery", 'Magento_Ui/js/modal/confirm', "jquery/ui", - "Magento_Integration/js/integration" + "Magento_Integration/js/integration", + 'mage/dataPost' ], function ($, Confirm) { window.integration = new Integration( @@ -37,7 +38,7 @@ content: "", actions: { confirm: function () { - window.location.href = $(e.target).data('url'); + $.mage.dataPost().postData({action: $(e.target).data('url'), data: {}}); } } }); diff --git a/app/code/Magento/Multishipping/Controller/Checkout/Addresses.php b/app/code/Magento/Multishipping/Controller/Checkout/Addresses.php index 78ea9fc1d2b88..f97589342bc38 100644 --- a/app/code/Magento/Multishipping/Controller/Checkout/Addresses.php +++ b/app/code/Magento/Multishipping/Controller/Checkout/Addresses.php @@ -6,9 +6,10 @@ */ namespace Magento\Multishipping\Controller\Checkout; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Multishipping\Model\Checkout\Type\Multishipping\State; -class Addresses extends \Magento\Multishipping\Controller\Checkout +class Addresses extends \Magento\Multishipping\Controller\Checkout implements HttpGetActionInterface { /** * Multishipping checkout select address page diff --git a/app/code/Magento/Multishipping/Controller/Checkout/Index.php b/app/code/Magento/Multishipping/Controller/Checkout/Index.php index 1fa96cfab8a1a..a4314d6d51883 100644 --- a/app/code/Magento/Multishipping/Controller/Checkout/Index.php +++ b/app/code/Magento/Multishipping/Controller/Checkout/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Multishipping\Controller\Checkout; -class Index extends \Magento\Multishipping\Controller\Checkout +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Multishipping\Controller\Checkout implements HttpGetActionInterface { /** * Index action of Multishipping checkout diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php index 9412b13895599..84ee5285a735b 100644 --- a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php @@ -176,8 +176,6 @@ class Multishipping extends \Magento\Framework\DataObject private $dataObjectHelper; /** - * Constructor - * * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Sales\Model\OrderFactory $orderFactory @@ -202,8 +200,9 @@ class Multishipping extends \Magento\Framework\DataObject * @param array $data * @param \Magento\Quote\Api\Data\CartExtensionFactory|null $cartExtensionFactory * @param AllowedCountries|null $allowedCountryReader - * @param Multishipping\PlaceOrderFactory $placeOrderFactory - * @param LoggerInterface $logger + * @param Multishipping\PlaceOrderFactory|null $placeOrderFactory + * @param LoggerInterface|null $logger + * @param \Magento\Framework\Api\DataObjectHelper|null $dataObjectHelper * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -272,6 +271,7 @@ public function __construct( /** * Initialize multishipping checkout. + * * Split virtual/not virtual items between default billing/shipping addresses * * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping @@ -337,6 +337,7 @@ protected function _init() /** * Get quote items assigned to different quote addresses populated per item qty. + * * Based on result array we can display each item separately * * @return array @@ -397,7 +398,7 @@ public function removeAddressItem($addressId, $itemId) /** * Assign quote items to addresses and specify items qty * - * array structure: + * Array structure: * array( * $quoteItemId => array( * 'qty' => $qty, @@ -693,6 +694,7 @@ protected function _prepareOrder(\Magento\Quote\Model\Quote\Address $address) $order->setIsVirtual(1); } else { $order->setShippingAddress($this->quoteAddressToOrderAddress->convert($address)); + $order->setShippingMethod($address->getShippingMethod()); } $order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment())); @@ -927,6 +929,8 @@ public function getMinimumAmountDescription() } /** + * Get minimum amount error. + * * @return string */ public function getMinimumAmountError() @@ -1071,7 +1075,7 @@ public function getCustomer() /** * Check if specified address ID belongs to customer. * - * @param $addressId + * @param mixed $addressId * @return bool */ protected function isAddressIdApplicable($addressId) @@ -1084,6 +1088,8 @@ protected function isAddressIdApplicable($addressId) } /** + * Prepare shipping assignment. + * * @param \Magento\Quote\Model\Quote $quote * @return \Magento\Quote\Model\Quote */ @@ -1104,6 +1110,8 @@ private function prepareShippingAssignment($quote) } /** + * Get shipping assignment processor. + * * @return \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor */ private function getShippingAssignmentProcessor() @@ -1186,10 +1194,11 @@ private function searchQuoteAddressId(OrderInterface $order, array $addresses): } /** + * Get quote address errors. + * * @param OrderInterface[] $orders * @param \Magento\Quote\Model\Quote\Address[] $addresses * @param \Exception[] $exceptionList - * * @return string[] * @throws NotFoundException */ diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php index 94c11bef1d311..853d3e3046be6 100644 --- a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php @@ -659,11 +659,13 @@ private function getOrderMock( 'getId', 'getCanSendNewEmailFlag', 'getItems', + 'setShippingMethod', ] )->getMock(); $orderMock->method('setQuote')->with($this->quoteMock); $orderMock->method('setBillingAddress')->with($orderAddressMock)->willReturnSelf(); $orderMock->method('setShippingAddress')->with($orderAddressMock)->willReturnSelf(); + $orderMock->expects($this->once())->method('setShippingMethod')->with('carrier')->willReturnSelf(); $orderMock->method('setPayment')->with($orderPaymentMock)->willReturnSelf(); $orderMock->method('addItem')->with($orderItemMock)->willReturnSelf(); $orderMock->method('getIncrementId')->willReturn('1'); diff --git a/app/code/Magento/NewRelicReporting/Model/Config.php b/app/code/Magento/NewRelicReporting/Model/Config.php index 32e1078c01c9d..4bb381eb2f12d 100644 --- a/app/code/Magento/NewRelicReporting/Model/Config.php +++ b/app/code/Magento/NewRelicReporting/Model/Config.php @@ -5,6 +5,9 @@ */ namespace Magento\NewRelicReporting\Model; +/** + * NewRelic configuration model + */ class Config { /**#@+ @@ -161,6 +164,16 @@ public function getNewRelicAppName() return (string)$this->scopeConfig->getValue('newrelicreporting/general/app_name'); } + /** + * Returns configured separate apps value + * + * @return bool + */ + public function isSeparateApps() + { + return (bool)$this->scopeConfig->getValue('newrelicreporting/general/separate_apps'); + } + /** * Returns config setting for overall cron to be enabled * diff --git a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php index 845ed0429d2c3..ec21e06976b8b 100644 --- a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php +++ b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php @@ -41,6 +41,19 @@ public function reportError($exception) } } + /** + * Wrapper for 'newrelic_set_appname' + * + * @param string $appName + * @return void + */ + public function setAppName(string $appName) + { + if (extension_loaded('newrelic')) { + newrelic_set_appname($appName); + } + } + /** * Checks whether newrelic-php5 agent is installed * diff --git a/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php b/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php new file mode 100644 index 0000000000000..8be29fa6db9d9 --- /dev/null +++ b/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php @@ -0,0 +1,102 @@ +config = $config; + $this->newRelicWrapper = $newRelicWrapper; + $this->logger = $logger; + } + + /** + * Set separate appname + * + * @param State $subject + * @param mixed $result + * @return mixed + */ + public function afterSetAreaCode(State $subject, $result) + { + if (!$this->shouldSetAppName()) { + return $result; + } + + try { + $this->newRelicWrapper->setAppName($this->appName($subject)); + } catch (LocalizedException $e) { + $this->logger->critical($e); + return $result; + } + + return $result; + } + + /** + * Format appName. + * + * @param State $state + * @return string + * @throws LocalizedException + */ + private function appName(State $state): string + { + $code = $state->getAreaCode(); + $current = $this->config->getNewRelicAppName(); + + return $current . ';' . $current . '_' . $code; + } + + /** + * Check if app name should be set. + * + * @return bool + */ + private function shouldSetAppName(): bool + { + return ( + $this->config->isSeparateApps() && + $this->config->getNewRelicAppName() && + $this->config->isNewRelicEnabled() + ); + } +} diff --git a/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml b/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml index 582b7c752386a..98f9c55adbdf0 100644 --- a/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml +++ b/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml @@ -46,6 +46,11 @@ This is located by navigating to Settings from the New Relic APM website + + + Magento\Config\Model\Config\Source\Yesno + In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set. + diff --git a/app/code/Magento/NewRelicReporting/etc/di.xml b/app/code/Magento/NewRelicReporting/etc/di.xml index 2dccc45c1129b..bab7d6611f14b 100644 --- a/app/code/Magento/NewRelicReporting/etc/di.xml +++ b/app/code/Magento/NewRelicReporting/etc/di.xml @@ -30,6 +30,9 @@ + + + diff --git a/app/code/Magento/NewRelicReporting/i18n/en_US.csv b/app/code/Magento/NewRelicReporting/i18n/en_US.csv index 433b1b22fcddd..5ea64d3d43439 100644 --- a/app/code/Magento/NewRelicReporting/i18n/en_US.csv +++ b/app/code/Magento/NewRelicReporting/i18n/en_US.csv @@ -21,3 +21,5 @@ General,General "This is located by navigating to Settings from the New Relic APM website","This is located by navigating to Settings from the New Relic APM website" Cron,Cron "Enable Cron","Enable Cron" +"Send Adminhtml and Frontend as Separate Apps","Send Adminhtml and Frontend as Separate Apps" +"In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set.","In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set." diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Problem/Index.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Problem/Index.php index 7ea3b2cb90951..453a42def61fe 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Problem/Index.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Problem/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Problem; -class Index extends \Magento\Newsletter\Controller\Adminhtml\Problem +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Newsletter\Controller\Adminhtml\Problem implements HttpGetActionInterface { /** * Newsletter problems report page diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Edit.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Edit.php index b012979a11ac9..f99c22a474396 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Edit.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Queue; -class Edit extends \Magento\Newsletter\Controller\Adminhtml\Queue +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Newsletter\Controller\Adminhtml\Queue implements HttpGetActionInterface { /** * Core registry diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Grid.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Grid.php index c992fe6c37701..4f734c09e475e 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Grid.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Grid.php @@ -6,7 +6,11 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Queue; -class Grid extends \Magento\Newsletter\Controller\Adminhtml\Queue +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\Newsletter\Controller\Adminhtml\Queue as QueueAction; + +class Grid extends QueueAction implements HttpPostActionInterface, HttpGetActionInterface { /** * Queue list Ajax action diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Index.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Index.php index 22c7adc5255cc..2d07ffabe3839 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Index.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Index.php @@ -6,7 +6,14 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Queue; -class Index extends \Magento\Newsletter\Controller\Adminhtml\Queue +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Newsletter\Controller\Adminhtml\Queue as QueueAction; + +/** + * Show newsletter queue. Needs to be accessible by POST because of filtering. + */ +class Index extends QueueAction implements HttpGetActionInterface, HttpPostActionInterface { /** * Queue list action diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Save.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Save.php index d3b091976e922..2dbe10bf1bdc9 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Save.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Save.php @@ -7,7 +7,9 @@ namespace Magento\Newsletter\Controller\Adminhtml\Queue; -class Save extends \Magento\Newsletter\Controller\Adminhtml\Queue +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Save extends \Magento\Newsletter\Controller\Adminhtml\Queue implements HttpPostActionInterface { /** * Save Newsletter queue diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Subscriber/Index.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Subscriber/Index.php index a730b8a21a154..09cf1ae7959fb 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Subscriber/Index.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Subscriber/Index.php @@ -6,7 +6,11 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Subscriber; -class Index extends \Magento\Newsletter\Controller\Adminhtml\Subscriber +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Newsletter\Controller\Adminhtml\Subscriber as SubscriberAction; + +class Index extends SubscriberAction implements HttpGetActionInterface, HttpPostActionInterface { /** * Newsletter subscribers page diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Drop.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Drop.php index 52d46065ad05b..2d167d4ccf5f3 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Drop.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Drop.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; -class Drop extends \Magento\Newsletter\Controller\Adminhtml\Template +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Drop extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpPostActionInterface { /** * Drop Newsletter Template diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Edit.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Edit.php index a1126be35af39..e60b865003f44 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Edit.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; -class Edit extends \Magento\Newsletter\Controller\Adminhtml\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpGetActionInterface { /** * Core registry diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Index.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Index.php index 5fcce53c6abbd..12cdb7e262db9 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Index.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; -class Index extends \Magento\Newsletter\Controller\Adminhtml\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpGetActionInterface { /** * View Templates list diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/NewAction.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/NewAction.php index 054e9025a4ffa..c739d6ba26b17 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/NewAction.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; -class NewAction extends \Magento\Newsletter\Controller\Adminhtml\Template +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpGetActionInterface { /** * Create new Newsletter Template diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Preview.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Preview.php index fbce319a75fc1..9fd9f4335b5c5 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Preview.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Preview.php @@ -6,7 +6,12 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; -class Preview extends \Magento\Newsletter\Controller\Adminhtml\Template +use Magento\Framework\App\Action\HttpGetActionInterface; + +/** + * View a rendered template. + */ +class Preview extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpGetActionInterface { /** * Preview Newsletter template diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php index c9db0d62e2e24..8fc729ea34078 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php @@ -6,10 +6,11 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\TemplateTypesInterface; use Magento\Framework\Exception\LocalizedException; -class Save extends \Magento\Newsletter\Controller\Adminhtml\Template +class Save extends \Magento\Newsletter\Controller\Adminhtml\Template implements HttpPostActionInterface { /** * Save Newsletter Template diff --git a/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml b/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml index 7355c06bdd655..279afe2c28e7a 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml +++ b/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml @@ -19,8 +19,7 @@ use Magento\Framework\App\TemplateTypesInterface; getForm() ?> -
- getBlockHtml('formkey') ?> +
diff --git a/app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement/Index.php b/app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement/Index.php index b4c68df6e29e0..ca92b6a044fa7 100644 --- a/app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement/Index.php +++ b/app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement; -class Index extends \Magento\Paypal\Controller\Adminhtml\Billing\Agreement +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Paypal\Controller\Adminhtml\Billing\Agreement implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Paypal/Controller/Adminhtml/Paypal/Reports/Index.php b/app/code/Magento/Paypal/Controller/Adminhtml/Paypal/Reports/Index.php index 91f3e8d9065b9..c2cee0ffbc67a 100644 --- a/app/code/Magento/Paypal/Controller/Adminhtml/Paypal/Reports/Index.php +++ b/app/code/Magento/Paypal/Controller/Adminhtml/Paypal/Reports/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports; -class Index extends \Magento\Paypal\Controller\Adminhtml\Paypal\Reports +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Paypal\Controller\Adminhtml\Paypal\Reports implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Paypal/Controller/Express/GetToken.php b/app/code/Magento/Paypal/Controller/Express/GetToken.php index 7c127803cb0b1..93e9abb4c097e 100644 --- a/app/code/Magento/Paypal/Controller/Express/GetToken.php +++ b/app/code/Magento/Paypal/Controller/Express/GetToken.php @@ -5,6 +5,7 @@ */ namespace Magento\Paypal\Controller\Express; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Checkout\Helper\Data; use Magento\Checkout\Helper\ExpressRedirect; use Magento\Checkout\Model\Type\Onepage; @@ -19,7 +20,7 @@ * Class GetToken * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class GetToken extends AbstractExpress +class GetToken extends AbstractExpress implements HttpGetActionInterface { /** * Config mode type diff --git a/app/code/Magento/Paypal/Controller/Express/Start.php b/app/code/Magento/Paypal/Controller/Express/Start.php index e0a3c5381be59..b381c413071a7 100644 --- a/app/code/Magento/Paypal/Controller/Express/Start.php +++ b/app/code/Magento/Paypal/Controller/Express/Start.php @@ -6,7 +6,9 @@ */ namespace Magento\Paypal\Controller\Express; -class Start extends \Magento\Paypal\Controller\Express\AbstractExpress\Start +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Start extends \Magento\Paypal\Controller\Express\AbstractExpress\Start implements HttpGetActionInterface { /** * Config mode type diff --git a/app/code/Magento/Paypal/Controller/Payflowexpress/Start.php b/app/code/Magento/Paypal/Controller/Payflowexpress/Start.php index a6fbcfd0239b4..4615320c9455f 100644 --- a/app/code/Magento/Paypal/Controller/Payflowexpress/Start.php +++ b/app/code/Magento/Paypal/Controller/Payflowexpress/Start.php @@ -6,7 +6,9 @@ */ namespace Magento\Paypal\Controller\Payflowexpress; -class Start extends \Magento\Paypal\Controller\Express\AbstractExpress\Start +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Start extends \Magento\Paypal\Controller\Express\AbstractExpress\Start implements HttpGetActionInterface { /** * Config mode type diff --git a/app/code/Magento/Paypal/Controller/Transparent/RequestSecureToken.php b/app/code/Magento/Paypal/Controller/Transparent/RequestSecureToken.php index 2efae34a96459..85907c9d371ab 100644 --- a/app/code/Magento/Paypal/Controller/Transparent/RequestSecureToken.php +++ b/app/code/Magento/Paypal/Controller/Transparent/RequestSecureToken.php @@ -5,6 +5,7 @@ */ namespace Magento\Paypal\Controller\Transparent; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\JsonFactory; @@ -21,7 +22,7 @@ * @package Magento\Paypal\Controller\Transparent * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class RequestSecureToken extends \Magento\Framework\App\Action\Action +class RequestSecureToken extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface { /** * @var JsonFactory diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 16bcac300de97..1300c79368943 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -17,7 +17,7 @@ /** * Wrapper that performs Paypal Express and Checkout communication - * Use current Paypal Express method instance + * * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -26,6 +26,7 @@ class Checkout { /** * Cache ID prefix for "pal" lookup + * * @var string */ const PAL_CACHE_ID = 'paypal_express_checkout_pal'; @@ -367,6 +368,7 @@ public function __construct( /** * Checkout with PayPal image URL getter + * * Spares API calls of getting "pal" variable, by putting it into cache per store view * * @return string @@ -599,8 +601,8 @@ public function canSkipOrderReviewStep() /** * Update quote when returned from PayPal - * rewrite billing address by paypal - * save old billing address for new customer + * + * Rewrite billing address by paypal, save old billing address for new customer, and * export shipping address in case address absence * * @param string $token @@ -616,14 +618,15 @@ public function returnFromPaypal($token) $this->ignoreAddressValidation(); + // check if we came from the Express Checkout button + $isButton = (bool)$quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON); + // import shipping address $exportedShippingAddress = $this->_getApi()->getExportedShippingAddress(); if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($shippingAddress) { - if ($exportedShippingAddress - && $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1 - ) { + if ($exportedShippingAddress && $isButton) { $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress); // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix $shippingAddress->setPrefix(null); @@ -651,12 +654,11 @@ public function returnFromPaypal($token) } // import billing address - $portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1 - && $this->_config->getValue( - 'requireBillingAddress' - ) != \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL - && !$quote->isVirtual(); - if ($portBillingFromShipping) { + $requireBillingAddress = (int)$this->_config->getValue( + 'requireBillingAddress' + ) === \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL; + + if ($isButton && !$requireBillingAddress && !$quote->isVirtual()) { $billingAddress = clone $shippingAddress; $billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null); $data = $billingAddress->getData(); @@ -664,11 +666,17 @@ public function returnFromPaypal($token) $quote->getBillingAddress()->addData($data); $quote->getShippingAddress()->setSameAsBilling(1); } else { - $billingAddress = $quote->getBillingAddress(); + $billingAddress = $quote->getBillingAddress()->setCustomerAddressId(null); } $exportedBillingAddress = $this->_getApi()->getExportedBillingAddress(); - $this->_setExportedAddressData($billingAddress, $exportedBillingAddress); + // Since country is required field for billing and shipping address, + // we consider the address information to be empty if country is empty. + $isEmptyAddress = ($billingAddress->getCountryId() === null); + + if ($requireBillingAddress || $isEmptyAddress) { + $this->_setExportedAddressData($billingAddress, $exportedBillingAddress); + } $billingAddress->setCustomerNote($exportedBillingAddress->getData('note')); $quote->setBillingAddress($billingAddress); $quote->setCheckoutMethod($this->getCheckoutMethod()); @@ -904,17 +912,6 @@ public function getCheckoutMethod() */ protected function _setExportedAddressData($address, $exportedAddress) { - // Exported data is more priority if we came from Express Checkout button - $isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON); - - // Since country is required field for billing and shipping address, - // we consider the address information to be empty if country is empty. - $isEmptyAddress = ($address->getCountryId() === null); - - if (!$isButton && !$isEmptyAddress) { - return; - } - foreach ($exportedAddress->getExportedKeys() as $key) { $data = $exportedAddress->getData($key); if (!empty($data)) { @@ -951,6 +948,8 @@ protected function _setBillingAgreementRequest() } /** + * Get api + * * @return \Magento\Paypal\Model\Api\Nvp */ protected function _getApi() @@ -963,8 +962,9 @@ protected function _getApi() /** * Attempt to collect address shipping rates and return them for further usage in instant update API - * Returns empty array if it was impossible to obtain any shipping rate - * If there are shipping rates obtained, the method must return one of them as default. + * + * Returns empty array if it was impossible to obtain any shipping rate and + * if there are shipping rates obtained, the method must return one of them as default. * * @param Address $address * @param bool $mayReturnEmpty @@ -1048,8 +1048,8 @@ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = f * Compare two shipping options based on their amounts * * This function is used as a callback comparison function in shipping options sorting process - * @see self::_prepareShippingOptions() * + * @see self::_prepareShippingOptions() * @param \Magento\Framework\DataObject $option1 * @param \Magento\Framework\DataObject $option2 * @return int @@ -1064,6 +1064,7 @@ protected static function cmpShippingOptions(DataObject $option1, DataObject $op /** * Try to find whether the code provided by PayPal corresponds to any of possible shipping rates + * * This method was created only because PayPal has issues with returning the selected code. * If in future the issue is fixed, we don't need to attempt to match it. It would be enough to set the method code * before collecting shipping rates @@ -1089,6 +1090,7 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode) /** * Create payment redirect url + * * @param bool|null $button * @param string $token * @return void @@ -1112,6 +1114,7 @@ public function getCustomerSession() /** * Set shipping options to api + * * @param \Magento\Paypal\Model\Cart $cart * @param \Magento\Quote\Model\Quote\Address|null $address * @return void diff --git a/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php b/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php index 23721cb4b1658..914b5fa271717 100644 --- a/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php +++ b/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php @@ -6,6 +6,7 @@ namespace Magento\ProductVideo\Controller\Adminhtml\Product\Gallery; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\File\Uploader; @@ -13,7 +14,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class RetrieveImage extends \Magento\Backend\App\Action +class RetrieveImage extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php b/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php index f30d98342beba..37a8fcd494fba 100644 --- a/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php +++ b/app/code/Magento/Quote/Model/MaskedQuoteIdToQuoteId.php @@ -10,6 +10,9 @@ use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource; +/** + * MaskedQuoteId to QuoteId resolver + */ class MaskedQuoteIdToQuoteId implements MaskedQuoteIdToQuoteIdInterface { /** diff --git a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php index 5ddadfc22f57d..2e802f47cfefe 100644 --- a/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php +++ b/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php @@ -8,29 +8,40 @@ namespace Magento\Quote\Model; use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource; +/** + * QuoteId to MaskedQuoteId resolver + */ class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface { /** * @var QuoteIdMaskFactory */ private $quoteIdMaskFactory; - /** * @var CartRepositoryInterface */ private $cartRepository; + /** + * @var QuoteIdMaskResource + */ + private $quoteIdMaskResource; + /** * @param QuoteIdMaskFactory $quoteIdMaskFactory * @param CartRepositoryInterface $cartRepository + * @param QuoteIdMaskResource $quoteIdMaskResource */ public function __construct( QuoteIdMaskFactory $quoteIdMaskFactory, - CartRepositoryInterface $cartRepository + CartRepositoryInterface $cartRepository, + QuoteIdMaskResource $quoteIdMaskResource ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; + $this->quoteIdMaskResource = $quoteIdMaskResource; } /** @@ -42,8 +53,9 @@ public function execute(int $quoteId): string $this->cartRepository->get($quoteId); $quoteIdMask = $this->quoteIdMaskFactory->create(); - $quoteIdMask->setQuoteId($quoteId)->save(); + $this->quoteIdMaskResource->load($quoteIdMask, $quoteId, 'quote_id'); + $maskedId = $quoteIdMask->getMaskedId() ?? ''; - return $quoteIdMask->getMaskedId(); + return $maskedId; } } diff --git a/app/code/Magento/Quote/Model/QuoteValidator.php b/app/code/Magento/Quote/Model/QuoteValidator.php index 04d6d4ecba160..062cf76bcaa1a 100644 --- a/app/code/Magento/Quote/Model/QuoteValidator.php +++ b/app/code/Magento/Quote/Model/QuoteValidator.php @@ -6,14 +6,17 @@ namespace Magento\Quote\Model; -use Magento\Framework\Exception\LocalizedException; -use Magento\Quote\Model\Quote as QuoteEntity; use Magento\Directory\Model\AllowedCountries; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Message\Error; +use Magento\Quote\Model\Quote as QuoteEntity; use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage; use Magento\Quote\Model\ValidationRules\QuoteValidationRuleInterface; /** + * Class to validate the quote + * * @api * @since 100.0.2 */ @@ -72,18 +75,24 @@ public function validateQuoteAmount(QuoteEntity $quote, $amount) $quote->setHasError(true); $quote->addMessage(__('This item price or quantity is not valid for checkout.')); } + return $this; } /** - * Validate quote before submit + * Validates quote before submit. * * @param Quote $quote * @return $this - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function validateBeforeSubmit(QuoteEntity $quote) { + if ($quote->getHasError()) { + $errors = $this->getQuoteErrors($quote); + throw new LocalizedException(__($errors ?: 'Something went wrong. Please try to place the order again.')); + } + foreach ($this->quoteValidationRule->validate($quote) as $validationResult) { if ($validationResult->isValid()) { continue; @@ -101,4 +110,22 @@ public function validateBeforeSubmit(QuoteEntity $quote) return $this; } + + /** + * Parses quote error messages and concatenates them into single string. + * + * @param Quote $quote + * @return string + */ + private function getQuoteErrors(QuoteEntity $quote): string + { + $errors = array_map( + function (Error $error) { + return $error->getText(); + }, + $quote->getErrors() + ); + + return implode(PHP_EOL, $errors); + } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php b/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php new file mode 100644 index 0000000000000..2dec8c278800b --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Authorization/IsCartMutationAllowedForCurrentUser.php @@ -0,0 +1,67 @@ +userContext = $userContext; + $this->cartRepository = $cartRepository; + } + + /** + * Check that the shopping cart operations are allowed for current user + * + * @param int $quoteId + * @return bool + * @throws GraphQlNoSuchEntityException + */ + public function execute(int $quoteId): bool + { + try { + $quote = $this->cartRepository->get($quoteId); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException(__($exception->getMessage())); + } + + $customerId = $quote->getCustomerId(); + + /* Guest cart, allow operations */ + if (!$customerId) { + return true; + } + + /* If the quote belongs to the current customer allow operations */ + return $customerId == $this->userContext->getUserId(); + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php index fcf23dd9f682b..78f9638313293 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php @@ -14,6 +14,7 @@ use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\GuestCartManagementInterface; use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; +use Magento\Quote\Model\QuoteIdMaskFactory; /** * @inheritdoc @@ -24,7 +25,6 @@ class CreateEmptyCart implements ResolverInterface * @var CartManagementInterface */ private $cartManagement; - /** * @var GuestCartManagementInterface */ @@ -40,22 +40,30 @@ class CreateEmptyCart implements ResolverInterface */ private $userContext; + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + /** * @param CartManagementInterface $cartManagement * @param GuestCartManagementInterface $guestCartManagement * @param UserContextInterface $userContext * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId + * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( CartManagementInterface $cartManagement, GuestCartManagementInterface $guestCartManagement, UserContextInterface $userContext, - QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId + QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId, + QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->cartManagement = $cartManagement; $this->guestCartManagement = $guestCartManagement; $this->userContext = $userContext; $this->quoteIdToMaskedId = $quoteIdToMaskedId; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; } /** @@ -67,7 +75,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value if (0 !== $customerId && null !== $customerId) { $quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId); - $maskedQuoteId = $this->quoteIdToMaskedId->execute($quoteId); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quoteId); + + if (empty($maskedQuoteId)) { + $quoteIdMask = $this->quoteIdMaskFactory->create(); + $quoteIdMask->setQuoteId($quoteId)->save(); + $maskedQuoteId = $quoteIdMask->getMaskedId(); + } } else { $maskedQuoteId = $this->guestCartManagement->createEmptyCart(); } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/ApplyCouponToCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/ApplyCouponToCart.php new file mode 100644 index 0000000000000..ab57b8ff499c6 --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/ApplyCouponToCart.php @@ -0,0 +1,110 @@ +couponManagement = $couponManagement; + $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToId; + $this->isCartMutationAllowedForCurrentUser = $isCartMutationAllowedForCurrentUser; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($args['input']['cart_id'])) { + throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); + } + $maskedCartId = $args['input']['cart_id']; + + if (!isset($args['input']['coupon_code'])) { + throw new GraphQlInputException(__('Required parameter "coupon_code" is missing')); + } + $couponCode = $args['input']['coupon_code']; + + try { + $cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException( + __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $maskedCartId]) + ); + } + + if (false === $this->isCartMutationAllowedForCurrentUser->execute($cartId)) { + throw new GraphQlAuthorizationException( + __( + 'The current user cannot perform operations on cart "%masked_cart_id"', + ['masked_cart_id' => $maskedCartId] + ) + ); + } + + /* Check current cart does not have coupon code applied */ + $appliedCouponCode = $this->couponManagement->get($cartId); + if (!empty($appliedCouponCode)) { + throw new GraphQlInputException( + __('A coupon is already applied to the cart. Please remove it to apply another') + ); + } + + try { + $this->couponManagement->set($cartId, $couponCode); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException(__($exception->getMessage())); + } catch (CouldNotSaveException $exception) { + throw new GraphQlInputException(__($exception->getMessage())); + } + + $data['cart']['applied_coupon'] = [ + 'code' => $couponCode, + ]; + return $data; + } +} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/RemoveCouponFromCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/RemoveCouponFromCart.php new file mode 100644 index 0000000000000..abb5a0b57519b --- /dev/null +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Coupon/RemoveCouponFromCart.php @@ -0,0 +1,97 @@ +couponManagement = $couponManagement; + $this->isCartMutationAllowedForCurrentUser = $isCartMutationAllowedForCurrentUser; + $this->maskedQuoteIdToId = $maskedQuoteIdToId; + } + + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($args['input']['cart_id'])) { + throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); + } + $maskedCartId = $args['input']['cart_id']; + + try { + $cartId = $this->maskedQuoteIdToId->execute($maskedCartId); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException( + __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $maskedCartId]) + ); + } + + if (false === $this->isCartMutationAllowedForCurrentUser->execute($cartId)) { + throw new GraphQlAuthorizationException( + __( + 'The current user cannot perform operations on cart "%masked_cart_id"', + ['masked_cart_id' => $maskedCartId] + ) + ); + } + + try { + $this->couponManagement->remove($cartId); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException(__($exception->getMessage())); + } catch (CouldNotDeleteException $exception) { + throw new GraphQlInputException(__($exception->getMessage())); + } + + $data['cart']['applied_coupon'] = [ + 'code' => '', + ]; + return $data; + } +} diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 46d1b97d0aea2..06b3328b9e058 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -3,4 +3,35 @@ type Mutation { createEmptyCart: String @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Cart\\CreateEmptyCart") @doc(description:"Creates empty shopping cart for guest or logged in user") + applyCouponToCart(input: ApplyCouponToCartInput): ApplyCouponToCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Coupon\\ApplyCouponToCart") + removeCouponFromCart(input: RemoveCouponFromCartInput): RemoveCouponFromCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Coupon\\RemoveCouponFromCart") } + +input ApplyCouponToCartInput { + cart_id: String! + coupon_code: String! +} + +type ApplyCouponToCartOutput { + cart: Cart! +} + +type Cart { + applied_coupon: AppliedCoupon +} + +type CartAddress { + applied_coupon: AppliedCoupon +} + +type AppliedCoupon { + code: String! +} + +input RemoveCouponFromCartInput { + cart_id: String! +} + +type RemoveCouponFromCartOutput { + cart: Cart +} \ No newline at end of file diff --git a/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php b/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php index be7dfa70efbb4..2ff87237222f0 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php @@ -3,8 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Reports\Block\Adminhtml\Grid; +/** + * Backend reports grid + */ class AbstractGrid extends \Magento\Backend\Block\Widget\Grid\Extended { /** @@ -90,9 +94,8 @@ protected function _construct() /** * Get resource collection name * - * @codeCoverageIgnore - * * @return string + * @codeCoverageIgnore */ public function getResourceCollectionName() { @@ -100,6 +103,8 @@ public function getResourceCollectionName() } /** + * Return reports collection + * * @return \Magento\Framework\Data\Collection */ public function getCollection() @@ -111,6 +116,8 @@ public function getCollection() } /** + * Retrieve array of columns that should be aggregated + * * @return array */ protected function _getAggregatedColumns() @@ -170,12 +177,7 @@ public function addColumn($columnId, $column) */ protected function _getStoreIds() { - $filterData = $this->getFilterData(); - if ($filterData) { - $storeIds = explode(',', $filterData->getData('store_ids')); - } else { - $storeIds = []; - } + $storeIds = $this->getFilteredStores(); // By default storeIds array contains only allowed stores $allowedStoreIds = array_keys($this->_storeManager->getStores()); // And then array_intersect with post data for prevent unauthorized stores reports @@ -191,6 +193,8 @@ protected function _getStoreIds() } /** + * Apply sorting and filtering to collection + * * @return $this|\Magento\Backend\Block\Widget\Grid * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) @@ -280,6 +284,8 @@ protected function _prepareCollection() } /** + * Return count totals + * * @return array */ public function getCountTotals() @@ -319,6 +325,8 @@ public function getCountTotals() } /** + * Retrieve subtotal items + * * @return array */ public function getSubTotals() @@ -360,6 +368,8 @@ public function setStoreIds($storeIds) } /** + * Return current currency code + * * @return string|\Magento\Directory\Model\Currency $currencyCode */ public function getCurrentCurrencyCode() @@ -399,6 +409,7 @@ protected function _addOrderStatusFilter($collection, $filterData) /** * Adds custom filter to resource collection + * * Can be overridden in child classes if custom filter needed * * @param \Magento\Reports\Model\ResourceModel\Report\Collection\AbstractCollection $collection @@ -411,4 +422,35 @@ protected function _addCustomFilter($collection, $filterData) { return $this; } + + /** + * Return stores by website, group and store id + * + * @return array + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function getFilteredStores(): array + { + $storeIds = []; + + $filterData = $this->getFilterData(); + if ($filterData) { + if ($filterData->getWebsite()) { + $storeIds = array_keys( + $this->_storeManager->getWebsite($filterData->getWebsite())->getStores() + ); + } + + if ($filterData->getGroup()) { + $storeIds = array_keys( + $this->_storeManager->getGroup($filterData->getGroup())->getStores() + ); + } + + if ($filterData->getData('store_ids')) { + $storeIds = explode(',', $filterData->getData('store_ids')); + } + } + return is_array($storeIds) ? $storeIds : []; + } } diff --git a/app/code/Magento/Reports/Block/Adminhtml/Sales/Sales/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Sales/Sales/Grid.php index 21836f1a8c276..9f5f784df677f 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Sales/Sales/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Sales/Sales/Grid.php @@ -6,6 +6,8 @@ namespace Magento\Reports\Block\Adminhtml\Sales\Sales; +use Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency; + /** * Adminhtml sales report grid block * @@ -22,7 +24,8 @@ class Grid extends \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid protected $_columnGroupBy = 'period'; /** - * {@inheritdoc} + * Reports grid constructor + * * @codeCoverageIgnore */ protected function _construct() @@ -32,17 +35,19 @@ protected function _construct() } /** - * {@inheritdoc} + * Return collection name based on report_type + * + * @return string */ public function getResourceCollectionName() { - return $this->getFilterData()->getData('report_type') == 'updated_at_order' + return $this->getFilterData()->getData('report_type') === 'updated_at_order' ? \Magento\Sales\Model\ResourceModel\Report\Order\Updatedat\Collection::class : \Magento\Sales\Model\ResourceModel\Report\Order\Collection::class; } /** - * {@inheritdoc} + * Initialize reports grid columns * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -103,9 +108,7 @@ protected function _prepareColumns() ] ); - if ($this->getFilterData()->getStoreIds()) { - $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds())); - } + $this->setStoreIds($this->_getStoreIds()); $currencyCode = $this->getCurrentCurrencyCode(); $rate = $this->getRate($currencyCode); @@ -118,6 +121,7 @@ protected function _prepareColumns() 'index' => 'total_income_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-sales-total', 'column_css_class' => 'col-sales-total' @@ -133,6 +137,7 @@ protected function _prepareColumns() 'index' => 'total_revenue_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-revenue', @@ -149,6 +154,7 @@ protected function _prepareColumns() 'index' => 'total_profit_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-profit', @@ -165,6 +171,7 @@ protected function _prepareColumns() 'index' => 'total_invoiced_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-invoiced', 'column_css_class' => 'col-invoiced' @@ -180,6 +187,7 @@ protected function _prepareColumns() 'index' => 'total_paid_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-paid', @@ -196,6 +204,7 @@ protected function _prepareColumns() 'index' => 'total_refunded_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-refunded', 'column_css_class' => 'col-refunded' @@ -211,6 +220,7 @@ protected function _prepareColumns() 'index' => 'total_tax_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-sales-tax', 'column_css_class' => 'col-sales-tax' @@ -226,6 +236,7 @@ protected function _prepareColumns() 'index' => 'total_tax_amount_actual', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-tax', @@ -242,6 +253,7 @@ protected function _prepareColumns() 'index' => 'total_shipping_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-sales-shipping', 'column_css_class' => 'col-sales-shipping' @@ -257,6 +269,7 @@ protected function _prepareColumns() 'index' => 'total_shipping_amount_actual', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-shipping', @@ -273,6 +286,7 @@ protected function _prepareColumns() 'index' => 'total_discount_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-sales-discount', 'column_css_class' => 'col-sales-discount' @@ -288,6 +302,7 @@ protected function _prepareColumns() 'index' => 'total_discount_amount_actual', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'visibility_filter' => ['show_actual_columns'], 'rate' => $rate, 'header_css_class' => 'col-discount', @@ -304,6 +319,7 @@ protected function _prepareColumns() 'index' => 'total_canceled_amount', 'total' => 'sum', 'sortable' => false, + 'renderer' => Currency::class, 'rate' => $rate, 'header_css_class' => 'col-canceled', 'column_css_class' => 'col-canceled' diff --git a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php index f81176b7a1124..5a92b6ab4e79c 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php @@ -37,6 +37,8 @@ public function __construct( } /** + * Grid constructor + * * @return void */ protected function _construct() @@ -46,6 +48,8 @@ protected function _construct() } /** + * Prepare collection + * * @return \Magento\Backend\Block\Widget\Grid */ protected function _prepareCollection() @@ -67,11 +71,16 @@ protected function _prepareCollection() $this->setCollection($collection); parent::_prepareCollection(); + if ($this->_isExport) { + $collection->setPageSize(null); + } $this->getCollection()->resolveCustomerNames(); return $this; } /** + * Add column filter to collection + * * @param array $column * * @return $this @@ -90,6 +99,8 @@ protected function _addColumnFilterToCollection($column) } /** + * Prepare columns + * * @return \Magento\Backend\Block\Widget\Grid\Extended * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -223,6 +234,8 @@ protected function _prepareColumns() } /** + * Get rows url + * * @param \Magento\Framework\DataObject $row * * @return string diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php index 3dbced45e0a69..2fbff13a5b644 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php @@ -9,13 +9,18 @@ * * @author Magento Core Team */ + namespace Magento\Reports\Controller\Adminhtml\Report; +use Magento\Backend\Helper\Data as BackendHelper; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; /** + * Reports api controller + * * @api * @since 100.0.2 + * @SuppressWarnings(PHPMD.AllPurposeAction) */ abstract class AbstractReport extends \Magento\Backend\App\Action { @@ -41,22 +46,30 @@ abstract class AbstractReport extends \Magento\Backend\App\Action */ protected $timezone; + /** + * @var BackendHelper + */ + private $backendHelper; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter * @param TimezoneInterface $timezone + * @param BackendHelper|null $backendHelperData */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, - TimezoneInterface $timezone + TimezoneInterface $timezone, + BackendHelper $backendHelperData = null ) { parent::__construct($context); $this->_fileFactory = $fileFactory; $this->_dateFilter = $dateFilter; $this->timezone = $timezone; + $this->backendHelper = $backendHelperData ?: $this->_objectManager->get(BackendHelper::class); } /** @@ -103,25 +116,7 @@ public function _initReportAction($blocks) $blocks = [$blocks]; } - $requestData = $this->_objectManager->get( - \Magento\Backend\Helper\Data::class - )->prepareFilterString( - $this->getRequest()->getParam('filter') - ); - $inputFilter = new \Zend_Filter_Input( - ['from' => $this->_dateFilter, 'to' => $this->_dateFilter], - [], - $requestData - ); - $requestData = $inputFilter->getUnescaped(); - $requestData['store_ids'] = $this->getRequest()->getParam('store_ids'); - $params = new \Magento\Framework\DataObject(); - - foreach ($requestData as $key => $value) { - if (!empty($value)) { - $params->setData($key, $value); - } - } + $params = $this->initFilterData(); foreach ($blocks as $block) { if ($block) { @@ -147,7 +142,7 @@ protected function _showLastExecutionTime($flagCode, $refreshCode) ->loadSelf(); $updatedAt = 'undefined'; if ($flag->hasData()) { - $updatedAt = $this->timezone->formatDate( + $updatedAt = $this->timezone->formatDate( $flag->getLastUpdate(), \IntlDateFormatter::MEDIUM, true @@ -155,17 +150,51 @@ protected function _showLastExecutionTime($flagCode, $refreshCode) } $refreshStatsLink = $this->getUrl('reports/report_statistics'); - $directRefreshLink = $this->getUrl('reports/report_statistics/refreshRecent', ['code' => $refreshCode]); + $directRefreshLink = $this->getUrl('reports/report_statistics/refreshRecent'); $this->messageManager->addNotice( __( 'Last updated: %1. To refresh last day\'s statistics, ' . - 'click here.', + 'click here.', $updatedAt, $refreshStatsLink, - $directRefreshLink + str_replace( + '"', + '"', + json_encode(['action' => $directRefreshLink, 'data' => ['code' => $refreshCode]]) + ) ) ); return $this; } + + /** + * Init filter data + * + * @return \Magento\Framework\DataObject + */ + private function initFilterData(): \Magento\Framework\DataObject + { + $requestData = $this->backendHelper + ->prepareFilterString( + $this->getRequest()->getParam('filter') + ); + + $filterRules = ['from' => $this->_dateFilter, 'to' => $this->_dateFilter]; + $inputFilter = new \Zend_Filter_Input($filterRules, [], $requestData); + + $requestData = $inputFilter->getUnescaped(); + $requestData['store_ids'] = $this->getRequest()->getParam('store_ids'); + $requestData['group'] = $this->getRequest()->getParam('group'); + $requestData['website'] = $this->getRequest()->getParam('website'); + + $params = new \Magento\Framework\DataObject(); + + foreach ($requestData as $key => $value) { + if (!empty($value)) { + $params->setData($key, $value); + } + } + return $params; + } } diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Accounts.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Accounts.php index ae1c0401add56..f8d0cbe9e6909 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Accounts.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Accounts.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Customer; -class Accounts extends \Magento\Reports\Controller\Adminhtml\Report\Customer +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Accounts extends \Magento\Reports\Controller\Adminhtml\Report\Customer implements HttpGetActionInterface { /** * New accounts action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Orders.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Orders.php index 56a594ac24ea2..be46fb6a94c76 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Orders.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Orders.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Customer; -class Orders extends \Magento\Reports\Controller\Adminhtml\Report\Customer +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Orders extends \Magento\Reports\Controller\Adminhtml\Report\Customer implements HttpGetActionInterface { /** * Customers by number of orders action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Totals.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Totals.php index 17928872eba97..02f40e5be9807 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Totals.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Customer/Totals.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Customer; -class Totals extends \Magento\Reports\Controller\Adminhtml\Report\Customer +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Totals extends \Magento\Reports\Controller\Adminhtml\Report\Customer implements HttpGetActionInterface { /** * Customers by orders total action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Downloads.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Downloads.php index e8df3118caa2f..f2c03d0dc22a5 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Downloads.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Downloads.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Product; -class Downloads extends \Magento\Reports\Controller\Adminhtml\Report\Product +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Downloads extends \Magento\Reports\Controller\Adminhtml\Report\Product implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Lowstock.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Lowstock.php index b5e3602383f7a..266d6a853414d 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Lowstock.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Lowstock.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Product; -class Lowstock extends \Magento\Reports\Controller\Adminhtml\Report\Product +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Lowstock extends \Magento\Reports\Controller\Adminhtml\Report\Product implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Sold.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Sold.php index 19b8258beaa5b..f01c46f4c142d 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Sold.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Sold.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Product; -class Sold extends \Magento\Reports\Controller\Adminhtml\Report\Product +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Sold extends \Magento\Reports\Controller\Adminhtml\Report\Product implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Viewed.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Viewed.php index 07beec5a72738..980540fb1fa0f 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Viewed.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Product/Viewed.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Viewed extends \Magento\Reports\Controller\Adminhtml\Report\Product +class Viewed extends \Magento\Reports\Controller\Adminhtml\Report\Product implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Customer.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Customer.php index 50b1f79abd4f0..481522b86f0dd 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Customer.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Customer.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Review; -class Customer extends \Magento\Reports\Controller\Adminhtml\Report\Review +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Customer extends \Magento\Reports\Controller\Adminhtml\Report\Review implements HttpGetActionInterface { /** * Customer Reviews Report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Product.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Product.php index 3d0ebc5f56828..911a313377ca9 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Product.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Review/Product.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Review; -class Product extends \Magento\Reports\Controller\Adminhtml\Report\Review +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Product extends \Magento\Reports\Controller\Adminhtml\Report\Review implements HttpGetActionInterface { /** * Product reviews report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Bestsellers.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Bestsellers.php index 60f8cc87f2ab4..eff3796b6d472 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Bestsellers.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Bestsellers.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Bestsellers extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Bestsellers extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Bestsellers report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Coupons.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Coupons.php index 2e324bceee3c8..d9e83cd77b991 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Coupons.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Coupons.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Coupons extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Coupons extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Coupons report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Invoiced.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Invoiced.php index f533d597990fc..c26b0f931e6b7 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Invoiced.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Invoiced.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Invoiced extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Invoiced extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Invoice report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Refunded.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Refunded.php index 85c5fdaed4279..f88e9f64b971a 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Refunded.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Refunded.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Refunded extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Refunded extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Refunds report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Sales.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Sales.php index d6460864c5c1b..e3f383ab5a743 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Sales.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Sales.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Sales extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Sales extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Sales report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Tax.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Tax.php index e8ae11088f5a7..2e6ba487f3981 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Tax.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Sales/Tax.php @@ -6,9 +6,10 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Sales; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Model\Flag; -class Tax extends \Magento\Reports\Controller\Adminhtml\Report\Sales +class Tax extends \Magento\Reports\Controller\Adminhtml\Report\Sales implements HttpGetActionInterface { /** * Tax report action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Abandoned.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Abandoned.php index e03f2f6556010..3f0567c05a93d 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Abandoned.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Abandoned.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Shopcart; -class Abandoned extends \Magento\Reports\Controller\Adminhtml\Report\Shopcart +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Abandoned extends \Magento\Reports\Controller\Adminhtml\Report\Shopcart implements HttpGetActionInterface { /** * Abandoned carts action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Product.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Product.php index 65db66f2d2e0c..b41c901fe8576 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Product.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Shopcart/Product.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Shopcart; -class Product extends \Magento\Reports\Controller\Adminhtml\Report\Shopcart +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Product extends \Magento\Reports\Controller\Adminhtml\Report\Shopcart implements HttpGetActionInterface { /** * Products in carts action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/Index.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/Index.php index d9f9de39657d1..61ec31337db58 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/Index.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Statistics; -class Index extends \Magento\Reports\Controller\Adminhtml\Report\Statistics +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Reports\Controller\Adminhtml\Report\Statistics implements HttpGetActionInterface { /** * Refresh statistics action diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php index 1f0f6e8e40535..66123938243d9 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php @@ -6,7 +6,12 @@ */ namespace Magento\Reports\Controller\Adminhtml\Report\Statistics; -class RefreshRecent extends \Magento\Reports\Controller\Adminhtml\Report\Statistics +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +/** + * Refresh recent stats. + */ +class RefreshRecent extends \Magento\Reports\Controller\Adminhtml\Report\Statistics implements HttpPostActionInterface { /** * Refresh statistics for last 25 hours diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php index a39b22ec080c6..7d922f30cd98b 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Framework\Controller\ResultFactory; -class Edit extends ProductController +class Edit extends ProductController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php index 0dce5b238838d..94c80f89f8d8c 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Framework\Controller\ResultFactory; -class Index extends ProductController +class Index extends ProductController implements HttpGetActionInterface { /** * @return \Magento\Framework\Controller\ResultInterface diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php b/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php index c6e9cc81d5814..bfd4b5e747043 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php @@ -5,6 +5,7 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; @@ -14,7 +15,7 @@ use Magento\Framework\DataObject; use Magento\Framework\Controller\ResultFactory; -class JsonProductInfo extends ProductController +class JsonProductInfo extends ProductController implements HttpGetActionInterface { /** * @var \Magento\Catalog\Api\ProductRepositoryInterface diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php b/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php index 5ac3a6a057246..2709b5ce64b37 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Framework\Controller\ResultFactory; -class NewAction extends ProductController +class NewAction extends ProductController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php index 1f21a52077bb7..b62fcc7326eec 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php @@ -5,12 +5,13 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Framework\Controller\ResultFactory; use Magento\Store\Model\Store; use Magento\Framework\Exception\LocalizedException; -class Post extends ProductController +class Post extends ProductController implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php b/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php index f1b25c3613d49..e4057be14af2f 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php @@ -5,6 +5,8 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; @@ -13,7 +15,7 @@ use Magento\Framework\View\LayoutFactory; use Magento\Framework\Controller\ResultFactory; -class ProductGrid extends ProductController +class ProductGrid extends ProductController implements HttpPostActionInterface, HttpGetActionInterface { /** * @var \Magento\Framework\View\LayoutFactory diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php b/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php index 5b0ab217e7191..1da8e4abbd6b0 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php @@ -5,6 +5,8 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; @@ -13,7 +15,7 @@ use Magento\Framework\View\LayoutFactory; use Magento\Framework\Controller\ResultFactory; -class RatingItems extends ProductController +class RatingItems extends ProductController implements HttpPostActionInterface, HttpGetActionInterface { /** * @var \Magento\Framework\View\LayoutFactory diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php index 7159b1825dc4d..35187e46933bc 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php @@ -5,11 +5,12 @@ */ namespace Magento\Review\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Product as ProductController; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; -class Save extends ProductController +class Save extends ProductController implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php index 5535c3de26e43..b25db6e498fe0 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Rating; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Rating as RatingController; use Magento\Framework\Controller\ResultFactory; -class Delete extends RatingController +class Delete extends RatingController implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php index 1b65966b77054..90dac026cfd64 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Rating; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Rating as RatingController; use Magento\Framework\Controller\ResultFactory; -class Edit extends RatingController +class Edit extends RatingController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php index b719a29950570..ff9ab4d50eac4 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Rating; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Rating as RatingController; use Magento\Framework\Controller\ResultFactory; -class Index extends RatingController +class Index extends RatingController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php index 18ff73ad31c5e..92d20aeec3eb7 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Rating; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Review\Controller\Adminhtml\Rating as RatingController; use Magento\Framework\Controller\ResultFactory; -class NewAction extends RatingController +class NewAction extends RatingController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Forward diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php index 62cca9c824e54..5dd464f7eb611 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php @@ -5,10 +5,11 @@ */ namespace Magento\Review\Controller\Adminhtml\Rating; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Adminhtml\Rating as RatingController; use Magento\Framework\Controller\ResultFactory; -class Save extends RatingController +class Save extends RatingController implements HttpPostActionInterface { /** * Save rating diff --git a/app/code/Magento/Review/Controller/Product/ListAjax.php b/app/code/Magento/Review/Controller/Product/ListAjax.php index a309b5f0626a4..d923814c7dce5 100644 --- a/app/code/Magento/Review/Controller/Product/ListAjax.php +++ b/app/code/Magento/Review/Controller/Product/ListAjax.php @@ -11,8 +11,9 @@ use Magento\Framework\View\Result\Layout; use Magento\Review\Controller\Product as ProductController; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; -class ListAjax extends ProductController +class ListAjax extends ProductController implements HttpGetActionInterface { /** * Show list of product's reviews diff --git a/app/code/Magento/Review/Controller/Product/Post.php b/app/code/Magento/Review/Controller/Product/Post.php index be18f8fe25bbe..32838eb6acbbb 100644 --- a/app/code/Magento/Review/Controller/Product/Post.php +++ b/app/code/Magento/Review/Controller/Product/Post.php @@ -5,11 +5,12 @@ */ namespace Magento\Review\Controller\Product; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Review\Controller\Product as ProductController; use Magento\Framework\Controller\ResultFactory; use Magento\Review\Model\Review; -class Post extends ProductController +class Post extends ProductController implements HttpPostActionInterface { /** * Submit new review action diff --git a/app/code/Magento/Robots/Block/Data.php b/app/code/Magento/Robots/Block/Data.php index 0e492eb73732d..460225d3ed71c 100644 --- a/app/code/Magento/Robots/Block/Data.php +++ b/app/code/Magento/Robots/Block/Data.php @@ -11,9 +11,11 @@ use Magento\Robots\Model\Config\Value; use Magento\Robots\Model\Robots; use Magento\Store\Model\StoreResolver; +use Magento\Store\Model\StoreManagerInterface; /** * Robots Block Class. + * * Prepares base content for robots.txt and implements Page Cache functionality. * * @api @@ -27,24 +29,29 @@ class Data extends AbstractBlock implements IdentityInterface private $robots; /** - * @var StoreResolver + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @param Context $context * @param Robots $robots * @param StoreResolver $storeResolver + * @param StoreManagerInterface|null $storeManager * @param array $data + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( Context $context, Robots $robots, StoreResolver $storeResolver, + StoreManagerInterface $storeManager = null, array $data = [] ) { $this->robots = $robots; - $this->storeResolver = $storeResolver; + $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(StoreManagerInterface::class); parent::__construct($context, $data); } @@ -69,7 +76,7 @@ protected function _toHtml() public function getIdentities() { return [ - Value::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(), + Value::CACHE_TAG . '_' . $this->storeManager->getStore()->getId(), ]; } } diff --git a/app/code/Magento/Robots/Model/Config/Value.php b/app/code/Magento/Robots/Model/Config/Value.php index 83c21d6602fca..c4e17e55f1262 100644 --- a/app/code/Magento/Robots/Model/Config/Value.php +++ b/app/code/Magento/Robots/Model/Config/Value.php @@ -14,9 +14,11 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; use Magento\Store\Model\StoreResolver; +use Magento\Store\Model\StoreManagerInterface; /** * Backend model for design/search_engine_robots/custom_instructions configuration value. + * * Required to implement Page Cache functionality. * * @api @@ -38,9 +40,9 @@ class Value extends ConfigValue implements IdentityInterface protected $_cacheTag = true; /** - * @var StoreResolver + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @param Context $context @@ -48,9 +50,12 @@ class Value extends ConfigValue implements IdentityInterface * @param ScopeConfigInterface $config * @param TypeListInterface $cacheTypeList * @param StoreResolver $storeResolver + * @param StoreManagerInterface|null $storeManager * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( Context $context, @@ -58,11 +63,13 @@ public function __construct( ScopeConfigInterface $config, TypeListInterface $cacheTypeList, StoreResolver $storeResolver, + StoreManagerInterface $storeManager = null, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] ) { - $this->storeResolver = $storeResolver; + $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(StoreManagerInterface::class); parent::__construct( $context, @@ -84,7 +91,7 @@ public function __construct( public function getIdentities() { return [ - self::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(), + self::CACHE_TAG . '_' . $this->storeManager->getStore()->getId(), ]; } } diff --git a/app/code/Magento/Robots/Test/Unit/Block/DataTest.php b/app/code/Magento/Robots/Test/Unit/Block/DataTest.php index 10d2595832a48..95aa97fc8f677 100644 --- a/app/code/Magento/Robots/Test/Unit/Block/DataTest.php +++ b/app/code/Magento/Robots/Test/Unit/Block/DataTest.php @@ -27,6 +27,11 @@ class DataTest extends \PHPUnit\Framework\TestCase */ private $storeResolver; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeManager; + /** * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -65,10 +70,14 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->block = new \Magento\Robots\Block\Data( $this->context, $this->robots, - $this->storeResolver + $this->storeResolver, + $this->storeManager ); } @@ -97,8 +106,14 @@ public function testGetIdentities() { $storeId = 1; - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') + $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock(); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->willReturn($storeMock); + + $storeMock->expects($this->once()) + ->method('getId') ->willReturn($storeId); $expected = [ diff --git a/app/code/Magento/Robots/Test/Unit/Model/Config/ValueTest.php b/app/code/Magento/Robots/Test/Unit/Model/Config/ValueTest.php index fc0c55ccef147..44e843e7de936 100644 --- a/app/code/Magento/Robots/Test/Unit/Model/Config/ValueTest.php +++ b/app/code/Magento/Robots/Test/Unit/Model/Config/ValueTest.php @@ -37,6 +37,11 @@ class ValueTest extends \PHPUnit\Framework\TestCase */ private $storeResolver; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeManager; + protected function setUp() { $this->context = $this->getMockBuilder(\Magento\Framework\Model\Context::class) @@ -57,12 +62,16 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->model = new \Magento\Robots\Model\Config\Value( $this->context, $this->registry, $this->scopeConfig, $this->typeList, - $this->storeResolver + $this->storeResolver, + $this->storeManager ); } @@ -73,8 +82,14 @@ public function testGetIdentities() { $storeId = 1; - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') + $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMockForAbstractClass(); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->willReturn($storeMock); + + $storeMock->expects($this->once()) + ->method('getId') ->willReturn($storeId); $expected = [ diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/Unassign.php b/app/code/Magento/Sales/Block/Status/Grid/Column/Unassign.php index b413951d9d4f3..f989deb0ae7c0 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/Unassign.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/Unassign.php @@ -5,12 +5,35 @@ */ namespace Magento\Sales\Block\Status\Grid\Column; +use Magento\Framework\App\ObjectManager; +use \Magento\Backend\Block\Template\Context; +use Magento\Framework\Serialize\Serializer\Json; + /** * @api * @since 100.0.2 */ class Unassign extends \Magento\Backend\Block\Widget\Grid\Column { + /** + * @var Json + */ + private $json; + + /** + * @inheritDoc + * + * @param Json|null $json + */ + public function __construct( + Context $context, + array $data = [], + ?Json $json = null + ) { + parent::__construct($context, $data); + $this->json = $json ?? ObjectManager::getInstance()->get(Json::class); + } + /** * Add decorated action to column * @@ -36,9 +59,16 @@ public function decorateAction($value, $row, $column, $isExport) $cell = ''; $state = $row->getState(); if (!empty($state)) { - $url = $this->getUrl('*/*/unassign', ['status' => $row->getStatus(), 'state' => $row->getState()]); + $url = $this->getUrl('*/*/unassign'); $label = __('Unassign'); - $cell = '' . $label . ''; + $cell = '' . $label . ''; } return $cell; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Index.php index b29c1ea3700ee..165c9e894de78 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Index.php @@ -5,7 +5,10 @@ */ namespace Magento\Sales\Controller\Adminhtml\Creditmemo; -class Index extends \Magento\Sales\Controller\Adminhtml\Creditmemo\AbstractCreditmemo\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; +use Magento\Sales\Controller\Adminhtml\Creditmemo\AbstractCreditmemo\Index as AbstractIndex; + +class Index extends AbstractIndex implements HttpGetActionInterface { /** * Index page diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/Index.php index 429a388d9392f..bc53f752801ba 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/Index.php @@ -6,6 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Invoice; -class Index extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\Index implements HttpGetActionInterface { } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/View.php index 62add99ab5976..3b52199943230 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/View.php @@ -6,6 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Invoice; -class View extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class View extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View implements HttpGetActionInterface { } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php index 7e41c7417b38d..f96d221a7d3b3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; -class Cancel extends \Magento\Sales\Controller\Adminhtml\Order +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Cancel extends \Magento\Sales\Controller\Adminhtml\Order implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index 8496c4f28d8bc..4acef74b810da 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -6,16 +6,20 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Sales\Api\OrderManagementInterface; use Magento\Sales\Api\OrderRepositoryInterface; use Psr\Log\LoggerInterface; +use Magento\Sales\Controller\Adminhtml\Order as OrderAction; /** - * Class CommentsHistory + * Comments History tab, needs to be accessible by POST becuase of tabs mechanism. + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order +class CommentsHistory extends OrderAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var \Magento\Framework\View\LayoutFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php index ce3a36729de95..035dc7877897d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php @@ -5,7 +5,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Create; -class Index extends \Magento\Sales\Controller\Adminhtml\Order\Create +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Sales\Controller\Adminhtml\Order\Create implements HttpGetActionInterface { /** * Index page diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php index bc4eb3cfba423..1e13e282cae3a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php @@ -5,12 +5,15 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Create; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Backend\Model\View\Result\ForwardFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\RawFactory; +use Magento\Sales\Controller\Adminhtml\Order\Create as CreateAction; -class LoadBlock extends \Magento\Sales\Controller\Adminhtml\Order\Create +class LoadBlock extends CreateAction implements HttpPostActionInterface, HttpGetActionInterface { /** * @var RawFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php index 929e23075e070..4348984d0403b 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php @@ -6,9 +6,10 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Create; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\PaymentException; -class Save extends \Magento\Sales\Controller\Adminhtml\Order\Create +class Save extends \Magento\Sales\Controller\Adminhtml\Order\Create implements HttpPostActionInterface { /** * Saving quote and create order diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php index 01119c3aa88a1..24aedf56ec5a1 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php @@ -5,12 +5,13 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Create; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Backend\Model\View\Result\ForwardFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\RawFactory; -class ShowUpdateResult extends \Magento\Sales\Controller\Adminhtml\Order\Create +class ShowUpdateResult extends \Magento\Sales\Controller\Adminhtml\Order\Create implements HttpGetActionInterface { /** * @var RawFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php index ee88b3361cc83..bc75bc4a5787f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php @@ -5,9 +5,10 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Create; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; -class Start extends \Magento\Sales\Controller\Adminhtml\Order\Create +class Start extends \Magento\Sales\Controller\Adminhtml\Order\Create implements HttpGetActionInterface { /** * Start order create action diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewAction.php index 03910f2ecccfe..3ac3abda82cd1 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewAction.php @@ -5,9 +5,10 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; -class NewAction extends \Magento\Backend\App\Action +class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php index 2a2445d2b2ae0..91ae3b7d4e058 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php @@ -5,11 +5,12 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender; -class Save extends \Magento\Backend\App\Action +class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php index 10ba7e425b651..3dc4aa6dcd500 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php @@ -5,7 +5,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; -class Start extends \Magento\Backend\App\Action +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Start extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php index bfd95666e7c48..d49fa8b8dc608 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php @@ -5,9 +5,10 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; -class UpdateQty extends \Magento\Backend\App\Action +class UpdateQty extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php index 13a86befec0a5..d5dc11719237c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php @@ -5,7 +5,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; -class Index extends \Magento\Sales\Controller\Adminhtml\Order +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Sales\Controller\Adminhtml\Order implements HttpGetActionInterface { /** * Orders grid diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php index 2d7826807a6c3..3295b244f323e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php @@ -7,12 +7,13 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Framework\Registry; use Magento\Framework\View\Result\PageFactory; use Magento\Sales\Model\Service\InvoiceService; -class NewAction extends \Magento\Backend\App\Action +class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php index 71338c818c418..ab74a64b6fcf3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; @@ -19,7 +20,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Backend\App\Action +class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php index ca97ee3b3349b..4648656a3253f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; -class Start extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Start extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View implements HttpGetActionInterface { /** * Start create invoice action diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php index 78fb4aff3f275..c94afa3cc8057 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php @@ -7,20 +7,21 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\LocalizedException; -use Magento\Backend\App\Action; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\RawFactory; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; use Magento\Sales\Model\Service\InvoiceService; +use Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View as AbstractView; /** * Class UpdateQty * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class UpdateQty extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View +class UpdateQty extends AbstractView implements HttpPostActionInterface { /** * @var JsonFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php index 78a413d5636e8..da700aae2f78a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php @@ -6,11 +6,12 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\View\Result\PageFactory; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; -class View extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View +class View extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View implements HttpGetActionInterface { /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php index 32cf6dbfc7c35..deb20a989a260 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -5,13 +5,14 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Backend\App\Action\Context; use Magento\Ui\Component\MassAction\Filter; use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; use Magento\Sales\Api\OrderManagementInterface; -class MassCancel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction +class MassCancel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php index 982ee53cb0ff2..211ded865b4e4 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php @@ -6,11 +6,12 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Registry; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class Assign extends \Magento\Sales\Controller\Adminhtml\Order\Status +class Assign extends \Magento\Sales\Controller\Adminhtml\Order\Status implements HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php index 3b98d206d5f66..28a8e1cb02a14 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -class AssignPost extends \Magento\Sales\Controller\Adminhtml\Order\Status +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class AssignPost extends \Magento\Sales\Controller\Adminhtml\Order\Status implements HttpPostActionInterface { /** * Save status assignment to state diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php index 110402ee27070..3755dca9da950 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php @@ -6,11 +6,12 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Registry; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class Index extends \Magento\Sales\Controller\Adminhtml\Order\Status +class Index extends \Magento\Sales\Controller\Adminhtml\Order\Status implements HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php index bd0ad771815b1..4645588a7522c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php @@ -6,25 +6,32 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -class Save extends \Magento\Sales\Controller\Adminhtml\Order\Status +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\Framework\Filter\FilterManager; +use Magento\Sales\Model\Order\Status; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Sales\Controller\Adminhtml\Order\Status as StatusAction; + +class Save extends StatusAction implements HttpPostActionInterface { /** * Save status form processing * - * @return \Magento\Backend\Model\View\Result\Redirect + * @return Redirect */ public function execute() { $data = $this->getRequest()->getPostValue(); $isNew = $this->getRequest()->getParam('is_new'); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $statusCode = $this->getRequest()->getParam('status'); //filter tags in labels/status - /** @var $filterManager \Magento\Framework\Filter\FilterManager */ - $filterManager = $this->_objectManager->get(\Magento\Framework\Filter\FilterManager::class); + /** @var $filterManager FilterManager */ + $filterManager = $this->_objectManager->get(FilterManager::class); if ($isNew) { $statusCode = $data['status'] = $filterManager->stripTags($data['status']); } @@ -37,7 +44,7 @@ public function execute() $label = $filterManager->stripTags($label); } - $status = $this->_objectManager->create(\Magento\Sales\Model\Order\Status::class)->load($statusCode); + $status = $this->_objectManager->create(Status::class)->load($statusCode); // check if status exist if ($isNew && $status->getStatus()) { $this->messageManager @@ -52,7 +59,7 @@ public function execute() $status->save(); $this->messageManager->addSuccessMessage(__('You saved the order status.')); return $resultRedirect->setPath('sales/*/'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage( @@ -67,11 +74,11 @@ public function execute() } /** - * @param \Magento\Backend\Model\View\Result\Redirect $resultRedirect + * @param Redirect $resultRedirect * @param bool $isNew - * @return \Magento\Backend\Model\View\Result\Redirect + * @return Redirect */ - private function getRedirect(\Magento\Backend\Model\View\Result\Redirect $resultRedirect, $isNew) + private function getRedirect(Redirect $resultRedirect, $isNew) { if ($isNew) { return $resultRedirect->setPath('sales/*/new'); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php index 2723d483dd38b..16bb275a88ec1 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -class Unassign extends \Magento\Sales\Controller\Adminhtml\Order\Status +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Unassign extends \Magento\Sales\Controller\Adminhtml\Order\Status implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/Index.php index c7f560c52fb66..59d8a68a7446d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/Index.php @@ -6,6 +6,9 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment; -class Index extends \Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\Index +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; +use Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\Index as AbstractIndex; + +class Index extends AbstractIndex implements HttpGetActionInterface { } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php index 750781e99197c..a7327050064ae 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php @@ -6,9 +6,10 @@ */ namespace Magento\Sales\Controller\Adminhtml\Transactions; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\Model\View\Result\Page; -class Index extends \Magento\Sales\Controller\Adminhtml\Transactions +class Index extends \Magento\Sales\Controller\Adminhtml\Transactions implements HttpGetActionInterface { /** * @return Page diff --git a/app/code/Magento/Sales/Controller/Order/Creditmemo.php b/app/code/Magento/Sales/Controller/Order/Creditmemo.php index 2a7fd3e9849e5..74aae3e1f8417 100644 --- a/app/code/Magento/Sales/Controller/Order/Creditmemo.php +++ b/app/code/Magento/Sales/Controller/Order/Creditmemo.php @@ -6,8 +6,10 @@ */ namespace Magento\Sales\Controller\Order; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Sales\Controller\OrderInterface; +use Magento\Sales\Controller\AbstractController\Creditmemo as AbstractCreditmemo; -class Creditmemo extends \Magento\Sales\Controller\AbstractController\Creditmemo implements OrderInterface +class Creditmemo extends AbstractCreditmemo implements OrderInterface, HttpGetActionInterface { } diff --git a/app/code/Magento/Sales/Controller/Order/History.php b/app/code/Magento/Sales/Controller/Order/History.php index 23e8208d8b198..37de159845856 100644 --- a/app/code/Magento/Sales/Controller/Order/History.php +++ b/app/code/Magento/Sales/Controller/Order/History.php @@ -6,11 +6,12 @@ */ namespace Magento\Sales\Controller\Order; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Sales\Controller\OrderInterface; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -class History extends \Magento\Framework\App\Action\Action implements OrderInterface +class History extends \Magento\Framework\App\Action\Action implements OrderInterface, HttpGetActionInterface { /** * @var PageFactory diff --git a/app/code/Magento/Sales/Controller/Order/View.php b/app/code/Magento/Sales/Controller/Order/View.php index d68b9481c8619..21a5706a4448f 100644 --- a/app/code/Magento/Sales/Controller/Order/View.php +++ b/app/code/Magento/Sales/Controller/Order/View.php @@ -6,8 +6,9 @@ */ namespace Magento\Sales\Controller\Order; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Sales\Controller\OrderInterface; -class View extends \Magento\Sales\Controller\AbstractController\View implements OrderInterface +class View extends \Magento\Sales\Controller\AbstractController\View implements OrderInterface, HttpGetActionInterface { } diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 7372d9715c725..9f30342ed331f 100644 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -16,7 +16,7 @@ use Magento\Sales\Model\ResourceModel\Order\Address\Collection; use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection as CreditmemoCollection; use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection as InvoiceCollection; -use Magento\Sales\Model\ResourceModel\Order\Item\Collection as ImportCollection; +use Magento\Sales\Model\ResourceModel\Order\Item\Collection as ItemCollection; use Magento\Sales\Model\ResourceModel\Order\Payment\Collection as PaymentCollection; use Magento\Sales\Model\ResourceModel\Order\Shipment\Collection as ShipmentCollection; use Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection as TrackCollection; @@ -564,6 +564,7 @@ public function canCancel() /** * Getter whether the payment can be voided + * * @return bool */ public function canVoidPayment() @@ -880,7 +881,7 @@ protected function _placePayment() } /** - * {@inheritdoc} + * @inheritdoc */ public function getPayment() { @@ -1008,6 +1009,7 @@ public function addStatusToHistory($status, $comment = '', $isCustomerNotified = /** * Add a comment to order + * * Different or default status may be specified * * @param string $comment @@ -1023,6 +1025,7 @@ public function addStatusHistoryComment($comment, $status = false) /** * Add a comment to order status history + * * Different or default status may be specified * * @param string $comment @@ -1088,6 +1091,8 @@ public function place() } /** + * Hold order + * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ @@ -1233,6 +1238,8 @@ public function getShippingMethod($asObject = false) /*********************** ADDRESSES ***************************/ /** + * Returns address collection instance + * * @return Collection */ public function getAddressesCollection() @@ -1247,6 +1254,8 @@ public function getAddressesCollection() } /** + * Returns address by id + * * @param mixed $addressId * @return false */ @@ -1261,6 +1270,8 @@ public function getAddressById($addressId) } /** + * Add address to order + * * @param \Magento\Sales\Model\Order\Address $address * @return $this */ @@ -1275,9 +1286,11 @@ public function addAddress(\Magento\Sales\Model\Order\Address $address) } /** + * Returns items collection + * * @param array $filterByTypes * @param bool $nonChildrenOnly - * @return ImportCollection + * @return ItemCollection */ public function getItemsCollection($filterByTypes = [], $nonChildrenOnly = false) { @@ -1302,7 +1315,7 @@ public function getItemsCollection($filterByTypes = [], $nonChildrenOnly = false * Get random items collection without related children * * @param int $limit - * @return ImportCollection + * @return ItemCollection */ public function getParentItemsRandomCollection($limit = 1) { @@ -1314,7 +1327,7 @@ public function getParentItemsRandomCollection($limit = 1) * * @param int $limit * @param bool $nonChildrenOnly - * @return ImportCollection + * @return ItemCollection */ protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false) { @@ -1347,6 +1360,8 @@ protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false) } /** + * Returns all order items + * * @return \Magento\Sales\Model\Order\Item[] */ public function getAllItems() @@ -1361,6 +1376,8 @@ public function getAllItems() } /** + * Returns all visible items + * * @return array */ public function getAllVisibleItems() @@ -1392,6 +1409,8 @@ public function getItemById($itemId) } /** + * Returns Item By QuoteItem Id + * * @param mixed $quoteItemId * @return \Magento\Framework\DataObject|null */ @@ -1406,6 +1425,8 @@ public function getItemByQuoteItemId($quoteItemId) } /** + * Add item to order + * * @param \Magento\Sales\Model\Order\Item $item * @return $this */ @@ -1421,6 +1442,8 @@ public function addItem(\Magento\Sales\Model\Order\Item $item) /*********************** PAYMENTS ***************************/ /** + * Returns payment collection + * * @return PaymentCollection */ public function getPaymentsCollection() @@ -1435,6 +1458,8 @@ public function getPaymentsCollection() } /** + * Returns all payments + * * @return array */ public function getAllPayments() @@ -1449,6 +1474,8 @@ public function getAllPayments() } /** + * Returns payment by id + * * @param mixed $paymentId * @return Payment|false */ @@ -1463,7 +1490,7 @@ public function getPaymentById($paymentId) } /** - * {@inheritdoc} + * @inheritdoc */ public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment = null) { @@ -1530,6 +1557,8 @@ public function getVisibleStatusHistory() } /** + * Returns status history by id + * * @param mixed $statusId * @return string|false */ @@ -1545,6 +1574,7 @@ public function getStatusHistoryById($statusId) /** * Set the order status history object and the order object to each other + * * Adds the object to the status history collection, which is automatically saved when the order is saved. * See the entity_id attribute backend model. * Or the history record can be saved standalone after this. @@ -1564,6 +1594,8 @@ public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $hist } /** + * Returns real order id + * * @return string */ public function getRealOrderId() @@ -1592,9 +1624,9 @@ public function getOrderCurrency() /** * Get formatted price value including order currency rate to order website currency * - * @param float $price - * @param bool $addBrackets - * @return string + * @param float $price + * @param bool $addBrackets + * @return string */ public function formatPrice($price, $addBrackets = false) { @@ -1602,6 +1634,8 @@ public function formatPrice($price, $addBrackets = false) } /** + * Format price precision + * * @param float $price * @param int $precision * @param bool $addBrackets @@ -1615,8 +1649,8 @@ public function formatPricePrecision($price, $precision, $addBrackets = false) /** * Retrieve text formatted price value including order rate * - * @param float $price - * @return string + * @param float $price + * @return string */ public function formatPriceTxt($price) { @@ -1637,6 +1671,8 @@ public function getBaseCurrency() } /** + * Format base price + * * @param float $price * @return string */ @@ -1646,6 +1682,8 @@ public function formatBasePrice($price) } /** + * Format Base Price Precision + * * @param float $price * @param int $precision * @return string @@ -1656,6 +1694,8 @@ public function formatBasePricePrecision($price, $precision) } /** + * Is Currency Different + * * @return bool */ public function isCurrencyDifferent() @@ -1688,6 +1728,8 @@ public function getBaseTotalDue() } /** + * Returns object data + * * @param string $key * @param null|string|int $index * @return mixed @@ -1828,6 +1870,8 @@ public function getRelatedObjects() } /** + * Returns customer name + * * @return string */ public function getCustomerName() @@ -1855,8 +1899,8 @@ public function addRelatedObject(\Magento\Framework\Model\AbstractModel $object) /** * Get formatted order created date in store timezone * - * @param string $format date format type (short|medium|long|full) - * @return string + * @param string $format date format type (short|medium|long|full) + * @return string */ public function getCreatedAtFormatted($format) { @@ -1870,6 +1914,8 @@ public function getCreatedAtFormatted($format) } /** + * Returns email customer note + * * @return string */ public function getEmailCustomerNote() @@ -1881,6 +1927,8 @@ public function getEmailCustomerNote() } /** + * Returns store group name + * * @return string */ public function getStoreGroupName() @@ -1894,7 +1942,8 @@ public function getStoreGroupName() /** * Resets all data in object - * so after another load it will be complete new object + * + * So after another load it will be complete new object * * @return $this */ @@ -1918,6 +1967,8 @@ public function reset() } /** + * Get order is not virtual + * * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ @@ -1960,6 +2011,8 @@ public function getIncrementId() } /** + * Returns order items + * * @return \Magento\Sales\Api\Data\OrderItemInterface[] */ public function getItems() @@ -1974,7 +2027,7 @@ public function getItems() } /** - * {@inheritdoc} + * @inheritdoc * @codeCoverageIgnore */ public function setItems($items) @@ -1983,6 +2036,8 @@ public function setItems($items) } /** + * Returns order addresses + * * @return \Magento\Sales\Api\Data\OrderAddressInterface[] */ public function getAddresses() @@ -1997,6 +2052,8 @@ public function getAddresses() } /** + * Returns status history + * * @return \Magento\Sales\Api\Data\OrderStatusHistoryInterface[]|null */ public function getStatusHistories() @@ -2011,7 +2068,7 @@ public function getStatusHistories() } /** - * {@inheritdoc} + * @inheritdoc * * @return \Magento\Sales\Api\Data\OrderExtensionInterface|null */ @@ -2021,7 +2078,7 @@ public function getExtensionAttributes() } /** - * {@inheritdoc} + * @inheritdoc * * @param \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes * @return $this @@ -2504,7 +2561,7 @@ public function getCreatedAt() } /** - * {@inheritdoc} + * @inheritdoc */ public function setCreatedAt($createdAt) { @@ -3322,7 +3379,7 @@ public function getXForwardedFor() } /** - * {@inheritdoc} + * @inheritdoc */ public function setStatusHistories(array $statusHistories = null) { @@ -3330,7 +3387,7 @@ public function setStatusHistories(array $statusHistories = null) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStatus($status) { @@ -3338,7 +3395,7 @@ public function setStatus($status) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCouponCode($code) { @@ -3346,7 +3403,7 @@ public function setCouponCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setProtectCode($code) { @@ -3354,7 +3411,7 @@ public function setProtectCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingDescription($description) { @@ -3362,7 +3419,7 @@ public function setShippingDescription($description) } /** - * {@inheritdoc} + * @inheritdoc */ public function setIsVirtual($isVirtual) { @@ -3370,7 +3427,7 @@ public function setIsVirtual($isVirtual) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStoreId($id) { @@ -3378,7 +3435,7 @@ public function setStoreId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerId($id) { @@ -3386,7 +3443,7 @@ public function setCustomerId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountAmount($amount) { @@ -3394,7 +3451,7 @@ public function setBaseDiscountAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountCanceled($baseDiscountCanceled) { @@ -3402,7 +3459,7 @@ public function setBaseDiscountCanceled($baseDiscountCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountInvoiced($baseDiscountInvoiced) { @@ -3410,7 +3467,7 @@ public function setBaseDiscountInvoiced($baseDiscountInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountRefunded($baseDiscountRefunded) { @@ -3418,7 +3475,7 @@ public function setBaseDiscountRefunded($baseDiscountRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseGrandTotal($amount) { @@ -3426,7 +3483,7 @@ public function setBaseGrandTotal($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingAmount($amount) { @@ -3434,7 +3491,7 @@ public function setBaseShippingAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingCanceled($baseShippingCanceled) { @@ -3442,7 +3499,7 @@ public function setBaseShippingCanceled($baseShippingCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingInvoiced($baseShippingInvoiced) { @@ -3450,7 +3507,7 @@ public function setBaseShippingInvoiced($baseShippingInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingRefunded($baseShippingRefunded) { @@ -3458,7 +3515,7 @@ public function setBaseShippingRefunded($baseShippingRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingTaxAmount($amount) { @@ -3466,7 +3523,7 @@ public function setBaseShippingTaxAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingTaxRefunded($baseShippingTaxRefunded) { @@ -3474,7 +3531,7 @@ public function setBaseShippingTaxRefunded($baseShippingTaxRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseSubtotal($amount) { @@ -3482,7 +3539,7 @@ public function setBaseSubtotal($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseSubtotalCanceled($baseSubtotalCanceled) { @@ -3490,7 +3547,7 @@ public function setBaseSubtotalCanceled($baseSubtotalCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseSubtotalInvoiced($baseSubtotalInvoiced) { @@ -3498,7 +3555,7 @@ public function setBaseSubtotalInvoiced($baseSubtotalInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseSubtotalRefunded($baseSubtotalRefunded) { @@ -3506,7 +3563,7 @@ public function setBaseSubtotalRefunded($baseSubtotalRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTaxAmount($amount) { @@ -3514,7 +3571,7 @@ public function setBaseTaxAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTaxCanceled($baseTaxCanceled) { @@ -3522,7 +3579,7 @@ public function setBaseTaxCanceled($baseTaxCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTaxInvoiced($baseTaxInvoiced) { @@ -3530,7 +3587,7 @@ public function setBaseTaxInvoiced($baseTaxInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTaxRefunded($baseTaxRefunded) { @@ -3538,7 +3595,7 @@ public function setBaseTaxRefunded($baseTaxRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseToGlobalRate($rate) { @@ -3546,7 +3603,7 @@ public function setBaseToGlobalRate($rate) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseToOrderRate($rate) { @@ -3554,7 +3611,7 @@ public function setBaseToOrderRate($rate) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalCanceled($baseTotalCanceled) { @@ -3562,7 +3619,7 @@ public function setBaseTotalCanceled($baseTotalCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalInvoiced($baseTotalInvoiced) { @@ -3570,7 +3627,7 @@ public function setBaseTotalInvoiced($baseTotalInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalInvoicedCost($baseTotalInvoicedCost) { @@ -3578,7 +3635,7 @@ public function setBaseTotalInvoicedCost($baseTotalInvoicedCost) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalOfflineRefunded($baseTotalOfflineRefunded) { @@ -3586,7 +3643,7 @@ public function setBaseTotalOfflineRefunded($baseTotalOfflineRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalOnlineRefunded($baseTotalOnlineRefunded) { @@ -3594,7 +3651,7 @@ public function setBaseTotalOnlineRefunded($baseTotalOnlineRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalPaid($baseTotalPaid) { @@ -3602,7 +3659,7 @@ public function setBaseTotalPaid($baseTotalPaid) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalQtyOrdered($baseTotalQtyOrdered) { @@ -3610,7 +3667,7 @@ public function setBaseTotalQtyOrdered($baseTotalQtyOrdered) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalRefunded($baseTotalRefunded) { @@ -3618,7 +3675,7 @@ public function setBaseTotalRefunded($baseTotalRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountAmount($amount) { @@ -3626,7 +3683,7 @@ public function setDiscountAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountCanceled($discountCanceled) { @@ -3634,7 +3691,7 @@ public function setDiscountCanceled($discountCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountInvoiced($discountInvoiced) { @@ -3642,7 +3699,7 @@ public function setDiscountInvoiced($discountInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountRefunded($discountRefunded) { @@ -3650,7 +3707,7 @@ public function setDiscountRefunded($discountRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setGrandTotal($amount) { @@ -3658,7 +3715,7 @@ public function setGrandTotal($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingAmount($amount) { @@ -3666,7 +3723,7 @@ public function setShippingAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingCanceled($shippingCanceled) { @@ -3674,7 +3731,7 @@ public function setShippingCanceled($shippingCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingInvoiced($shippingInvoiced) { @@ -3682,7 +3739,7 @@ public function setShippingInvoiced($shippingInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingRefunded($shippingRefunded) { @@ -3690,7 +3747,7 @@ public function setShippingRefunded($shippingRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingTaxAmount($amount) { @@ -3698,7 +3755,7 @@ public function setShippingTaxAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingTaxRefunded($shippingTaxRefunded) { @@ -3706,7 +3763,7 @@ public function setShippingTaxRefunded($shippingTaxRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStoreToBaseRate($rate) { @@ -3714,7 +3771,7 @@ public function setStoreToBaseRate($rate) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStoreToOrderRate($rate) { @@ -3722,7 +3779,7 @@ public function setStoreToOrderRate($rate) } /** - * {@inheritdoc} + * @inheritdoc */ public function setSubtotal($amount) { @@ -3730,7 +3787,7 @@ public function setSubtotal($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setSubtotalCanceled($subtotalCanceled) { @@ -3738,7 +3795,7 @@ public function setSubtotalCanceled($subtotalCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setSubtotalInvoiced($subtotalInvoiced) { @@ -3746,7 +3803,7 @@ public function setSubtotalInvoiced($subtotalInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setSubtotalRefunded($subtotalRefunded) { @@ -3754,7 +3811,7 @@ public function setSubtotalRefunded($subtotalRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTaxAmount($amount) { @@ -3762,7 +3819,7 @@ public function setTaxAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTaxCanceled($taxCanceled) { @@ -3770,7 +3827,7 @@ public function setTaxCanceled($taxCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTaxInvoiced($taxInvoiced) { @@ -3778,7 +3835,7 @@ public function setTaxInvoiced($taxInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTaxRefunded($taxRefunded) { @@ -3786,7 +3843,7 @@ public function setTaxRefunded($taxRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalCanceled($totalCanceled) { @@ -3794,7 +3851,7 @@ public function setTotalCanceled($totalCanceled) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalInvoiced($totalInvoiced) { @@ -3802,7 +3859,7 @@ public function setTotalInvoiced($totalInvoiced) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalOfflineRefunded($totalOfflineRefunded) { @@ -3810,7 +3867,7 @@ public function setTotalOfflineRefunded($totalOfflineRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalOnlineRefunded($totalOnlineRefunded) { @@ -3818,7 +3875,7 @@ public function setTotalOnlineRefunded($totalOnlineRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalPaid($totalPaid) { @@ -3826,7 +3883,7 @@ public function setTotalPaid($totalPaid) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalQtyOrdered($totalQtyOrdered) { @@ -3834,7 +3891,7 @@ public function setTotalQtyOrdered($totalQtyOrdered) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalRefunded($totalRefunded) { @@ -3842,7 +3899,7 @@ public function setTotalRefunded($totalRefunded) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCanShipPartially($flag) { @@ -3850,7 +3907,7 @@ public function setCanShipPartially($flag) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCanShipPartiallyItem($flag) { @@ -3858,7 +3915,7 @@ public function setCanShipPartiallyItem($flag) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerIsGuest($customerIsGuest) { @@ -3866,7 +3923,7 @@ public function setCustomerIsGuest($customerIsGuest) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerNoteNotify($customerNoteNotify) { @@ -3874,7 +3931,7 @@ public function setCustomerNoteNotify($customerNoteNotify) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBillingAddressId($id) { @@ -3882,7 +3939,7 @@ public function setBillingAddressId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerGroupId($id) { @@ -3890,7 +3947,7 @@ public function setCustomerGroupId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setEditIncrement($editIncrement) { @@ -3898,7 +3955,7 @@ public function setEditIncrement($editIncrement) } /** - * {@inheritdoc} + * @inheritdoc */ public function setEmailSent($emailSent) { @@ -3906,7 +3963,7 @@ public function setEmailSent($emailSent) } /** - * {@inheritdoc} + * @inheritdoc */ public function setForcedShipmentWithInvoice($forcedShipmentWithInvoice) { @@ -3914,7 +3971,7 @@ public function setForcedShipmentWithInvoice($forcedShipmentWithInvoice) } /** - * {@inheritdoc} + * @inheritdoc */ public function setPaymentAuthExpiration($paymentAuthExpiration) { @@ -3922,7 +3979,7 @@ public function setPaymentAuthExpiration($paymentAuthExpiration) } /** - * {@inheritdoc} + * @inheritdoc */ public function setQuoteAddressId($id) { @@ -3930,7 +3987,7 @@ public function setQuoteAddressId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setQuoteId($id) { @@ -3938,7 +3995,7 @@ public function setQuoteId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setAdjustmentNegative($adjustmentNegative) { @@ -3946,7 +4003,7 @@ public function setAdjustmentNegative($adjustmentNegative) } /** - * {@inheritdoc} + * @inheritdoc */ public function setAdjustmentPositive($adjustmentPositive) { @@ -3954,7 +4011,7 @@ public function setAdjustmentPositive($adjustmentPositive) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseAdjustmentNegative($baseAdjustmentNegative) { @@ -3962,7 +4019,7 @@ public function setBaseAdjustmentNegative($baseAdjustmentNegative) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseAdjustmentPositive($baseAdjustmentPositive) { @@ -3970,7 +4027,7 @@ public function setBaseAdjustmentPositive($baseAdjustmentPositive) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingDiscountAmount($amount) { @@ -3978,7 +4035,7 @@ public function setBaseShippingDiscountAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseSubtotalInclTax($amount) { @@ -3986,7 +4043,7 @@ public function setBaseSubtotalInclTax($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseTotalDue($baseTotalDue) { @@ -3994,7 +4051,7 @@ public function setBaseTotalDue($baseTotalDue) } /** - * {@inheritdoc} + * @inheritdoc */ public function setPaymentAuthorizationAmount($amount) { @@ -4002,7 +4059,7 @@ public function setPaymentAuthorizationAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingDiscountAmount($amount) { @@ -4010,7 +4067,7 @@ public function setShippingDiscountAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setSubtotalInclTax($amount) { @@ -4018,7 +4075,7 @@ public function setSubtotalInclTax($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalDue($totalDue) { @@ -4026,7 +4083,7 @@ public function setTotalDue($totalDue) } /** - * {@inheritdoc} + * @inheritdoc */ public function setWeight($weight) { @@ -4034,7 +4091,7 @@ public function setWeight($weight) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerDob($customerDob) { @@ -4042,7 +4099,7 @@ public function setCustomerDob($customerDob) } /** - * {@inheritdoc} + * @inheritdoc */ public function setIncrementId($id) { @@ -4050,7 +4107,7 @@ public function setIncrementId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setAppliedRuleIds($appliedRuleIds) { @@ -4058,7 +4115,7 @@ public function setAppliedRuleIds($appliedRuleIds) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseCurrencyCode($code) { @@ -4066,7 +4123,7 @@ public function setBaseCurrencyCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerEmail($customerEmail) { @@ -4074,7 +4131,7 @@ public function setCustomerEmail($customerEmail) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerFirstname($customerFirstname) { @@ -4082,7 +4139,7 @@ public function setCustomerFirstname($customerFirstname) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerLastname($customerLastname) { @@ -4090,7 +4147,7 @@ public function setCustomerLastname($customerLastname) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerMiddlename($customerMiddlename) { @@ -4098,7 +4155,7 @@ public function setCustomerMiddlename($customerMiddlename) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerPrefix($customerPrefix) { @@ -4106,7 +4163,7 @@ public function setCustomerPrefix($customerPrefix) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerSuffix($customerSuffix) { @@ -4114,7 +4171,7 @@ public function setCustomerSuffix($customerSuffix) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerTaxvat($customerTaxvat) { @@ -4122,7 +4179,7 @@ public function setCustomerTaxvat($customerTaxvat) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountDescription($description) { @@ -4130,7 +4187,7 @@ public function setDiscountDescription($description) } /** - * {@inheritdoc} + * @inheritdoc */ public function setExtCustomerId($id) { @@ -4138,7 +4195,7 @@ public function setExtCustomerId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setExtOrderId($id) { @@ -4146,7 +4203,7 @@ public function setExtOrderId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setGlobalCurrencyCode($code) { @@ -4154,7 +4211,7 @@ public function setGlobalCurrencyCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setHoldBeforeState($holdBeforeState) { @@ -4162,7 +4219,7 @@ public function setHoldBeforeState($holdBeforeState) } /** - * {@inheritdoc} + * @inheritdoc */ public function setHoldBeforeStatus($holdBeforeStatus) { @@ -4170,7 +4227,7 @@ public function setHoldBeforeStatus($holdBeforeStatus) } /** - * {@inheritdoc} + * @inheritdoc */ public function setOrderCurrencyCode($code) { @@ -4178,7 +4235,7 @@ public function setOrderCurrencyCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setOriginalIncrementId($id) { @@ -4186,7 +4243,7 @@ public function setOriginalIncrementId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setRelationChildId($id) { @@ -4194,7 +4251,7 @@ public function setRelationChildId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setRelationChildRealId($realId) { @@ -4202,7 +4259,7 @@ public function setRelationChildRealId($realId) } /** - * {@inheritdoc} + * @inheritdoc */ public function setRelationParentId($id) { @@ -4210,7 +4267,7 @@ public function setRelationParentId($id) } /** - * {@inheritdoc} + * @inheritdoc */ public function setRelationParentRealId($realId) { @@ -4218,7 +4275,7 @@ public function setRelationParentRealId($realId) } /** - * {@inheritdoc} + * @inheritdoc */ public function setRemoteIp($remoteIp) { @@ -4226,7 +4283,7 @@ public function setRemoteIp($remoteIp) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStoreCurrencyCode($code) { @@ -4234,7 +4291,7 @@ public function setStoreCurrencyCode($code) } /** - * {@inheritdoc} + * @inheritdoc */ public function setStoreName($storeName) { @@ -4242,7 +4299,7 @@ public function setStoreName($storeName) } /** - * {@inheritdoc} + * @inheritdoc */ public function setXForwardedFor($xForwardedFor) { @@ -4250,7 +4307,7 @@ public function setXForwardedFor($xForwardedFor) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerNote($customerNote) { @@ -4258,7 +4315,7 @@ public function setCustomerNote($customerNote) } /** - * {@inheritdoc} + * @inheritdoc */ public function setUpdatedAt($timestamp) { @@ -4266,7 +4323,7 @@ public function setUpdatedAt($timestamp) } /** - * {@inheritdoc} + * @inheritdoc */ public function setTotalItemCount($totalItemCount) { @@ -4274,7 +4331,7 @@ public function setTotalItemCount($totalItemCount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setCustomerGender($customerGender) { @@ -4282,7 +4339,7 @@ public function setCustomerGender($customerGender) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountTaxCompensationAmount($amount) { @@ -4290,7 +4347,7 @@ public function setDiscountTaxCompensationAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountTaxCompensationAmount($amount) { @@ -4298,7 +4355,7 @@ public function setBaseDiscountTaxCompensationAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingDiscountTaxCompensationAmount($amount) { @@ -4306,7 +4363,7 @@ public function setShippingDiscountTaxCompensationAmount($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingDiscountTaxCompensationAmnt($amnt) { @@ -4314,7 +4371,7 @@ public function setBaseShippingDiscountTaxCompensationAmnt($amnt) } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountTaxCompensationInvoiced($discountTaxCompensationInvoiced) { @@ -4322,7 +4379,7 @@ public function setDiscountTaxCompensationInvoiced($discountTaxCompensationInvoi } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountTaxCompensationInvoiced($baseDiscountTaxCompensationInvoiced) { @@ -4333,7 +4390,7 @@ public function setBaseDiscountTaxCompensationInvoiced($baseDiscountTaxCompensat } /** - * {@inheritdoc} + * @inheritdoc */ public function setDiscountTaxCompensationRefunded($discountTaxCompensationRefunded) { @@ -4344,7 +4401,7 @@ public function setDiscountTaxCompensationRefunded($discountTaxCompensationRefun } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseDiscountTaxCompensationRefunded($baseDiscountTaxCompensationRefunded) { @@ -4355,7 +4412,7 @@ public function setBaseDiscountTaxCompensationRefunded($baseDiscountTaxCompensat } /** - * {@inheritdoc} + * @inheritdoc */ public function setShippingInclTax($amount) { @@ -4363,7 +4420,7 @@ public function setShippingInclTax($amount) } /** - * {@inheritdoc} + * @inheritdoc */ public function setBaseShippingInclTax($amount) { diff --git a/app/code/Magento/Sales/Model/Order/Status.php b/app/code/Magento/Sales/Model/Order/Status.php index 288955705425f..4b33f4b4d9251 100644 --- a/app/code/Magento/Sales/Model/Order/Status.php +++ b/app/code/Magento/Sales/Model/Order/Status.php @@ -12,6 +12,7 @@ * Class Status * * @method string getStatus() + * @method $this setStatus(string $status) * @method string getLabel() */ class Status extends \Magento\Sales\Model\AbstractModel diff --git a/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultMergerTest.php b/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultMergerTest.php new file mode 100644 index 0000000000000..4236890a2a37d --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultMergerTest.php @@ -0,0 +1,87 @@ +validatorResultFactoryMock = $this->getMockBuilder(ValidatorResultInterfaceFactory::class) + ->setMethods(['create'])->disableOriginalConstructor()->getMock(); + $this->objectManager = new ObjectManager($this); + $this->validatorResultMerger = $this->objectManager->getObject( + ValidatorResultMerger::class, + [ + 'validatorResultInterfaceFactory' => $this->validatorResultFactoryMock, + ] + ); + } + + /** + * Test merge method + * + * @return void + */ + public function testMerge() + { + $validatorResultMock = $this->createMock(ValidatorResultInterface::class); + $orderValidationResultMock = $this->createMock(ValidatorResultInterface::class); + $creditmemoValidationResultMock = $this->createMock(ValidatorResultInterface::class); + $itemsValidationMessages = [['test04', 'test05'], ['test06']]; + $this->validatorResultFactoryMock->expects($this->once())->method('create') + ->willReturn($validatorResultMock); + $orderValidationResultMock->expects($this->once())->method('getMessages')->willReturn(['test01', 'test02']); + $creditmemoValidationResultMock->expects($this->once())->method('getMessages')->willReturn(['test03']); + + $validatorResultMock->expects($this->at(0))->method('addMessage')->with('test01'); + $validatorResultMock->expects($this->at(1))->method('addMessage')->with('test02'); + $validatorResultMock->expects($this->at(2))->method('addMessage')->with('test03'); + $validatorResultMock->expects($this->at(3))->method('addMessage')->with('test04'); + $validatorResultMock->expects($this->at(4))->method('addMessage')->with('test05'); + $validatorResultMock->expects($this->at(5))->method('addMessage')->with('test06'); + $expected = $validatorResultMock; + $actual = $this->validatorResultMerger->merge( + $orderValidationResultMock, + $creditmemoValidationResultMock, + ...$itemsValidationMessages + ); + $this->assertEquals($expected, $actual); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultTest.php b/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultTest.php new file mode 100644 index 0000000000000..f4ab2d4f48e6f --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/ValidatorResultTest.php @@ -0,0 +1,75 @@ +objectManager = new ObjectManager($this); + $this->validatorResult = $this->objectManager->getObject(ValidatorResult::class); + } + + /** + * Test addMessage method + * + * @return void + */ + public function testAddMessages() + { + $messageFirst = 'Sample message 01.'; + $messageSecond = 'Sample messages 02.'; + $messageThird = 'Sample messages 03.'; + $expected = [$messageFirst, $messageSecond, $messageThird]; + $this->validatorResult->addMessage($messageFirst); + $this->validatorResult->addMessage($messageSecond); + $this->validatorResult->addMessage($messageThird); + $actual = $this->validatorResult->getMessages(); + $this->assertEquals($expected, $actual); + } + + /** + * Test hasMessages method + * + * @return void + */ + public function testHasMessages() + { + $this->assertFalse($this->validatorResult->hasMessages()); + $messageFirst = 'Sample message 01.'; + $messageSecond = 'Sample messages 02.'; + $this->validatorResult->addMessage($messageFirst); + $this->validatorResult->addMessage($messageSecond); + $this->assertTrue($this->validatorResult->hasMessages()); + } +} diff --git a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/DeleteButton.php b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/DeleteButton.php index 0cb286056d825..bee7573c1fe2a 100644 --- a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/DeleteButton.php +++ b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/DeleteButton.php @@ -26,7 +26,7 @@ public function getButtonData() 'class' => 'delete', 'on_click' => 'deleteConfirm(\'' . __( 'Are you sure you want to delete this?' - ) . '\', \'' . $this->urlBuilder->getUrl('*/*/delete', ['id' => $ruleId]) . '\')', + ) . '\', \'' . $this->urlBuilder->getUrl('*/*/delete', ['id' => $ruleId]) . '\', {data: {}})', 'sort_order' => 20, ]; } diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Delete.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Delete.php index 28993e159499b..45b717fb9bd2d 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Delete.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote; -class Delete extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpPostActionInterface { /** * Delete promo quote action diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php index 717c71fde4837..3255ee0f2b724 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote; -class Edit extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpGetActionInterface { /** * @var \Magento\Framework\View\Result\PageFactory diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Index.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Index.php index 0c11ee3785a08..4f3c712049e43 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Index.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote; -class Index extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewAction.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewAction.php index ecf39605a8709..5adef0552bc8b 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewAction.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewAction.php @@ -6,7 +6,9 @@ */ namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote; -class NewAction extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class NewAction extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpGetActionInterface { /** * New promo quote action diff --git a/app/code/Magento/SalesRule/Test/Unit/Block/Adminhtml/Promo/Quote/Edit/DeleteButtonTest.php b/app/code/Magento/SalesRule/Test/Unit/Block/Adminhtml/Promo/Quote/Edit/DeleteButtonTest.php index fb01476ed6b34..7812444c68694 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Block/Adminhtml/Promo/Quote/Edit/DeleteButtonTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Block/Adminhtml/Promo/Quote/Edit/DeleteButtonTest.php @@ -25,13 +25,16 @@ class DeleteButtonTest extends \PHPUnit\Framework\TestCase */ protected $registryMock; + /** + * @inheritDoc + */ protected function setUp() { $this->urlBuilderMock = $this->createMock(\Magento\Framework\UrlInterface::class); $this->registryMock = $this->createMock(\Magento\Framework\Registry::class); $contextMock = $this->createMock(\Magento\Backend\Block\Widget\Context::class); - $contextMock->expects($this->once())->method('getUrlBuilder')->willReturn($this->urlBuilderMock); + $contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilderMock); $this->model = (new ObjectManager($this))->getObject( \Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\DeleteButton::class, @@ -42,33 +45,9 @@ protected function setUp() ); } - public function testGetButtonData() - { - $ruleId = 42; - $deleteUrl = 'http://magento.com/rule/delete/' . $ruleId; - $ruleMock = new \Magento\Framework\DataObject(['id' => $ruleId]); - - $this->registryMock->expects($this->once()) - ->method('registry') - ->with(RegistryConstants::CURRENT_SALES_RULE) - ->willReturn($ruleMock); - $this->urlBuilderMock->expects($this->once()) - ->method('getUrl') - ->with('*/*/delete', ['id' => $ruleId]) - ->willReturn($deleteUrl); - - $data = [ - 'label' => __('Delete'), - 'class' => 'delete', - 'on_click' => 'deleteConfirm(\'' . __( - 'Are you sure you want to delete this?' - ) . '\', \'' . $deleteUrl . '\')', - 'sort_order' => 20, - ]; - - $this->assertEquals($data, $this->model->getButtonData()); - } - + /** + * Test empty response without a present rule. + */ public function testGetButtonDataWithoutRule() { $this->assertEquals([], $this->model->getButtonData()); diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php index c7adf32da0fb0..ce3dfcc601fa4 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php @@ -5,10 +5,11 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Framework\Controller\ResultFactory; -class Delete extends TermController +class Delete extends TermController implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php index 3ee0ea240377f..cd1ef7553c7ec 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php @@ -5,12 +5,13 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; use Magento\Framework\Controller\ResultFactory; -class Edit extends TermController +class Edit extends TermController implements HttpGetActionInterface { /** * Core registry diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php index f7d0b86590721..c097cc08489f9 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php @@ -5,9 +5,10 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Search\Controller\Adminhtml\Term as TermController; -class Index extends TermController +class Index extends TermController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php b/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php index f6874078f2f64..84e475b7275ae 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php @@ -5,10 +5,11 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Framework\Controller\ResultFactory; -class MassDelete extends TermController +class MassDelete extends TermController implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php b/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php index 8565c03724c65..49805400713fc 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php @@ -5,10 +5,11 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Framework\Controller\ResultFactory; -class NewAction extends TermController +class NewAction extends TermController implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Forward diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php index fb4964717e565..b0ce066f12709 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php @@ -5,10 +5,11 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Reports\Controller\Adminhtml\Index as ReportsIndexController; use Magento\Framework\Controller\ResultFactory; -class Report extends ReportsIndexController +class Report extends ReportsIndexController implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php index cd9b1347ed1ed..39ae07f0d3531 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php @@ -5,13 +5,14 @@ */ namespace Magento\Search\Controller\Adminhtml\Term; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\ResultFactory; use Magento\Search\Model\QueryFactory; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Framework\Exception\LocalizedException; -class Save extends TermController +class Save extends TermController implements HttpPostActionInterface { /** * @var QueryFactory diff --git a/app/code/Magento/Search/Controller/Ajax/Suggest.php b/app/code/Magento/Search/Controller/Ajax/Suggest.php index 307f4df163243..6eab0949145b7 100644 --- a/app/code/Magento/Search/Controller/Ajax/Suggest.php +++ b/app/code/Magento/Search/Controller/Ajax/Suggest.php @@ -5,12 +5,13 @@ */ namespace Magento\Search\Controller\Ajax; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Search\Model\AutocompleteInterface; use Magento\Framework\Controller\ResultFactory; -class Suggest extends Action +class Suggest extends Action implements HttpGetActionInterface { /** * @var \Magento\Search\Model\AutocompleteInterface diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/NewAction.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/NewAction.php index be0555fbcda40..7231bc8b9c6e0 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/NewAction.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/NewAction.php @@ -6,10 +6,11 @@ */ namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; use Magento\Framework\App\ObjectManager; -class NewAction extends \Magento\Backend\App\Action +class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php index 4804efcc76ecc..8bd64ccf82d88 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php @@ -6,6 +6,7 @@ */ namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; use Magento\Sales\Model\Order\Shipment\Validation\QuantityValidator; @@ -13,7 +14,7 @@ * Class Save * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Backend\App\Action +class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Start.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Start.php index ac15c0accd1c3..8a874ddc79526 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Start.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Start.php @@ -6,7 +6,9 @@ */ namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment; -class Start extends \Magento\Backend\App\Action +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Start extends \Magento\Backend\App\Action implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Sitemap/Block/Robots.php b/app/code/Magento/Sitemap/Block/Robots.php index 410bc02da3630..ac99b2ab1cd4a 100644 --- a/app/code/Magento/Sitemap/Block/Robots.php +++ b/app/code/Magento/Sitemap/Block/Robots.php @@ -22,11 +22,6 @@ */ class Robots extends AbstractBlock implements IdentityInterface { - /** - * @var StoreResolver - */ - private $storeResolver; - /** * @var CollectionFactory */ @@ -49,6 +44,8 @@ class Robots extends AbstractBlock implements IdentityInterface * @param SitemapHelper $sitemapHelper * @param StoreManagerInterface $storeManager * @param array $data + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( Context $context, @@ -58,7 +55,6 @@ public function __construct( StoreManagerInterface $storeManager, array $data = [] ) { - $this->storeResolver = $storeResolver; $this->sitemapCollectionFactory = $sitemapCollectionFactory; $this->sitemapHelper = $sitemapHelper; $this->storeManager = $storeManager; @@ -78,8 +74,7 @@ public function __construct( */ protected function _toHtml() { - $defaultStoreId = $this->storeResolver->getCurrentStoreId(); - $defaultStore = $this->storeManager->getStore($defaultStoreId); + $defaultStore = $this->storeManager->getDefaultStoreView(); /** @var \Magento\Store\Model\Website $website */ $website = $this->storeManager->getWebsite($defaultStore->getWebsiteId()); @@ -138,7 +133,7 @@ protected function getSitemapLinks(array $storeIds) public function getIdentities() { return [ - Value::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(), + Value::CACHE_TAG . '_' . $this->storeManager->getDefaultStoreView()->getId(), ]; } } diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php index 5f2cc805de0fc..e6823c6070a1b 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Index.php @@ -6,9 +6,10 @@ */ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Backend\App\Action; -class Index extends \Magento\Sitemap\Controller\Adminhtml\Sitemap +class Index extends \Magento\Sitemap\Controller\Adminhtml\Sitemap implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php b/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php index d69b8e6d44815..7a6d28259bfed 100644 --- a/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php +++ b/app/code/Magento/Sitemap/Model/Config/Backend/Robots.php @@ -15,9 +15,11 @@ use Magento\Framework\Registry; use Magento\Robots\Model\Config\Value as RobotsValue; use Magento\Store\Model\StoreResolver; +use Magento\Store\Model\StoreManagerInterface; /** * Backend model for sitemap/search_engines/submission_robots configuration value. + * * Required to implement Page Cache functionality. */ class Robots extends Value implements IdentityInterface @@ -30,9 +32,9 @@ class Robots extends Value implements IdentityInterface protected $_cacheTag = true; /** - * @var StoreResolver + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @param Context $context @@ -40,9 +42,12 @@ class Robots extends Value implements IdentityInterface * @param ScopeConfigInterface $config * @param TypeListInterface $cacheTypeList * @param StoreResolver $storeResolver + * @param StoreManagerInterface|null $storeManager * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( Context $context, @@ -50,11 +55,13 @@ public function __construct( ScopeConfigInterface $config, TypeListInterface $cacheTypeList, StoreResolver $storeResolver, + StoreManagerInterface $storeManager = null, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] ) { - $this->storeResolver = $storeResolver; + $this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(StoreManagerInterface::class); parent::__construct( $context, @@ -75,7 +82,7 @@ public function __construct( public function getIdentities() { return [ - RobotsValue::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(), + RobotsValue::CACHE_TAG . '_' . $this->storeManager->getStore()->getId(), ]; } } diff --git a/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php b/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php index 6fcd247ab1f0f..b7cfd2028b75f 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Sitemap\Test\Unit\Block; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -77,6 +79,7 @@ protected function setUp() $this->sitemapCollectionFactory = $this->getMockBuilder( \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory::class ) + ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); @@ -109,12 +112,17 @@ public function testToHtmlRobotsSubmissionIsDisabled() $this->initEventManagerMock($expected); $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') - ->willReturn($defaultStoreId); - $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class) ->getMockForAbstractClass(); + + $storeMock->expects($this->once()) + ->method('getWebsiteId') + ->willReturn($defaultWebsiteId); + + $this->storeManager->expects($this->once()) + ->method('getDefaultStoreView') + ->willReturn($storeMock); + $storeMock->expects($this->any()) ->method('getWebsiteId') ->willReturn($defaultWebsiteId); @@ -126,10 +134,6 @@ public function testToHtmlRobotsSubmissionIsDisabled() ->method('getStoreIds') ->willReturn([$defaultStoreId]); - $this->storeManager->expects($this->once()) - ->method('getStore') - ->with($defaultStoreId) - ->willReturn($storeMock); $this->storeManager->expects($this->once()) ->method('getWebsite') ->with($defaultWebsiteId) @@ -165,12 +169,13 @@ public function testAfterGetDataRobotsSubmissionIsEnabled() $this->initEventManagerMock($expected); $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') - ->willReturn($defaultStoreId); - $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class) ->getMockForAbstractClass(); + + $this->storeManager->expects($this->once()) + ->method('getDefaultStoreView') + ->willReturn($storeMock); + $storeMock->expects($this->any()) ->method('getWebsiteId') ->willReturn($defaultWebsiteId); @@ -182,10 +187,6 @@ public function testAfterGetDataRobotsSubmissionIsEnabled() ->method('getStoreIds') ->willReturn([$defaultStoreId, $secondStoreId]); - $this->storeManager->expects($this->once()) - ->method('getStore') - ->with($defaultStoreId) - ->willReturn($storeMock); $this->storeManager->expects($this->once()) ->method('getWebsite') ->with($defaultWebsiteId) @@ -228,8 +229,14 @@ public function testGetIdentities() { $storeId = 1; - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') + $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMockForAbstractClass(); + + $this->storeManager->expects($this->once()) + ->method('getDefaultStoreView') + ->willReturn($storeMock); + + $storeMock->expects($this->once()) + ->method('getId') ->willReturn($storeId); $expected = [ diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/RobotsTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/RobotsTest.php index f3c2f90de286b..cbf353d0a93c7 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/RobotsTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/RobotsTest.php @@ -37,6 +37,11 @@ class RobotsTest extends \PHPUnit\Framework\TestCase */ private $storeResolver; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeManager; + protected function setUp() { $this->context = $this->getMockBuilder(\Magento\Framework\Model\Context::class) @@ -57,12 +62,16 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->model = new \Magento\Sitemap\Model\Config\Backend\Robots( $this->context, $this->registry, $this->scopeConfig, $this->typeList, - $this->storeResolver + $this->storeResolver, + $this->storeManager ); } @@ -73,8 +82,14 @@ public function testGetIdentities() { $storeId = 1; - $this->storeResolver->expects($this->once()) - ->method('getCurrentStoreId') + $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock(); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->willReturn($storeMock); + + $storeMock->expects($this->once()) + ->method('getId') ->willReturn($storeId); $expected = [ diff --git a/app/code/Magento/Store/Api/StoreResolverInterface.php b/app/code/Magento/Store/Api/StoreResolverInterface.php index 7eb28729ec239..7c32e321fa6c4 100644 --- a/app/code/Magento/Store/Api/StoreResolverInterface.php +++ b/app/code/Magento/Store/Api/StoreResolverInterface.php @@ -8,8 +8,8 @@ /** * Store resolver interface * - * @api - * @since 100.0.2 + * @deprecated + * @see \Magento\Store\Model\StoreManagerInterface */ interface StoreResolverInterface { diff --git a/app/code/Magento/Store/App/Action/Plugin/Context.php b/app/code/Magento/Store/App/Action/Plugin/Context.php index 6ec6cf01bc71c..0d34179d3c63e 100644 --- a/app/code/Magento/Store/App/Action/Plugin/Context.php +++ b/app/code/Magento/Store/App/Action/Plugin/Context.php @@ -9,10 +9,8 @@ use Magento\Framework\App\Http\Context as HttpContext; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\NotFoundException; -use Magento\Framework\Phrase; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\StoreCookieManagerInterface; -use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\Action\AbstractAction; use Magento\Framework\App\RequestInterface; @@ -80,7 +78,7 @@ public function beforeDispatch( /** @var string|array|null $storeCode */ $storeCode = $request->getParam( - StoreResolverInterface::PARAM_NAME, + \Magento\Store\Model\StoreManagerInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); if (is_array($storeCode)) { @@ -106,7 +104,7 @@ public function beforeDispatch( /** * Take action in case of invalid store requested. * - * @param \Throwable|null $previousException + * @param \Throwable|null $previousException * @return void * @throws NotFoundException */ diff --git a/app/code/Magento/Store/App/Request/PathInfoProcessor.php b/app/code/Magento/Store/App/Request/PathInfoProcessor.php index 3fa78dc94aa35..fad0d07c3a0a7 100644 --- a/app/code/Magento/Store/App/Request/PathInfoProcessor.php +++ b/app/code/Magento/Store/App/Request/PathInfoProcessor.php @@ -3,56 +3,75 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Store\App\Request; +declare(strict_types=1); -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Store\Model\Store; +namespace Magento\Store\App\Request; +/** + * Processes the path and looks for the store in the url and removes it and modifies the path accordingly. + */ class PathInfoProcessor implements \Magento\Framework\App\Request\PathInfoProcessorInterface { /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StorePathInfoValidator */ - private $storeManager; + private $storePathInfoValidator; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @var \Magento\Framework\App\Config\ReinitableConfigInterface */ - public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager) - { - $this->storeManager = $storeManager; + private $config; + + /** + * @param \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator + * @param \Magento\Framework\App\Config\ReinitableConfigInterface $config + */ + public function __construct( + \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator, + \Magento\Framework\App\Config\ReinitableConfigInterface $config + ) { + $this->storePathInfoValidator = $storePathInfoValidator; + $this->config = $config; } /** - * Process path info + * Process path info and remove store from pathInfo. + * + * This method also sets request to no route if store is not valid and store is present in url config is enabled * * @param \Magento\Framework\App\RequestInterface $request * @param string $pathInfo * @return string */ - public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo) + public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo) : string { - $pathParts = explode('/', ltrim($pathInfo, '/'), 2); - $storeCode = $pathParts[0]; - - try { - /** @var \Magento\Store\Api\Data\StoreInterface $store */ - $store = $this->storeManager->getStore($storeCode); - } catch (NoSuchEntityException $e) { - return $pathInfo; - } - - if ($store->isUseStoreInUrl()) { - if (!$request->isDirectAccessFrontendName($storeCode) && $storeCode != Store::ADMIN_CODE) { - $this->storeManager->setCurrentStore($store->getCode()); - $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); - return $pathInfo; - } elseif (!empty($storeCode)) { - $request->setActionName('noroute'); - return $pathInfo; + //can store code be used in url + if ((bool)$this->config->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL)) { + $storeCode = $this->storePathInfoValidator->getValidStoreCode($request, $pathInfo); + if (!empty($storeCode)) { + if (!$request->isDirectAccessFrontendName($storeCode)) { + $pathInfo = $this->trimStoreCodeFromPathInfo($pathInfo, $storeCode); + } else { + //no route in case we're trying to access a store that has the same code as a direct access + $request->setActionName(\Magento\Framework\App\Router\Base::NO_ROUTE); + } } - return $pathInfo; } return $pathInfo; } + + /** + * Trim store code from path info string if exists + * + * @param string $pathInfo + * @param string $storeCode + * @return string + */ + private function trimStoreCodeFromPathInfo(string $pathInfo, string $storeCode) : ?string + { + if (substr($pathInfo, 0, strlen('/' . $storeCode)) == '/'. $storeCode) { + $pathInfo = substr($pathInfo, strlen($storeCode)+1); + } + return empty($pathInfo) ? '/' : $pathInfo; + } } diff --git a/app/code/Magento/Store/App/Request/StorePathInfoValidator.php b/app/code/Magento/Store/App/Request/StorePathInfoValidator.php new file mode 100644 index 0000000000000..0b66ba7586009 --- /dev/null +++ b/app/code/Magento/Store/App/Request/StorePathInfoValidator.php @@ -0,0 +1,102 @@ +config = $config; + $this->storeRepository = $storeRepository; + $this->pathInfo = $pathInfo; + } + + /** + * Get store code from path info validate if config value. If path info is empty the try to calculate from request. + * + * @param \Magento\Framework\App\Request\Http $request + * @param string $pathInfo + * @return string|null + */ + public function getValidStoreCode( + \Magento\Framework\App\Request\Http $request, + string $pathInfo = '' + ) : ?string { + if (empty($pathInfo)) { + $pathInfo = $this->pathInfo->getPathInfo( + $request->getRequestUri(), + $request->getBaseUrl() + ); + } + $storeCode = $this->getStoreCode($pathInfo); + if (!empty($storeCode) + && $storeCode != Store::ADMIN_CODE + && (bool)$this->config->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL) + ) { + try { + $this->storeRepository->getActiveStoreByCode($storeCode); + + if ((bool)$this->config->getValue( + \Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $storeCode + )) { + return $storeCode; + } + } catch (NoSuchEntityException $e) { + //return null; + } catch (\Magento\Store\Model\StoreIsInactiveException $e) { + //return null; + } + } + return null; + } + + /** + * Get store code from path info string + * + * @param string $pathInfo + * @return string + */ + private function getStoreCode(string $pathInfo) : string + { + $pathParts = explode('/', ltrim($pathInfo, '/'), 2); + return current($pathParts); + } +} diff --git a/app/code/Magento/Store/App/Response/Redirect.php b/app/code/Magento/Store/App/Response/Redirect.php index 534c6be41c937..3ad6a86db6908 100644 --- a/app/code/Magento/Store/App/Response/Redirect.php +++ b/app/code/Magento/Store/App/Response/Redirect.php @@ -7,8 +7,9 @@ */ namespace Magento\Store\App\Response; -use Magento\Store\Api\StoreResolverInterface; - +/** + * Class Redirect computes redirect urls responses. + */ class Redirect implements \Magento\Framework\App\Response\RedirectInterface { /** @@ -76,6 +77,8 @@ public function __construct( } /** + * Get the referrer url. + * * @return string * @throws \Magento\Framework\Exception\NoSuchEntityException */ @@ -164,10 +167,7 @@ public function success($defaultUrl) } /** - * {@inheritdoc} - * - * @param array $arguments - * @return array + * @inheritdoc */ public function updatePathParams(array $arguments) { @@ -248,10 +248,10 @@ protected function normalizeRefererQueryParts($refererQuery) $store = $this->_storeManager->getStore(); if ($store - && !empty($refererQuery[StoreResolverInterface::PARAM_NAME]) - && ($refererQuery[StoreResolverInterface::PARAM_NAME] !== $store->getCode()) + && !empty($refererQuery[\Magento\Store\Model\StoreManagerInterface::PARAM_NAME]) + && ($refererQuery[\Magento\Store\Model\StoreManagerInterface::PARAM_NAME] !== $store->getCode()) ) { - $refererQuery[StoreResolverInterface::PARAM_NAME] = $store->getCode(); + $refererQuery[\Magento\Store\Model\StoreManagerInterface::PARAM_NAME] = $store->getCode(); } return $refererQuery; diff --git a/app/code/Magento/Store/Block/Switcher.php b/app/code/Magento/Store/Block/Switcher.php index 58a7ba3c1c283..f15349f11066d 100644 --- a/app/code/Magento/Store/Block/Switcher.php +++ b/app/code/Magento/Store/Block/Switcher.php @@ -10,7 +10,6 @@ namespace Magento\Store\Block; use Magento\Directory\Helper\Data; -use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\Group; use Magento\Store\Model\Store; use Magento\Framework\App\ActionInterface; @@ -18,6 +17,8 @@ use Magento\Framework\Url\Helper\Data as UrlHelper; /** + * Switcher block + * * @api * @since 100.0.2 */ @@ -39,8 +40,6 @@ class Switcher extends \Magento\Framework\View\Element\Template private $urlHelper; /** - * Constructs - * * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper * @param array $data @@ -58,6 +57,8 @@ public function __construct( } /** + * Get current website Id. + * * @return int|null|string */ public function getCurrentWebsiteId() @@ -66,6 +67,8 @@ public function getCurrentWebsiteId() } /** + * Get current group Id. + * * @return int|null|string */ public function getCurrentGroupId() @@ -74,6 +77,8 @@ public function getCurrentGroupId() } /** + * Get current Store Id. + * * @return int */ public function getCurrentStoreId() @@ -82,6 +87,8 @@ public function getCurrentStoreId() } /** + * Get raw groups. + * * @return array */ public function getRawGroups() @@ -99,6 +106,8 @@ public function getRawGroups() } /** + * Get raw stores. + * * @return array */ public function getRawStores() @@ -170,6 +179,8 @@ public function getGroups() } /** + * Get stores. + * * @return \Magento\Store\Model\Store[] */ public function getStores() @@ -189,6 +200,8 @@ public function getStores() } /** + * Get current store code. + * * @return string */ public function getCurrentStoreCode() @@ -197,6 +210,8 @@ public function getCurrentStoreCode() } /** + * Is store in url. + * * @return bool */ public function isStoreInUrl() @@ -208,7 +223,7 @@ public function isStoreInUrl() } /** - * Get store code + * Get store code. * * @return string */ @@ -218,7 +233,7 @@ public function getStoreCode() } /** - * Get store name + * Get store name. * * @return null|string */ @@ -228,7 +243,7 @@ public function getStoreName() } /** - * Returns target store post data + * Returns target store post data. * * @param Store $store * @param array $data @@ -237,7 +252,7 @@ public function getStoreName() */ public function getTargetStorePostData(Store $store, $data = []) { - $data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME] = $store->getCode(); + $data[\Magento\Store\Model\StoreManagerInterface::PARAM_NAME] = $store->getCode(); $data['___from_store'] = $this->_storeManager->getStore()->getCode(); $urlOnTargetStore = $store->getCurrentUrl(false); diff --git a/app/code/Magento/Store/Controller/Store/SwitchAction.php b/app/code/Magento/Store/Controller/Store/SwitchAction.php index df946b45d60e5..de721869c5aba 100644 --- a/app/code/Magento/Store/Controller/Store/SwitchAction.php +++ b/app/code/Magento/Store/Controller/Store/SwitchAction.php @@ -15,13 +15,13 @@ use Magento\Store\Api\StoreCookieManagerInterface; use Magento\Store\Api\StoreRepositoryInterface; use Magento\Store\Model\StoreIsInactiveException; -use Magento\Store\Model\StoreResolver; use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\StoreSwitcher; use Magento\Store\Model\StoreSwitcherInterface; /** * Handles store switching url and makes redirect. + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class SwitchAction extends Action @@ -81,13 +81,15 @@ public function __construct( } /** + * Execute action + * * @return void * @throws StoreSwitcher\CannotSwitchStoreException */ public function execute() { $targetStoreCode = $this->_request->getParam( - StoreResolver::PARAM_NAME, + \Magento\Store\Model\StoreManagerInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); $fromStoreCode = $this->_request->getParam('___from_store'); diff --git a/app/code/Magento/Store/Model/Argument/Interpreter/ServiceUrl.php b/app/code/Magento/Store/Model/Argument/Interpreter/ServiceUrl.php index cfa13e65ea42a..4d4021f5528ad 100644 --- a/app/code/Magento/Store/Model/Argument/Interpreter/ServiceUrl.php +++ b/app/code/Magento/Store/Model/Argument/Interpreter/ServiceUrl.php @@ -6,8 +6,8 @@ namespace Magento\Store\Model\Argument\Interpreter; use Magento\Framework\Data\Argument\InterpreterInterface; -use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\StoreRepository; +use Magento\Store\Model\StoreManagerInterface; /** * Interpreter that builds Service URL by input path and optional parameters @@ -25,9 +25,9 @@ class ServiceUrl implements InterpreterInterface private $service; /** - * @var StoreResolverInterface + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @var string @@ -41,21 +41,21 @@ class ServiceUrl implements InterpreterInterface /** * @param \Magento\Framework\Url $url - * @param StoreResolverInterface $storeResolver + * @param StoreManagerInterface $storeManager * @param StoreRepository $storeRepository * @param string $service * @param string $version */ public function __construct( \Magento\Framework\Url $url, - StoreResolverInterface $storeResolver, + StoreManagerInterface $storeManager, StoreRepository $storeRepository, $service = "rest", $version = "V1" ) { $this->url = $url; $this->service = $service; - $this->storeResolver = $storeResolver; + $this->storeManager = $storeManager; $this->version = $version; $this->storeRepository = $storeRepository; } @@ -67,14 +67,16 @@ public function __construct( */ private function getServiceUrl() { - $store = $this->storeRepository->getById($this->storeResolver->getCurrentStoreId()); + $store = $this->storeRepository->getById($this->storeManager->getStore()->getId()); return $this->url->getUrl( $this->service . "/" . $store->getCode() . "/" . $this->version ); } /** - * {@inheritdoc} + * Compute and return effective value of an argument + * + * @param array $data * @return string * @throws \InvalidArgumentException */ diff --git a/app/code/Magento/Store/Model/Plugin/StoreCookie.php b/app/code/Magento/Store/Model/Plugin/StoreCookie.php index 9fca86ab71762..7aa2c91652e86 100644 --- a/app/code/Magento/Store/Model/Plugin/StoreCookie.php +++ b/app/code/Magento/Store/Model/Plugin/StoreCookie.php @@ -12,8 +12,6 @@ use Magento\Store\Model\StoreIsInactiveException; use Magento\Framework\Exception\NoSuchEntityException; use \InvalidArgumentException; -use Magento\Store\Api\StoreResolverInterface; -use Magento\Framework\App\ObjectManager; /** * Class StoreCookie @@ -35,27 +33,19 @@ class StoreCookie */ protected $storeRepository; - /** - * @var StoreResolverInterface - */ - private $storeResolver; - /** * @param StoreManagerInterface $storeManager * @param StoreCookieManagerInterface $storeCookieManager * @param StoreRepositoryInterface $storeRepository - * @param StoreResolverInterface $storeResolver */ public function __construct( StoreManagerInterface $storeManager, StoreCookieManagerInterface $storeCookieManager, - StoreRepositoryInterface $storeRepository, - StoreResolverInterface $storeResolver = null + StoreRepositoryInterface $storeRepository ) { $this->storeManager = $storeManager; $this->storeCookieManager = $storeCookieManager; $this->storeRepository = $storeRepository; - $this->storeResolver = $storeResolver ?: ObjectManager::getInstance()->get(StoreResolverInterface::class); } /** diff --git a/app/code/Magento/Store/Model/StoreManagerInterface.php b/app/code/Magento/Store/Model/StoreManagerInterface.php index 220155c47f6df..f440515f23e0b 100644 --- a/app/code/Magento/Store/Model/StoreManagerInterface.php +++ b/app/code/Magento/Store/Model/StoreManagerInterface.php @@ -21,6 +21,11 @@ interface StoreManagerInterface */ const CONTEXT_STORE = 'store'; + /** + * The store GET Param name + */ + const PARAM_NAME = '___store'; + /** * Allow or disallow single store mode * diff --git a/app/code/Magento/Store/Model/StoreResolver.php b/app/code/Magento/Store/Model/StoreResolver.php index 3f449f10c6d42..aafdd15138981 100644 --- a/app/code/Magento/Store/Model/StoreResolver.php +++ b/app/code/Magento/Store/Model/StoreResolver.php @@ -3,10 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Store\Model; +declare(strict_types=1); -use Magento\Framework\Serialize\SerializerInterface; +namespace Magento\Store\Model; +/** + * Class used to resolve store from url path or get parameters or cookie. + */ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface { /** @@ -25,12 +28,12 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface protected $storeCookieManager; /** - * @var \Magento\Framework\Cache\FrontendInterface + * @deprecated */ protected $cache; /** - * @var \Magento\Store\Model\StoreResolver\ReaderList + * @deprecated */ protected $readerList; @@ -45,56 +48,70 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface protected $scopeCode; /** - * @var \Magento\Framework\App\RequestInterface + * @var \Magento\Framework\App\Request\Http */ protected $request; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var StoresData + */ + private $storesData; + + /** + * @var \Magento\Store\App\Request\StorePathInfoValidator */ - private $serializer; + private $storePathInfoValidator; /** * @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository * @param \Magento\Store\Api\StoreCookieManagerInterface $storeCookieManager - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\Cache\FrontendInterface $cache - * @param \Magento\Store\Model\StoreResolver\ReaderList $readerList - * @param string $runMode - * @param null $scopeCode + * @param \Magento\Framework\App\Request\Http $request + * @param \Magento\Store\Model\StoresData $storesData + * @param \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator + * @param string|null $runMode + * @param string|null $scopeCode */ public function __construct( \Magento\Store\Api\StoreRepositoryInterface $storeRepository, \Magento\Store\Api\StoreCookieManagerInterface $storeCookieManager, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\Cache\FrontendInterface $cache, - \Magento\Store\Model\StoreResolver\ReaderList $readerList, + \Magento\Framework\App\Request\Http $request, + \Magento\Store\Model\StoresData $storesData, + \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator, $runMode = ScopeInterface::SCOPE_STORE, $scopeCode = null ) { $this->storeRepository = $storeRepository; $this->storeCookieManager = $storeCookieManager; $this->request = $request; - $this->cache = $cache; - $this->readerList = $readerList; + $this->storePathInfoValidator = $storePathInfoValidator; + $this->storesData = $storesData; $this->runMode = $scopeCode ? $runMode : ScopeInterface::SCOPE_WEBSITE; $this->scopeCode = $scopeCode; } /** - * {@inheritdoc} + * @inheritdoc */ public function getCurrentStoreId() { list($stores, $defaultStoreId) = $this->getStoresData(); - $storeCode = $this->request->getParam(self::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie()); + $storeCode = $this->storePathInfoValidator->getValidStoreCode($this->request); + + if (!$storeCode) { + $storeCode = $this->request->getParam( + \Magento\Store\Model\StoreManagerInterface::PARAM_NAME, + $this->storeCookieManager->getStoreCodeFromCookie() + ); + } + if (is_array($storeCode)) { if (!isset($storeCode['_data']['code'])) { throw new \InvalidArgumentException(__('Invalid store parameter.')); } $storeCode = $storeCode['_data']['code']; } + if ($storeCode) { try { $store = $this->getRequestedStoreByCode($storeCode); @@ -116,28 +133,21 @@ public function getCurrentStoreId() * * @return array */ - protected function getStoresData() + protected function getStoresData() : array { - $cacheKey = 'resolved_stores_' . md5($this->runMode . $this->scopeCode); - $cacheData = $this->cache->load($cacheKey); - if ($cacheData) { - $storesData = $this->getSerializer()->unserialize($cacheData); - } else { - $storesData = $this->readStoresData(); - $this->cache->save($this->getSerializer()->serialize($storesData), $cacheKey, [self::CACHE_TAG]); - } - return $storesData; + return $this->storesData->getStoresData($this->runMode, $this->scopeCode); } /** * Read stores data. First element is allowed store ids, second is default store id * * @return array + * @deprecated + * @see \Magento\Store\Model\StoreResolver::getStoresData */ - protected function readStoresData() + protected function readStoresData() : array { - $reader = $this->readerList->getReader($this->runMode); - return [$reader->getAllowedStoreIds($this->scopeCode), $reader->getDefaultStoreId($this->scopeCode)]; + return $this->getStoresData(); } /** @@ -147,7 +157,7 @@ protected function readStoresData() * @return \Magento\Store\Api\Data\StoreInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - protected function getRequestedStoreByCode($storeCode) + protected function getRequestedStoreByCode($storeCode) : \Magento\Store\Api\Data\StoreInterface { try { $store = $this->storeRepository->getActiveStoreByCode($storeCode); @@ -165,7 +175,7 @@ protected function getRequestedStoreByCode($storeCode) * @return \Magento\Store\Api\Data\StoreInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - protected function getDefaultStoreById($id) + protected function getDefaultStoreById($id) : \Magento\Store\Api\Data\StoreInterface { try { $store = $this->storeRepository->getActiveStoreById($id); @@ -175,19 +185,4 @@ protected function getDefaultStoreById($id) return $store; } - - /** - * Get serializer - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated 100.2.0 - */ - private function getSerializer() - { - if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); - } - return $this->serializer; - } } diff --git a/app/code/Magento/Store/Model/StoreResolver/Website.php b/app/code/Magento/Store/Model/StoreResolver/Website.php index 29f85716fea29..e314538099c8f 100644 --- a/app/code/Magento/Store/Model/StoreResolver/Website.php +++ b/app/code/Magento/Store/Model/StoreResolver/Website.php @@ -5,6 +5,9 @@ */ namespace Magento\Store\Model\StoreResolver; +/** + * Reader implementation for website. + */ class Website implements ReaderInterface { /** @@ -38,22 +41,25 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function getAllowedStoreIds($scopeCode) { $stores = []; $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault(); foreach ($this->storeRepository->getList() as $store) { - if ($store->isActive() && $store->getWebsiteId() == $website->getId()) { - $stores[] = $store->getId(); + if ($store->getIsActive()) { + if (($scopeCode && $store->getWebsiteId() == $website->getId()) || (!$scopeCode)) { + $stores[$store->getId()] = $store->getId(); + } } } + sort($stores); return $stores; } /** - * {@inheritdoc} + * @inheritdoc */ public function getDefaultStoreId($scopeCode) { diff --git a/app/code/Magento/Store/Model/StoresData.php b/app/code/Magento/Store/Model/StoresData.php new file mode 100644 index 0000000000000..b3d00bc97cd2e --- /dev/null +++ b/app/code/Magento/Store/Model/StoresData.php @@ -0,0 +1,77 @@ +cache = $cache; + $this->readerList = $readerList; + $this->serializer = $serializer; + } + + /** + * Get stores data + * + * @param string $runMode + * @param string|null $scopeCode + * @return array + */ + public function getStoresData(string $runMode, string $scopeCode = null) : array + { + $cacheKey = 'resolved_stores_' . md5($runMode . $scopeCode); + $cacheData = $this->cache->load($cacheKey); + if ($cacheData) { + $storesData = $this->serializer->unserialize($cacheData); + } else { + $reader = $this->readerList->getReader($runMode); + $storesData = [$reader->getAllowedStoreIds($scopeCode), $reader->getDefaultStoreId($scopeCode)]; + $this->cache->save( + $this->serializer->serialize($storesData), + $cacheKey, + [ + self::CACHE_TAG, + \Magento\Store\Model\Store::CACHE_TAG + ] + ); + } + return $storesData; + } +} diff --git a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php index 4a9b7d798c325..5d0f11b8a98d4 100644 --- a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php @@ -12,45 +12,83 @@ class PathInfoProcessorTest extends \PHPUnit\Framework\TestCase /** * @var \Magento\Store\App\Request\PathInfoProcessor */ - protected $_model; + private $model; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_storeManagerMock; + private $requestMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_requestMock; + private $validatorConfigMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $processorConfigMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $pathInfoMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $storeRepositoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $storePathInfoValidator; /** * @var string */ - protected $_pathInfo = '/storeCode/node_one/'; + protected $pathInfo = '/storeCode/node_one/'; protected function setUp() { - $this->_requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) + $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) + ->disableOriginalConstructor()->getMock(); + + $this->validatorConfigMock = $this->createMock(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + + $this->processorConfigMock = $this->createMock(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + + $this->storeRepositoryMock = $this->createMock(\Magento\Store\Api\StoreRepositoryInterface::class); + + $this->pathInfoMock = $this->getMockBuilder(\Magento\Framework\App\Request\PathInfo ::class) ->disableOriginalConstructor()->getMock(); - $this->_storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManager::class); - $this->_model = new \Magento\Store\App\Request\PathInfoProcessor($this->_storeManagerMock); + + $this->storePathInfoValidator = new \Magento\Store\App\Request\StorePathInfoValidator( + $this->validatorConfigMock, + $this->storeRepositoryMock, + $this->pathInfoMock + ); + + $this->model = new \Magento\Store\App\Request\PathInfoProcessor( + $this->storePathInfoValidator, + $this->validatorConfigMock + ); } public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName() { + $this->validatorConfigMock->expects($this->any())->method('getValue')->willReturn(true); + $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->_storeManagerMock->expects( - $this->once() + $this->storeRepositoryMock->expects( + $this->atLeastOnce() )->method( - 'getStore' + 'getActiveStoreByCode' )->with( 'storeCode' )->willReturn($store); - $store->expects($this->once())->method('getCode')->will($this->returnValue('storeCode')); - $store->expects($this->once())->method('isUseStoreInUrl')->will($this->returnValue(true)); - $this->_requestMock->expects( - $this->once() + $this->requestMock->expects( + $this->atLeastOnce() )->method( 'isDirectAccessFrontendName' )->with( @@ -58,67 +96,69 @@ public function testProcessIfStoreExistsAndIsNotDirectAccessToFrontName() )->will( $this->returnValue(false) ); - $this->_storeManagerMock->expects($this->once())->method('setCurrentStore')->with('storeCode'); - $this->assertEquals('/node_one/', $this->_model->process($this->_requestMock, $this->_pathInfo)); + $this->assertEquals('/node_one/', $this->model->process($this->requestMock, $this->pathInfo)); } public function testProcessIfStoreExistsAndDirectAccessToFrontName() { - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->_storeManagerMock->expects( - $this->once() + $this->validatorConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturn(true); + + $this->storeRepositoryMock->expects( + $this->any() )->method( - 'getStore' - )->with( - 'storeCode' - )->willReturn($store); - $store->expects($this->once())->method('isUseStoreInUrl')->will($this->returnValue(true)); - $this->_requestMock->expects( - $this->once() + 'getActiveStoreByCode' + ); + $this->requestMock->expects( + $this->atLeastOnce() )->method( 'isDirectAccessFrontendName' )->with( 'storeCode' - )->will( - $this->returnValue(true) - ); - $this->_requestMock->expects($this->once())->method('setActionName')->with('noroute'); - $this->assertEquals($this->_pathInfo, $this->_model->process($this->_requestMock, $this->_pathInfo)); + )->willReturn(true); + $this->requestMock->expects($this->once())->method('setActionName')->with('noroute'); + $this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo)); } public function testProcessIfStoreIsEmpty() { + $this->validatorConfigMock->expects($this->any())->method('getValue')->willReturn(true); + $path = '/0/node_one/'; - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->_storeManagerMock->expects( - $this->once() + $this->storeRepositoryMock->expects( + $this->never() )->method( - 'getStore' - )->with( - '0' - )->willReturn($store); - $store->expects($this->once())->method('isUseStoreInUrl')->will($this->returnValue(true)); - $this->_requestMock->expects( - $this->once() + 'getActiveStoreByCode' + ); + $this->requestMock->expects( + $this->never() )->method( 'isDirectAccessFrontendName' - )->with( - '0' - )->will( - $this->returnValue(true) ); - $this->_requestMock->expects($this->never())->method('setActionName'); - $this->assertEquals($path, $this->_model->process($this->_requestMock, $path)); + $this->requestMock->expects($this->never())->method('setActionName'); + $this->assertEquals($path, $this->model->process($this->requestMock, $path)); } public function testProcessIfStoreCodeIsNotExist() { - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->_storeManagerMock->expects($this->once())->method('getStore')->with('storeCode') + $this->validatorConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturn(true); + + $this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->with('storeCode') ->willThrowException(new NoSuchEntityException()); - $store->expects($this->never())->method('isUseStoreInUrl'); - $this->_requestMock->expects($this->never())->method('isDirectAccessFrontendName'); + $this->requestMock->expects($this->never())->method('isDirectAccessFrontendName'); + + $this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo)); + } + + public function testProcessIfStoreUrlNotEnabled() + { + $this->validatorConfigMock->expects($this->at(0))->method('getValue')->willReturn(true); + + $this->validatorConfigMock->expects($this->at(1))->method('getValue')->willReturn(true); + + $this->validatorConfigMock->expects($this->at(2))->method('getValue')->willReturn(false); + + $this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->willReturn(1); - $this->assertEquals($this->_pathInfo, $this->_model->process($this->_requestMock, $this->_pathInfo)); + $this->assertEquals($this->pathInfo, $this->model->process($this->requestMock, $this->pathInfo)); } } diff --git a/app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php b/app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php index 0454c0096a6ab..9f4be98ab5580 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php @@ -54,11 +54,6 @@ class StoreCookieTest extends \PHPUnit\Framework\TestCase */ protected $storeRepositoryMock; - /** - * @var \Magento\Store\Api\StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $storeResolverMock; - /** * Set up */ @@ -94,18 +89,12 @@ protected function setUp() ->setMethods([]) ->getMock(); - $this->storeResolverMock = $this->getMockBuilder(\Magento\Store\Api\StoreResolverInterface::class) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->plugin = (new ObjectManager($this))->getObject( \Magento\Store\Model\Plugin\StoreCookie::class, [ 'storeManager' => $this->storeManagerMock, 'storeCookieManager' => $this->storeCookieManagerMock, - 'storeRepository' => $this->storeRepositoryMock, - 'storeResolver' => $this->storeResolverMock + 'storeRepository' => $this->storeRepositoryMock ] ); } diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index 3d740bfee2093..be005264b7bbf 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -102,11 +102,15 @@ - Magento\Framework\App\Cache\Type\Config Magento\Store\Model\StoreManager::PARAM_RUN_TYPE Magento\Store\Model\StoreManager::PARAM_RUN_CODE + + + Magento\Framework\App\Cache\Type\Config + + Magento\Store\Model\StoreManager::PARAM_RUN_TYPE diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rate/Index.php b/app/code/Magento/Tax/Controller/Adminhtml/Rate/Index.php index b91eef7b6f70e..565af0e0bf93b 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Rate/Index.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rate/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Tax\Controller\Adminhtml\Rate; -class Index extends \Magento\Tax\Controller\Adminhtml\Rate +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Tax\Controller\Adminhtml\Rate implements HttpGetActionInterface { /** * Show Main Grid diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php index 71b6d7bf39396..1e46f0ea3d24a 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php @@ -6,9 +6,10 @@ */ namespace Magento\Tax\Controller\Adminhtml\Rule; +use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\ResultFactory; -class Delete extends \Magento\Tax\Controller\Adminhtml\Rule +class Delete extends \Magento\Tax\Controller\Adminhtml\Rule implements HttpPostActionInterface { /** * @return \Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php index dc0f518802520..740d7e8afe62c 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php @@ -6,9 +6,10 @@ */ namespace Magento\Tax\Controller\Adminhtml\Rule; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; -class Edit extends \Magento\Tax\Controller\Adminhtml\Rule +class Edit extends \Magento\Tax\Controller\Adminhtml\Rule implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Index.php b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Index.php index ddf6099a4f832..fd774777e3ef4 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Index.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Tax\Controller\Adminhtml\Rule; -class Index extends \Magento\Tax\Controller\Adminhtml\Rule +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Tax\Controller\Adminhtml\Rule implements HttpGetActionInterface { /** * @return \Magento\Backend\Model\View\Result\Page diff --git a/app/code/Magento/TaxImportExport/Controller/Adminhtml/Rate/ImportExport.php b/app/code/Magento/TaxImportExport/Controller/Adminhtml/Rate/ImportExport.php index 929c9db01a298..4264f5c3b7765 100644 --- a/app/code/Magento/TaxImportExport/Controller/Adminhtml/Rate/ImportExport.php +++ b/app/code/Magento/TaxImportExport/Controller/Adminhtml/Rate/ImportExport.php @@ -5,9 +5,10 @@ */ namespace Magento\TaxImportExport\Controller\Adminhtml\Rate; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\Controller\ResultFactory; -class ImportExport extends \Magento\TaxImportExport\Controller\Adminhtml\Rate +class ImportExport extends \Magento\TaxImportExport\Controller\Adminhtml\Rate implements HttpGetActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php index d51fd658075f1..1a136cca4d62a 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Index.php @@ -6,11 +6,13 @@ */ namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + /** * Class Index * @deprecated 100.2.0 */ -class Index extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme +class Index extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme implements HttpGetActionInterface { /** * Index action diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php b/app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php index 60d374fbf26ca..b45880c1ce726 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php @@ -5,6 +5,7 @@ */ namespace Magento\Ui\Controller\Adminhtml\Bookmark; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Authorization\Model\UserContextInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\Json\DecoderInterface; @@ -20,7 +21,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends AbstractAction +class Save extends AbstractAction implements HttpPostActionInterface { /** * Identifier for current bookmark diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php index fb99cef8e53cc..b983e56b8aee2 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php @@ -14,6 +14,11 @@ use Magento\Framework\Escaper; use Magento\Framework\Controller\Result\JsonFactory; +/** + * Render a component. + * + * @SuppressWarnings(PHPMD.AllPurposeAction) + */ class Render extends AbstractAction { /** diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render/Handle.php b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render/Handle.php index cc028a455456d..d1254790cb8eb 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Index/Render/Handle.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Index/Render/Handle.php @@ -5,6 +5,7 @@ */ namespace Magento\Ui\Controller\Adminhtml\Index\Render; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\View\Element\Template; use Magento\Ui\Component\Control\ActionPool; use Magento\Ui\Component\Wrapper\UiComponent; @@ -13,7 +14,7 @@ /** * Class Handle */ -class Handle extends AbstractAction +class Handle extends AbstractAction implements HttpGetActionInterface { /** * Render UI component by namespace in handle context diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/actions.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/actions.js index be7a1a13fbd61..c75f7797cf0f3 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/actions.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/actions.js @@ -11,8 +11,9 @@ define([ 'mageUtils', 'uiRegistry', './column', - 'Magento_Ui/js/modal/confirm' -], function (_, utils, registry, Column, confirm) { + 'Magento_Ui/js/modal/confirm', + 'mage/dataPost' +], function (_, utils, registry, Column, confirm, dataPost) { 'use strict'; return Column.extend({ @@ -267,7 +268,14 @@ define([ * @param {Object} action - Action's data. */ defaultCallback: function (actionIndex, recordId, action) { - window.location.href = action.href; + if (action.post) { + dataPost().postData({ + action: action.href, + data: {} + }); + } else { + window.location.href = action.href; + } }, /** diff --git a/app/code/Magento/UrlRewrite/Block/Edit.php b/app/code/Magento/UrlRewrite/Block/Edit.php index 115c5db43a70a..c8716f6c80f70 100644 --- a/app/code/Magento/UrlRewrite/Block/Edit.php +++ b/app/code/Magento/UrlRewrite/Block/Edit.php @@ -173,7 +173,7 @@ protected function _addDeleteButton() ['id' => $this->getUrlRewrite()->getId()] ) ) - . ')', + . ', {data: {}})', 'class' => 'scalable delete', 'level' => -1 ] @@ -243,7 +243,7 @@ private function _getSelectorBlock() * Since buttons are set as children, we remove them as children after generating them * not to duplicate them in future * - * @param string $area + * @param string|null $area * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ diff --git a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/CmsPageGrid.php b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/CmsPageGrid.php index 480efa8235716..7240dfc36f1e1 100644 --- a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/CmsPageGrid.php +++ b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/CmsPageGrid.php @@ -6,7 +6,11 @@ */ namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; -class CmsPageGrid extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; +use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite as RewriteAction; + +class CmsPageGrid extends RewriteAction implements HttpPostActionInterface, HttpGetActionInterface { /** * Ajax CMS pages grid action diff --git a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Delete.php b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Delete.php index f8f7b145e2806..dc49776a1ac00 100644 --- a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Delete.php +++ b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Delete.php @@ -6,7 +6,9 @@ */ namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; -class Delete extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite +use Magento\Framework\App\Action\HttpPostActionInterface; + +class Delete extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite implements HttpPostActionInterface { /** * URL rewrite delete action diff --git a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Edit.php b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Edit.php index b7ff92213003c..e2161f4ffd9bb 100644 --- a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Edit.php +++ b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Edit.php @@ -6,7 +6,9 @@ */ namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; -class Edit extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Edit extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite implements HttpGetActionInterface { /**#@+ * Modes diff --git a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Index.php b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Index.php index 066377ff7bd75..4f3a1e7849ec0 100644 --- a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Index.php +++ b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; -class Index extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite implements HttpGetActionInterface { /** * Show URL rewrites index page diff --git a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Save.php b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Save.php index 6325fe162d9e7..c508e85d87c3b 100644 --- a/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Save.php +++ b/app/code/Magento/UrlRewrite/Controller/Adminhtml/Url/Rewrite/Save.php @@ -7,11 +7,12 @@ namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\LocalizedException; use Magento\UrlRewrite\Model\UrlFinderInterface; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; -class Save extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite +class Save extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite implements HttpPostActionInterface { /** * @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator diff --git a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php index 488f1281ce30f..5bdaf36272536 100644 --- a/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php +++ b/app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php @@ -75,7 +75,7 @@ public function resolve( if ($urlRewrite) { $result = [ 'id' => $urlRewrite->getEntityId(), - 'canonical_url' => $urlRewrite->getTargetPath(), + 'relative_url' => $urlRewrite->getTargetPath(), 'type' => $this->sanitizeType($urlRewrite->getEntityType()) ]; } diff --git a/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls b/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls index 38f1d9c65637c..e9a39617774c0 100644 --- a/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/UrlRewriteGraphQl/etc/schema.graphqls @@ -1,14 +1,14 @@ # Copyright © Magento, Inc. All rights reserved. # See COPYING.txt for license details. -type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `canonical_url`, and `type` attributes") { +type EntityUrl @doc(description: "EntityUrl is an output object containing the `id`, `relative_url`, and `type` attributes") { id: Int @doc(description: "The ID assigned to the object associated with the specified url. This could be a product ID, category ID, or page ID.") - canonical_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.") + relative_url: String @doc(description: "The internal relative URL. If the specified url is a redirect, the query returns the redirected URL, not the original.") type: UrlRewriteEntityTypeEnum @doc(description: "One of PRODUCT, CATEGORY, or CMS_PAGE.") } type Query { - urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite") @doc(description: "The urlResolver query returns the canonical URL for a specified product, category or CMS page") + urlResolver(url: String!): EntityUrl @resolver(class: "Magento\\UrlRewriteGraphQl\\Model\\Resolver\\UrlRewrite") @doc(description: "The urlResolver query returns the relative URL for a specified product, category or CMS page") } enum UrlRewriteEntityTypeEnum { diff --git a/app/code/Magento/User/Controller/Adminhtml/Locks/Index.php b/app/code/Magento/User/Controller/Adminhtml/Locks/Index.php index 7c0e31076cace..e3e1e3def3985 100644 --- a/app/code/Magento/User/Controller/Adminhtml/Locks/Index.php +++ b/app/code/Magento/User/Controller/Adminhtml/Locks/Index.php @@ -6,10 +6,12 @@ */ namespace Magento\User\Controller\Adminhtml\Locks; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + /** * Locks Index action */ -class Index extends \Magento\User\Controller\Adminhtml\Locks +class Index extends \Magento\User\Controller\Adminhtml\Locks implements HttpGetActionInterface { /** * Render page with grid diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Index.php b/app/code/Magento/User/Controller/Adminhtml/User/Index.php index 7f79dd4773731..bc4157c144a87 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Index.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\User\Controller\Adminhtml\User; -class Index extends \Magento\User\Controller\Adminhtml\User +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\User\Controller\Adminhtml\User implements HttpGetActionInterface { /** * @return void diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Role/Index.php b/app/code/Magento/User/Controller/Adminhtml/User/Role/Index.php index e1853be17a128..8d468d45f1aee 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Role/Index.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Role/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\User\Controller\Adminhtml\User\Role; -class Index extends \Magento\User\Controller\Adminhtml\User\Role +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\User\Controller\Adminhtml\User\Role implements HttpGetActionInterface { /** * Show grid with roles existing in systems diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Role/RoleGrid.php b/app/code/Magento/User/Controller/Adminhtml/User/Role/RoleGrid.php index 4d97b62cd8b14..ad8c87b617d52 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Role/RoleGrid.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Role/RoleGrid.php @@ -6,7 +6,11 @@ */ namespace Magento\User\Controller\Adminhtml\User\Role; -class RoleGrid extends \Magento\User\Controller\Adminhtml\User\Role +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\User\Controller\Adminhtml\User\Role as RoleAction; + +class RoleGrid extends RoleAction implements HttpGetActionInterface, HttpPostActionInterface { /** * Action for ajax request from grid diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php b/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php index 9dfe34e435385..44862f1fce2a0 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php @@ -7,6 +7,7 @@ namespace Magento\User\Controller\Adminhtml\User\Role; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Authorization\Model\Acl\Role\Group as RoleGroup; use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Controller\ResultFactory; @@ -16,7 +17,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class SaveRole extends \Magento\User\Controller\Adminhtml\User\Role +class SaveRole extends \Magento\User\Controller\Adminhtml\User\Role implements HttpPostActionInterface { /** * Session keys for Info form data diff --git a/app/code/Magento/User/Controller/Adminhtml/User/RoleGrid.php b/app/code/Magento/User/Controller/Adminhtml/User/RoleGrid.php index 2bfbadd3a0d5f..e171f0a8c2bc8 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/RoleGrid.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/RoleGrid.php @@ -6,7 +6,11 @@ */ namespace Magento\User\Controller\Adminhtml\User; -class RoleGrid extends \Magento\User\Controller\Adminhtml\User +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\User\Controller\Adminhtml\User as UserAction; + +class RoleGrid extends UserAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @return void diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Save.php b/app/code/Magento/User/Controller/Adminhtml/User/Save.php index 4b984b761c1fe..09061384a8e61 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Save.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Save.php @@ -6,6 +6,7 @@ namespace Magento\User\Controller\Adminhtml\User; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\Exception\AuthenticationException; use Magento\Framework\Exception\State\UserLockedException; use Magento\Security\Model\SecurityCookie; @@ -13,7 +14,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\User\Controller\Adminhtml\User +class Save extends \Magento\User\Controller\Adminhtml\User implements HttpPostActionInterface { /** * @var SecurityCookie @@ -44,10 +45,14 @@ public function execute() { $userId = (int)$this->getRequest()->getParam('user_id'); $data = $this->getRequest()->getPostValue(); + if (array_key_exists('form_key', $data)) { + unset($data['form_key']); + } if (!$data) { $this->_redirect('adminhtml/*/'); return; } + /** @var $model \Magento\User\Model\User */ $model = $this->_userFactory->create()->load($userId); if ($userId && $model->isObjectNew()) { diff --git a/app/code/Magento/Variable/Controller/Adminhtml/System/Variable/Index.php b/app/code/Magento/Variable/Controller/Adminhtml/System/Variable/Index.php index f70cb31eb545f..71cb76a67d15d 100644 --- a/app/code/Magento/Variable/Controller/Adminhtml/System/Variable/Index.php +++ b/app/code/Magento/Variable/Controller/Adminhtml/System/Variable/Index.php @@ -6,12 +6,14 @@ */ namespace Magento\Variable\Controller\Adminhtml\System\Variable; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + /** * Display Variables list page * @api * @since 100.0.2 */ -class Index extends \Magento\Variable\Controller\Adminhtml\System\Variable +class Index extends \Magento\Variable\Controller\Adminhtml\System\Variable implements HttpGetActionInterface { /** * Index Action diff --git a/app/code/Magento/Version/Controller/Index/Index.php b/app/code/Magento/Version/Controller/Index/Index.php index c5d02cd9a1fd2..0db9b5f80d483 100644 --- a/app/code/Magento/Version/Controller/Index/Index.php +++ b/app/code/Magento/Version/Controller/Index/Index.php @@ -6,6 +6,7 @@ */ namespace Magento\Version\Controller\Index; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ProductMetadataInterface; @@ -13,7 +14,7 @@ /** * Magento Version controller */ -class Index extends Action +class Index extends Action implements HttpGetActionInterface { /** * @var ProductMetadataInterface diff --git a/app/code/Magento/Webapi/Controller/PathProcessor.php b/app/code/Magento/Webapi/Controller/PathProcessor.php index 5e8c23aa15506..c5748cc6e848e 100644 --- a/app/code/Magento/Webapi/Controller/PathProcessor.php +++ b/app/code/Magento/Webapi/Controller/PathProcessor.php @@ -8,6 +8,9 @@ use Magento\Framework\Exception\NoSuchEntityException; +/** + * Class PathProcessor + */ class PathProcessor { /** Store code alias to indicate that all stores should be affected by action */ @@ -50,7 +53,7 @@ private function stripPathBeforeStorecode($pathInfo) public function process($pathInfo) { $pathParts = $this->stripPathBeforeStorecode($pathInfo); - $storeCode = $pathParts[0]; + $storeCode = current($pathParts); $stores = $this->storeManager->getStores(false, true); if (isset($stores[$storeCode])) { $this->storeManager->setCurrentStore($storeCode); diff --git a/app/code/Magento/Widget/Controller/Adminhtml/Widget/BuildWidget.php b/app/code/Magento/Widget/Controller/Adminhtml/Widget/BuildWidget.php index d9ef20aa90e47..0b9431f717e0a 100644 --- a/app/code/Magento/Widget/Controller/Adminhtml/Widget/BuildWidget.php +++ b/app/code/Magento/Widget/Controller/Adminhtml/Widget/BuildWidget.php @@ -6,7 +6,9 @@ */ namespace Magento\Widget\Controller\Adminhtml\Widget; -class BuildWidget extends \Magento\Backend\App\Action +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class BuildWidget extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Index.php b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Index.php index 61e44fe00db61..e7454faf925a6 100644 --- a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Index.php +++ b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Widget\Controller\Adminhtml\Widget; -class Index extends \Magento\Backend\App\Action +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Index extends \Magento\Backend\App\Action implements HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Index.php b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Index.php index 40ade57f6a9e9..50f3addaf7c59 100644 --- a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Index.php +++ b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Index.php @@ -6,7 +6,9 @@ */ namespace Magento\Widget\Controller\Adminhtml\Widget\Instance; -class Index extends \Magento\Widget\Controller\Adminhtml\Widget\Instance +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; + +class Index extends \Magento\Widget\Controller\Adminhtml\Widget\Instance implements HttpGetActionInterface { /** * Widget Instances Grid diff --git a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Save.php b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Save.php index b5d31dc10be34..dc137365498b2 100644 --- a/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Save.php +++ b/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Save.php @@ -6,7 +6,9 @@ */ namespace Magento\Widget\Controller\Adminhtml\Widget\Instance; -class Save extends \Magento\Widget\Controller\Adminhtml\Widget\Instance +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; + +class Save extends \Magento\Widget\Controller\Adminhtml\Widget\Instance implements HttpPostActionInterface { /** * Save action diff --git a/app/code/Magento/Widget/Controller/Adminhtml/Widget/LoadOptions.php b/app/code/Magento/Widget/Controller/Adminhtml/Widget/LoadOptions.php index 054019079ebaa..03d9d10311382 100644 --- a/app/code/Magento/Widget/Controller/Adminhtml/Widget/LoadOptions.php +++ b/app/code/Magento/Widget/Controller/Adminhtml/Widget/LoadOptions.php @@ -6,9 +6,11 @@ */ namespace Magento\Widget\Controller\Adminhtml\Widget; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\ObjectManager; -class LoadOptions extends \Magento\Backend\App\Action +class LoadOptions extends \Magento\Backend\App\Action implements HttpGetActionInterface, HttpPostActionInterface { /** * Authorization level of a basic admin session diff --git a/app/code/Magento/Wishlist/Helper/Data.php b/app/code/Magento/Wishlist/Helper/Data.php index f4c1aa9662bda..3b9f431566da0 100644 --- a/app/code/Magento/Wishlist/Helper/Data.php +++ b/app/code/Magento/Wishlist/Helper/Data.php @@ -195,6 +195,7 @@ public function getWishlist() /** * Retrieve wishlist item count (include config settings) + * * Used in top link menu only * * @return int @@ -450,6 +451,8 @@ public function getSharedAddAllToCartUrl() } /** + * Get cart URL parameters + * * @param string|\Magento\Catalog\Model\Product|\Magento\Wishlist\Model\Item $item * @return array */ @@ -576,7 +579,7 @@ public function calculate() ) { $count = $collection->getItemsQty(); } else { - $count = $collection->getSize(); + $count = $collection->count(); } $this->_customerSession->setWishlistDisplayType( $this->scopeConfig->getValue( diff --git a/app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php b/app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php index 225026f31a994..b285270c67ef8 100644 --- a/app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php +++ b/app/code/Magento/Wishlist/Model/ResourceModel/Item/Collection.php @@ -307,6 +307,7 @@ protected function _assignProducts() $checkInStock = $this->_productInStock && !$this->stockConfiguration->isShowOutOfStock(); + /** @var \Magento\Wishlist\Model\Item $item */ foreach ($this as $item) { $product = $productCollection->getItemById($item->getProductId()); if ($product) { @@ -320,7 +321,7 @@ protected function _assignProducts() $item->setPrice($product->getPrice()); } } else { - $item->isDeleted(true); + $this->removeItemByKey($item->getId()); } } @@ -418,6 +419,7 @@ public function setVisibilityFilter($flag = true) /** * Set Salable Filter. + * * This filter apply Salable Product Types Filter to product collection. * * @param bool $flag @@ -431,6 +433,7 @@ public function setSalableFilter($flag = true) /** * Set In Stock Filter. + * * This filter remove items with no salable product. * * @param bool $flag @@ -567,6 +570,8 @@ public function getItemsQty() } /** + * After load data + * * @return $this */ protected function _afterLoadData() diff --git a/app/code/Magento/Wishlist/Model/Wishlist.php b/app/code/Magento/Wishlist/Model/Wishlist.php index ec0021c4949ea..9797ab58b0766 100644 --- a/app/code/Magento/Wishlist/Model/Wishlist.php +++ b/app/code/Magento/Wishlist/Model/Wishlist.php @@ -380,6 +380,7 @@ public function addItem(Item $item) /** * Adds new product to wishlist. + * * Returns new item or string on error. * * @param int|\Magento\Catalog\Model\Product $product @@ -581,7 +582,7 @@ public function setStore($store) */ public function getItemsCount() { - return $this->getItemCollection()->getSize(); + return $this->getItemCollection()->count(); } /** diff --git a/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontCustomerWishlistActionGroup.xml b/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontCustomerWishlistActionGroup.xml index c4b3763af9b97..7bb42e12d1451 100644 --- a/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontCustomerWishlistActionGroup.xml +++ b/app/code/Magento/Wishlist/Test/Mftf/ActionGroup/StorefrontCustomerWishlistActionGroup.xml @@ -25,6 +25,7 @@ + diff --git a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml index 8ea82490a63f9..145fb94f356f7 100644 --- a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml +++ b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml @@ -87,15 +87,12 @@ - - - diff --git a/app/design/adminhtml/Magento/backend/Magento_Backend/web/images/logo-magento.png b/app/design/adminhtml/Magento/backend/Magento_Backend/web/images/logo-magento.png index d9395c938cbff..0cca183e08da2 100644 Binary files a/app/design/adminhtml/Magento/backend/Magento_Backend/web/images/logo-magento.png and b/app/design/adminhtml/Magento/backend/Magento_Backend/web/images/logo-magento.png differ diff --git a/app/design/adminhtml/Magento/backend/web/css/source/components/_calendar-temp.less b/app/design/adminhtml/Magento/backend/web/css/source/components/_calendar-temp.less index 11b187db3d1e4..5ba18af6b0547 100644 --- a/app/design/adminhtml/Magento/backend/web/css/source/components/_calendar-temp.less +++ b/app/design/adminhtml/Magento/backend/web/css/source/components/_calendar-temp.less @@ -43,7 +43,7 @@ height: @action__height; margin-left: -@action__height; overflow: hidden; - position: absolute; + position: relative; vertical-align: top; z-index: 1; diff --git a/app/design/frontend/Magento/blank/web/images/logo.svg b/app/design/frontend/Magento/blank/web/images/logo.svg index 013d6e7c5a107..e4f627809b627 100644 --- a/app/design/frontend/Magento/blank/web/images/logo.svg +++ b/app/design/frontend/Magento/blank/web/images/logo.svg @@ -1 +1 @@ - \ No newline at end of file +Magento-an-Adobe-Company-logo-horizontal diff --git a/app/etc/di.xml b/app/etc/di.xml index 8e050dec6eb87..db979f9b76382 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -206,8 +206,6 @@ - @@ -1695,4 +1693,32 @@ Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT + + + + + CsrfRequestValidator + + Magento\Framework\App\Request\HttpMethodValidator + + + + + + + + + \Magento\Framework\App\Action\HttpOptionsActionInterface + \Magento\Framework\App\Action\HttpGetActionInterface + \Magento\Framework\App\Action\HttpHeadActionInterface + \Magento\Framework\App\Action\HttpPostActionInterface + \Magento\Framework\App\Action\HttpPutActionInterface + \Magento\Framework\App\Action\HttpPatchActionInterface + \Magento\Framework\App\Action\HttpDeleteActionInterface + \Magento\Framework\App\Action\HttpConnectActionInterface + \Magento\Framework\App\Action\HttpPropfindActionInterface + \Magento\Framework\App\Action\HttpTraceActionInterface + + + diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php new file mode 100644 index 0000000000000..ede719bb569ba --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CustomerChangePasswordTest.php @@ -0,0 +1,147 @@ +customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); + $this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class); + $this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testCustomerChangeValidPassword() + { + $customerEmail = 'customer@example.com'; + $oldCustomerPassword = 'password'; + $newCustomerPassword = 'anotherPassword1'; + + $query = $this->getChangePassQuery($oldCustomerPassword, $newCustomerPassword); + $headerMap = $this->getCustomerAuthHeaders($customerEmail, $oldCustomerPassword); + + $response = $this->graphQlQuery($query, [], '', $headerMap); + $this->assertEquals($customerEmail, $response['changeCustomerPassword']['email']); + + try { + // registry contains the old password hash so needs to be reset + $this->customerRegistry->removeByEmail($customerEmail); + $this->accountManagement->authenticate($customerEmail, $newCustomerPassword); + } catch (LocalizedException $e) { + $this->fail('Password was not changed: ' . $e->getMessage()); + } + } + + public function testGuestUserCannotChangePassword() + { + $query = $this->getChangePassQuery('currentpassword', 'newpassword'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage( + 'GraphQL response contains errors: Current customer' . ' ' . + 'does not have access to the resource "customer"' + ); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testChangeWeakPassword() + { + $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/190'); + $customerEmail = 'customer@example.com'; + $oldCustomerPassword = 'password'; + $newCustomerPassword = 'weakpass'; + + $query = $this->getChangePassQuery($oldCustomerPassword, $newCustomerPassword); + $headerMap = $this->getCustomerAuthHeaders($customerEmail, $oldCustomerPassword); + + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/Minimum of different classes of characters in password is.*/'); + + $this->graphQlQuery($query, [], '', $headerMap); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testCannotChangeWithIncorrectPassword() + { + $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/190'); + $customerEmail = 'customer@example.com'; + $oldCustomerPassword = 'password'; + $newCustomerPassword = 'anotherPassword1'; + $incorrectPassword = 'password-incorrect'; + + $query = $this->getChangePassQuery($incorrectPassword, $newCustomerPassword); + + // acquire authentication with correct password + $headerMap = $this->getCustomerAuthHeaders($customerEmail, $oldCustomerPassword); + + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('/The password doesn\'t match this account. Verify the password.*/'); + + // but try to change with incorrect 'old' password + $this->graphQlQuery($query, [], '', $headerMap); + } + + private function getChangePassQuery($currentPassword, $newPassword) + { + $query = <<customerTokenService->createCustomerAccessToken($email, $password); + return ['Authorization' => 'Bearer ' . $customerToken]; + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php new file mode 100644 index 0000000000000..ae28e23a28bf1 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php @@ -0,0 +1,71 @@ +graphQlQuery($mutation); + $this->assertArrayHasKey('generateCustomerToken', $response); + $this->assertInternalType('array', $response['generateCustomerToken']); + } + + /** + * Verify customer with invalid credentials + */ + public function testGenerateCustomerTokenWithInvalidCredentials() + { + $userName = 'customer@example.com'; + $password = 'bad-password'; + + $mutation + = <<expectException(\Exception::class); + $this->expectExceptionMessage('GraphQL response contains errors: The account sign-in' . ' ' . + 'was incorrect or your account is disabled temporarily. Please wait and try again later.'); + $this->graphQlQuery($mutation); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CouponTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CouponTest.php new file mode 100644 index 0000000000000..1f8ad06a9f8ed --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CouponTest.php @@ -0,0 +1,225 @@ +quoteResource = $objectManager->create(QuoteResource::class); + $this->quote = $objectManager->create(Quote::class); + $this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + */ + public function testApplyCouponToGuestCartWithItems() + { + $couponCode = '2?ds5!2d'; + + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey("applyCouponToCart", $response); + self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + */ + public function testApplyCouponTwice() + { + $couponCode = '2?ds5!2d'; + + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey("applyCouponToCart", $response); + self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']); + + self::expectExceptionMessage('A coupon is already applied to the cart. Please remove it to apply another'); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + */ + public function testApplyCouponToCartWithNoItems() + { + $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/191'); + $couponCode = '2?ds5!2d'; + + $this->quoteResource->load($this->quote, 'test_order_1', 'reserved_order_id'); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode); + + self::expectExceptionMessageRegExp('/Cart doesn\'t contain products/'); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testGuestCustomerAttemptToChangeCustomerCart() + { + $couponCode = '2?ds5!2d'; + + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $this->quote->setCustomerId(1); + $this->quoteResource->save($this->quote); + $query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode); + + self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"'); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + */ + public function testRemoveCoupon() + { + $couponCode = '2?ds5!2d'; + + /* Apply coupon to the quote */ + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $query = $this->prepareAddCouponRequestQuery($maskedQuoteId, $couponCode); + $this->graphQlQuery($query); + + /* Remove coupon from quote */ + $query = $this->prepareRemoveCouponRequestQuery($maskedQuoteId); + $response = $this->graphQlQuery($query); + + self::assertArrayHasKey('removeCouponFromCart', $response); + self::assertSame('', $response['removeCouponFromCart']['cart']['applied_coupon']['code']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testRemoveCouponFromCustomerCartByGuest() + { + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); + $this->quoteResource->load( + $this->quote, + 'test_order_with_simple_product_without_address', + 'reserved_order_id' + ); + $this->quote->setCustomerId(1); + $this->quoteResource->save($this->quote); + $query = $this->prepareRemoveCouponRequestQuery($maskedQuoteId); + + self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"'); + $this->graphQlQuery($query); + } + + /** + * @param string $maskedQuoteId + * @param string $couponCode + * @return string + */ + private function prepareAddCouponRequestQuery(string $maskedQuoteId, string $couponCode): string + { + return <<graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } /** - * Tests the use case where canonical_url is provided as resolver input in the Query + * Tests the use case where relative_url is provided as resolver input in the Query * * @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php */ @@ -101,7 +104,7 @@ public function testProductUrlWithCanonicalUrlInput() urlResolver(url:"{$canonicalPath}") { id - canonical_url + relative_url type } } @@ -109,7 +112,7 @@ public function testProductUrlWithCanonicalUrlInput() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -144,7 +147,7 @@ public function testCategoryUrlResolver() urlResolver(url:"{$urlPath2}") { id - canonical_url + relative_url type } } @@ -152,7 +155,7 @@ public function testCategoryUrlResolver() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($categoryId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -180,14 +183,14 @@ public function testCMSPageUrlResolver() urlResolver(url:"{$requestPath}") { id - canonical_url + relative_url type } } QUERY; $response = $this->graphQlQuery($query); $this->assertEquals($cmsPageId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper(str_replace('-', '_', $expectedEntityType)), $response['urlResolver']['type']); } @@ -223,7 +226,7 @@ public function testProductUrlRewriteResolver() urlResolver(url:"{$urlPath}") { id - canonical_url + relative_url type } } @@ -231,7 +234,7 @@ public function testProductUrlRewriteResolver() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($product->getEntityId(), $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -263,7 +266,7 @@ public function testInvalidUrlResolverInput() urlResolver(url:"{$urlPath}") { id - canonical_url + relative_url type } } @@ -304,7 +307,7 @@ public function testCategoryUrlWithLeadingSlash() urlResolver(url:"/{$urlPath}") { id - canonical_url + relative_url type } } @@ -312,7 +315,7 @@ public function testCategoryUrlWithLeadingSlash() $response = $this->graphQlQuery($query); $this->assertArrayHasKey('urlResolver', $response); $this->assertEquals($categoryId, $response['urlResolver']['id']); - $this->assertEquals($targetPath, $response['urlResolver']['canonical_url']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals(strtoupper($expectedType), $response['urlResolver']['type']); } @@ -321,22 +324,35 @@ public function testCategoryUrlWithLeadingSlash() */ public function testResolveSlash() { + /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface */ + $scopeConfigInterface = $this->objectManager->get(ScopeConfigInterface::class); + $homePageIdentifier = $scopeConfigInterface->getValue( + PageHelper::XML_PATH_HOME_PAGE, + ScopeInterface::SCOPE_STORE + ); + /** @var \Magento\Cms\Model\Page $page */ + $page = $this->objectManager->get(\Magento\Cms\Model\Page::class); + $page->load($homePageIdentifier); + $homePageId = $page->getId(); + /** @var \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $urlPathGenerator */ + $urlPathGenerator = $this->objectManager->get(\Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator::class); + /** @param \Magento\Cms\Api\Data\PageInterface $page */ + $targetPath = $urlPathGenerator->getCanonicalUrlPath($page); $query = <<graphQlQuery($query); - $this->assertArrayHasKey('urlResolver', $response); - $this->assertEquals(2, $response['urlResolver']['id']); - $this->assertEquals('cms/page/view/page_id/2', $response['urlResolver']['canonical_url']); + $this->assertEquals($homePageId, $response['urlResolver']['id']); + $this->assertEquals($targetPath, $response['urlResolver']['relative_url']); $this->assertEquals('CMS_PAGE', $response['urlResolver']['type']); } } diff --git a/dev/tests/functional/lib/Magento/Mtf/Constraint/AbstractAssertForm.php b/dev/tests/functional/lib/Magento/Mtf/Constraint/AbstractAssertForm.php index eb04450d5261d..61e5b7649303f 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Constraint/AbstractAssertForm.php +++ b/dev/tests/functional/lib/Magento/Mtf/Constraint/AbstractAssertForm.php @@ -53,7 +53,7 @@ protected function verifyData(array $fixtureData, array $formData, $isStrict = f } $formValue = isset($formData[$key]) ? $formData[$key] : null; if (is_numeric($formValue)) { - $formValue = floatval($formValue); + $formValue = (float)$formValue; } if (null === $formValue) { @@ -118,6 +118,7 @@ protected function sortData(array $data) /** * Sort multidimensional array by paths. + * * Pattern path: key/subKey::sortKey. * Example: * $data = [ @@ -150,7 +151,6 @@ protected function sortData(array $data) * * @param array $data * @param string $path - * @param string $path * @return array * @throws \Exception * diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Ui/LoginUser.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Ui/LoginUser.php index 3738f51ef6c6a..01d8401b22fe1 100644 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Ui/LoginUser.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Ui/LoginUser.php @@ -6,6 +6,7 @@ namespace Magento\Backend\Test\Handler\Ui; +use Magento\Backend\Test\Page\AdminAuthLogin; use Magento\Mtf\Factory\Factory; use Magento\Mtf\Fixture\FixtureInterface; use Magento\Mtf\Handler\Ui; @@ -29,10 +30,15 @@ public function persist(FixtureInterface $fixture = null) $fixture = Factory::getFixtureFactory()->getMagentoBackendAdminSuperAdmin(); } + /** @var AdminAuthLogin $loginPage */ $loginPage = Factory::getPageFactory()->getAdminAuthLogin(); $loginForm = $loginPage->getLoginBlock(); - $adminHeaderPanel = $loginPage->getHeaderBlock(); + if (!$loginForm->isVisible() && !$adminHeaderPanel->isVisible()) { + //We are currently not in the admin area. + $loginPage->open(); + } + if (!$adminHeaderPanel || !$adminHeaderPanel->isVisible()) { $loginPage->open(); if ($adminHeaderPanel->isVisible()) { diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View/CustomOptions.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View/CustomOptions.php index 9f05a4ade8a37..dcc8cce970098 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View/CustomOptions.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View/CustomOptions.php @@ -231,7 +231,7 @@ protected function getFieldData(SimpleElement $option) return [ 'options' => [ [ - 'price' => floatval($price), + 'price' => (float)$price, 'max_characters' => $maxCharacters, ], ] @@ -262,7 +262,7 @@ protected function getFileData(SimpleElement $option) return [ 'options' => [ [ - 'price' => floatval($price), + 'price' => (float)$price, 'file_extension' => $this->getOptionNotice($option, 1), 'image_size_x' => preg_replace('/[^0-9]/', '', $this->getOptionNotice($option, 2)), 'image_size_y' => preg_replace('/[^0-9]/', '', $this->getOptionNotice($option, 3)), @@ -344,7 +344,7 @@ protected function getDateData(SimpleElement $option) return [ 'options' => [ [ - 'price' => floatval($price), + 'price' => (float)$price, ], ] ]; diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.php index 5e871bf6d97a5..707a62a446054 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.php @@ -10,6 +10,7 @@ use Magento\Catalog\Test\Page\Adminhtml\CatalogProductNew; use Magento\Mtf\Fixture\FixtureFactory; use Magento\Mtf\TestCase\Injectable; +use Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Section\Downloadable; /** * Test Creation for ProductTypeSwitchingOnCreation @@ -75,18 +76,49 @@ public function __inject( * * @param string $createProduct * @param string $product + * @param string $actionName * @return array */ - public function test($createProduct, $product) + public function test(string $createProduct, string $product, string $actionName = null): array { // Steps list($fixture, $dataset) = explode('::', $product); $product = $this->fixtureFactory->createByCode($fixture, ['dataset' => $dataset]); $this->catalogProductIndex->open(); $this->catalogProductIndex->getGridPageActionBlock()->addProduct($createProduct); + if ($actionName) { + $this->performAction($actionName); + } $this->catalogProductNew->getProductForm()->fill($product); $this->catalogProductNew->getFormPageActions()->save($product); return ['product' => $product]; } + + /** + * Perform action. + * + * @param string $actionName + * @return void + */ + private function performAction(string $actionName): void + { + if (method_exists(__CLASS__, $actionName)) { + $this->$actionName(); + } + } + + /** + * Clear downloadable product data. + * + * @return void + */ + private function clearDownloadableData(): void + { + $this->catalogProductNew->getProductForm()->openSection('downloadable_information'); + /** @var Downloadable $downloadableInfoTab */ + $downloadableInfoTab = $this->catalogProductNew->getProductForm()->getSection('downloadable_information'); + $downloadableInfoTab->getDownloadableBlock('Links')->clearDownloadableData(); + $downloadableInfoTab->setIsDownloadable('No'); + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.xml index f45fbc96a738d..7c4824c604e29 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/ProductTypeSwitchingOnCreationTest.xml @@ -76,7 +76,7 @@ downloadable configurableProduct::not_virtual_for_type_switching - to_maintain:yes + clearDownloadableData diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Constraint/AssertCatalogPriceRuleForm.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Constraint/AssertCatalogPriceRuleForm.php index 7db32337b995d..17739f5524e13 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Constraint/AssertCatalogPriceRuleForm.php +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Constraint/AssertCatalogPriceRuleForm.php @@ -42,10 +42,10 @@ public function processAssert( $fixtureData = $catalogPriceRule->getData(); //convert discount_amount to float to compare if (isset($formData['discount_amount'])) { - $formData['discount_amount'] = floatval($formData['discount_amount']); + $formData['discount_amount'] = (float)$formData['discount_amount']; } if (isset($fixtureData['discount_amount'])) { - $fixtureData['discount_amount'] = floatval($fixtureData['discount_amount']); + $fixtureData['discount_amount'] = (float)$fixtureData['discount_amount']; } $diff = $this->verifyData($formData, $fixtureData); \PHPUnit\Framework\Assert::assertTrue( diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Downloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Downloadable.php index ebc19eec9ad53..d78a2d94e7635 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Downloadable.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Downloadable.php @@ -104,4 +104,21 @@ public function setFieldsData(array $fields, SimpleElement $element = null) return $this; } + + /** + * Set "Is this downloadable Product?" value. + * + * @param string $downloadable + * @param SimpleElement|null $element + * @return void + */ + public function setIsDownloadable(string $downloadable = 'Yes', SimpleElement $element = null): void + { + $context = $element ?: $this->_rootElement; + $isDownloadable = $context->find($this->isDownloadableProduct); + $value = 'Yes' == $downloadable ? '1' : '0'; + if ($isDownloadable->isVisible() && $isDownloadable->getAttribute('value') != $value) { + $isDownloadable->click(); + } + } } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Webapi.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Webapi.php index 434c78e55c69b..d14d6754b12ec 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Webapi.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/DownloadableProduct/Webapi.php @@ -148,7 +148,7 @@ protected function prepareLinkData(array $link) 'title' => $link['title'], 'sort_order' => isset($link['sort_order']) ? $link['sort_order'] : 0, 'is_shareable' => $link['is_shareable'], - 'price' => floatval($link['price']), + 'price' => (float)$link['price'], 'number_of_downloads' => isset($link['number_of_downloads']) ? $link['number_of_downloads'] : 0, 'link_type' => $link['type'], 'link_url' => isset($link['link_url']) ? $link['link_url'] : null, diff --git a/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportIntervalResult.php b/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportIntervalResult.php index 745450aa2c024..1236a86e160b6 100644 --- a/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportIntervalResult.php +++ b/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportIntervalResult.php @@ -52,7 +52,7 @@ protected function prepareSalesResult($salesResult) { $data = []; foreach ($salesResult as $key => $result) { - $data[$key] = floatval($result); + $data[$key] = (float)$result; } return $data; diff --git a/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportTotalResult.php b/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportTotalResult.php index 5f435e4822904..423ca6dafbdde 100644 --- a/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportTotalResult.php +++ b/dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertSalesReportTotalResult.php @@ -52,7 +52,7 @@ protected function prepareSalesResult($salesResult) { $data = []; foreach ($salesResult as $key => $result) { - $data[$key] = floatval($result); + $data[$key] = (float)$result; } return $data; diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php index 543bac2c6b5b5..b2e0b57bae729 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php @@ -5,10 +5,12 @@ */ namespace Magento\TestFramework\TestCase; +use Magento\Framework\App\Request\Http as HttpRequest; + /** - * A parent class for backend controllers - contains directives for admin user creation and authentication + * A parent class for backend controllers - contains directives for admin user creation and authentication. + * * @SuppressWarnings(PHPMD.NumberOfChildren) - * @SuppressWarnings(PHPMD.numberOfChildren) */ abstract class AbstractBackendController extends \Magento\TestFramework\TestCase\AbstractController { @@ -36,6 +38,16 @@ abstract class AbstractBackendController extends \Magento\TestFramework\TestCase */ protected $uri = null; + /** + * @var string|null + */ + protected $httpMethod; + + /** + * @inheritDoc + * + * @throws \Magento\Framework\Exception\AuthenticationException + */ protected function setUp() { parent::setUp(); @@ -62,6 +74,9 @@ protected function _getAdminCredentials() ]; } + /** + * @inheritDoc + */ protected function tearDown() { $this->_auth->getAuthStorage()->destroy(['send_expire_cookie' => false]); @@ -86,21 +101,33 @@ public function assertSessionMessages( parent::assertSessionMessages($constraint, $messageType, $messageManagerClass); } + /** + * Test ACL configuration for action working. + */ public function testAclHasAccess() { if ($this->uri === null) { $this->markTestIncomplete('AclHasAccess test is not complete'); } + if ($this->httpMethod) { + $this->getRequest()->setMethod($this->httpMethod); + } $this->dispatch($this->uri); $this->assertNotSame(403, $this->getResponse()->getHttpResponseCode()); $this->assertNotSame(404, $this->getResponse()->getHttpResponseCode()); } + /** + * Test ACL actually denying access. + */ public function testAclNoAccess() { if ($this->resource === null) { $this->markTestIncomplete('Acl test is not complete'); } + if ($this->httpMethod) { + $this->getRequest()->setMethod($this->httpMethod); + } $this->_objectManager->get(\Magento\Framework\Acl\Builder::class) ->getAcl() ->deny(null, $this->resource); diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php index 1bf6d471fc40a..feb9eca0793a2 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php @@ -10,10 +10,12 @@ namespace Magento\TestFramework\TestCase; use Magento\Framework\Data\Form\FormKey; +use Magento\Framework\Message\MessageInterface; use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\View\Element\Message\InterpretationStrategyInterface; use Magento\Theme\Controller\Result\MessagePlugin; use Magento\Framework\App\Request\Http as HttpRequest; +use Magento\Framework\App\Response\Http as HttpResponse; /** * @SuppressWarnings(PHPMD.NumberOfChildren) @@ -70,6 +72,9 @@ protected function setUp() $this->_objectManager->removeSharedInstance(\Magento\Framework\App\RequestInterface::class); } + /** + * @inheritDoc + */ protected function tearDown() { $this->_request = null; @@ -114,7 +119,7 @@ public function dispatch($uri) /** * Request getter * - * @return \Magento\Framework\App\RequestInterface + * @return \Magento\Framework\App\RequestInterface|HttpRequest */ public function getRequest() { @@ -127,7 +132,7 @@ public function getRequest() /** * Response getter * - * @return \Magento\Framework\App\ResponseInterface + * @return \Magento\Framework\App\ResponseInterface|HttpResponse */ public function getResponse() { @@ -212,13 +217,21 @@ public function assertSessionMessages( $messageManagerClass = \Magento\Framework\Message\Manager::class ) { $this->_assertSessionErrors = false; - + /** @var MessageInterface[]|string[] $messageObjects */ $messages = $this->getMessages($messageType, $messageManagerClass); + /** @var string[] $messages */ + $messagesFiltered = array_map( + function ($message) { + /** @var MessageInterface|string $message */ + return ($message instanceof MessageInterface) ? $message->toString() : $message; + }, + $messages + ); $this->assertThat( - $messages, + $messagesFiltered, $constraint, - 'Session messages do not meet expectations ' . var_export($messages, true) + 'Session messages do not meet expectations ' . var_export($messagesFiltered, true) ); } diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/IndexTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/IndexTest.php index 219fde6e37075..d5a48b960811e 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/IndexTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/IndexTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Controller\Adminhtml; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoAppArea adminhtml * @magentoDbIsolation enabled @@ -45,6 +47,7 @@ public function testLoggedIndexAction() public function testGlobalSearchAction() { $this->getRequest()->setParam('isAjax', 'true'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue('query', 'dummy'); $this->dispatch('backend/admin/index/globalSearch'); diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/UrlRewriteTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/UrlRewriteTest.php index 1185ae9727e98..0d48fc8b0f59c 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/UrlRewriteTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/UrlRewriteTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Controller\Adminhtml; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoAppArea adminhtml */ @@ -20,6 +22,7 @@ public function testSaveActionCmsPage() $page = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Cms\Model\Page::class); $page->load('page_design_blank', 'identifier'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'description' => 'Some URL rewrite description', diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php index 11f49464bbd21..a6d03fcc200e2 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Catalog\Controller\Adminhtml; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoAppArea adminhtml */ @@ -27,6 +29,7 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved $store->load('fixturestore', 'code'); $storeId = $store->getId(); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($inputData); $this->getRequest()->setParam('store', $storeId); $this->getRequest()->setParam('id', 2); @@ -75,6 +78,7 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved */ public function testSaveActionFromProductCreationPage($postData) { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/category/save'); @@ -123,6 +127,9 @@ public static function categoryCreatedFromProductCreationPageDataProvider() return [[$postData], [$postData + ['return_session_messages_only' => 1]]]; } + /** + * Test SuggestCategories finds any categories. + */ public function testSuggestCategoriesActionDefaultCategoryFound() { $this->getRequest()->setParam('label_part', 'Default'); @@ -133,6 +140,9 @@ public function testSuggestCategoriesActionDefaultCategoryFound() ); } + /** + * Test SuggestCategories properly processes search by label. + */ public function testSuggestCategoriesActionNoSuggestions() { $this->getRequest()->setParam('label_part', strrev('Default')); @@ -322,8 +332,12 @@ public function saveActionDataProvider() ]; } + /** + * Test validation. + */ public function testSaveActionCategoryWithDangerRequest() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'general' => [ @@ -374,7 +388,8 @@ public function testMoveAction($parentId, $childId, $childUrlKey, $grandChildId, } $this->getRequest() ->setPostValue('id', $grandChildId) - ->setPostValue('pid', $parentId); + ->setPostValue('pid', $parentId) + ->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/category/move'); $jsonResponse = json_decode($this->getResponse()->getBody()); $this->assertNotNull($jsonResponse); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php index cea49d940cb62..a2967878402d0 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Action; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoAppArea adminhtml */ @@ -23,6 +25,7 @@ public function testSaveActionRedirectsSuccessfully() /** @var $session \Magento\Backend\Model\Session */ $session = $objectManager->get(\Magento\Backend\Model\Session::class); $session->setProductIds([1]); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_action_attribute/save/store/0'); @@ -69,6 +72,7 @@ public function testSaveActionChangeVisibility($attributes) $session = $objectManager->get(\Magento\Backend\Model\Session::class); $session->setProductIds([$product->getId()]); $this->getRequest()->setParam('attributes', $attributes); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_action_attribute/save/store/0'); /** @var \Magento\Catalog\Model\Category $category */ @@ -89,6 +93,8 @@ public function testSaveActionChangeVisibility($attributes) } /** + * @param array $attributes Request parameter. + * * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute * * @dataProvider validateActionDataProvider diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php index 4261873cc8e6e..98eb9d3ad4cc4 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php @@ -6,10 +6,13 @@ namespace Magento\Catalog\Controller\Adminhtml\Product; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml * @magentoDbIsolation enabled + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class AttributeTest extends \Magento\TestFramework\TestCase\AbstractBackendController { @@ -25,6 +28,7 @@ public function testWrongFrontendInput() 'frontend_input' => 'some_input', ] ); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); @@ -50,6 +54,7 @@ public function testWithPopup() 'popup' => 'true', 'new_attribute_set_name' => 'new_attribute_set', ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); @@ -71,6 +76,7 @@ public function testWithExceptionWhenSaveAttribute() { $postData = $this->_getAttributeData() + ['attribute_id' => 0, 'frontend_input' => 'boolean']; $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); $this->assertContains( @@ -89,6 +95,7 @@ public function testWrongAttributeId() { $postData = $this->_getAttributeData() + ['attribute_id' => 100500]; $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); $this->assertContains( @@ -113,6 +120,7 @@ public function testAttributeWithoutId() 'set' => 4, 'frontend_input' => 'boolean', ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); @@ -135,6 +143,7 @@ public function testWrongAttributeCode() { $postData = $this->_getAttributeData() + ['attribute_code' => '_()&&&?']; $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); $this->assertContains( @@ -159,6 +168,7 @@ public function testWrongAttributeCode() public function testAttributeWithoutEntityTypeId() { $postData = $this->_getAttributeData() + ['attribute_id' => '2', 'new_attribute_set_name' => ' ']; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals(302, $this->getResponse()->getHttpResponseCode()); @@ -174,6 +184,7 @@ public function testAttributeWithoutEntityTypeId() public function testSaveActionApplyToDataSystemAttribute() { $postData = $this->_getAttributeData() + ['attribute_id' => '2']; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $model = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class); @@ -187,6 +198,7 @@ public function testSaveActionApplyToDataSystemAttribute() public function testSaveActionApplyToDataUserDefinedAttribute() { $postData = $this->_getAttributeData() + ['attribute_id' => '1']; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $model */ @@ -202,6 +214,7 @@ public function testSaveActionApplyToData() { $postData = $this->_getAttributeData() + ['attribute_id' => '3']; unset($postData['apply_to']); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $model = $this->_objectManager->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class); @@ -221,6 +234,7 @@ public function testSaveActionCleanAttributeLabelCache() $this->assertEquals('predefined string translation', $this->_translate('string to translate')); $string->saveTranslate('string to translate', 'new string translation'); $postData = $this->_getAttributeData() + ['attribute_id' => 1]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/product_attribute/save'); $this->assertEquals('new string translation', $this->_translate('string to translate')); @@ -293,6 +307,7 @@ public function testLargeOptionsDataSet() $optionsData []= "option[delete][option_{$i}="; } $attributeData['serialized_options'] = json_encode($optionsData); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($attributeData); $this->dispatch('backend/catalog/product_attribute/save'); $entityTypeId = $this->_objectManager->create( diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php index 7c5d4ea48a238..7e034b8b3cb7e 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/DeleteTest.php @@ -6,6 +6,7 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; use Magento\Framework\Message\MessageInterface; +use Magento\Framework\App\Request\Http as HttpRequest; class DeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendController { @@ -15,7 +16,7 @@ class DeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendControll public function testDeleteById() { $attributeSet = $this->getAttributeSetByName('empty_attribute_set'); - $this->getRequest()->setParam('id', $attributeSet->getId()); + $this->getRequest()->setParam('id', $attributeSet->getId())->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product_set/delete/'); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php index 5b711b2ea7418..8ccd426424a29 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php @@ -9,6 +9,7 @@ use Magento\Eav\Api\Data\AttributeSetInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; class SaveTest extends \Magento\TestFramework\TestCase\AbstractBackendController { @@ -20,6 +21,7 @@ public function testAlreadyExistsExceptionProcessingWhenGroupCodeIsDuplicated() $attributeSet = $this->getAttributeSetByName('attribute_set_test'); $this->assertNotEmpty($attributeSet, 'Attribute set with name "attribute_set_test" is missed'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue('data', json_encode([ 'attribute_set_name' => 'attribute_set_test', 'groups' => [ diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php index 2877ef4fb3619..06bbc43e36e8d 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php @@ -6,17 +6,20 @@ namespace Magento\Catalog\Controller\Adminhtml; use Magento\Framework\App\Request\DataPersistorInterface; -use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Message\Manager; -use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml */ class ProductTest extends \Magento\TestFramework\TestCase\AbstractBackendController { + /** + * Test calling save with invalid product's ID. + */ public function testSaveActionWithDangerRequest() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue(['product' => ['entity_id' => 15]]); $this->dispatch('backend/catalog/product/save'); $this->assertSessionMessages( @@ -27,6 +30,8 @@ public function testSaveActionWithDangerRequest() } /** + * Test saving existing product and specifying that we want redirect to new product form. + * * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testSaveActionAndNew() @@ -34,6 +39,7 @@ public function testSaveActionAndNew() $this->getRequest()->setPostValue(['back' => 'new']); $repository = $this->_objectManager->create(\Magento\Catalog\Model\ProductRepository::class); $product = $repository->get('simple'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product/save/id/' . $product->getEntityId()); $this->assertRedirect($this->stringStartsWith('http://localhost/index.php/backend/catalog/product/new/')); $this->assertSessionMessages( @@ -43,6 +49,9 @@ public function testSaveActionAndNew() } /** + * Test saving existing product and specifying that + * we want redirect to new product form with saved product's data applied. + * * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testSaveActionAndDuplicate() @@ -50,6 +59,7 @@ public function testSaveActionAndDuplicate() $this->getRequest()->setPostValue(['back' => 'duplicate']); $repository = $this->_objectManager->create(\Magento\Catalog\Model\ProductRepository::class); $product = $repository->get('simple'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product/save/id/' . $product->getEntityId()); $this->assertRedirect($this->stringStartsWith('http://localhost/index.php/backend/catalog/product/edit/')); $this->assertRedirect( @@ -69,6 +79,9 @@ public function testSaveActionAndDuplicate() ); } + /** + * Testing Add Product button showing. + */ public function testIndexAction() { $this->dispatch('backend/catalog/product'); @@ -109,6 +122,8 @@ public function testIndexAction() } /** + * Testing existing product edit page. + * * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testEditAction() @@ -159,11 +174,13 @@ public function testEditAction() public function testSaveActionWithAlreadyExistingUrlKey(array $postData) { $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/catalog/product/save'); /** @var Manager $messageManager */ $messageManager = $this->_objectManager->get(Manager::class); $messages = $messageManager->getMessages(); $errors = $messages->getItemsByType('error'); + $this->assertNotEmpty($errors); $message = array_shift($errors); $this->assertSame('URL key for specified store already exists.', $message->getText()); $this->assertRedirect($this->stringContains('/backend/catalog/product/new')); @@ -231,7 +248,6 @@ public function saveActionWithAlreadyExistingUrlKeyDataProvider() 'thumbnail' => '/m/a//magento_image.jpg.tmp', 'swatch_image' => '/m/a//magento_image.jpg.tmp', ], - 'form_key' => Bootstrap::getObjectManager()->get(FormKey::class)->getFormKey(), ] ] ]; diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php index ec2e97f942451..1cb2caace4fa1 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php @@ -7,6 +7,7 @@ namespace Magento\Catalog\Controller\Product; use Magento\Framework\Message\MessageInterface; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoDataFixture Magento/Catalog/controllers/_files/products.php @@ -23,7 +24,7 @@ class CompareTest extends \Magento\TestFramework\TestCase\AbstractController protected $productRepository; /** - * Test setup + * @inheritDoc */ protected function setUp() { @@ -36,6 +37,8 @@ protected function setUp() } /** + * Test adding product to compare list. + * * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testAddAction() @@ -45,6 +48,7 @@ public function testAddAction() /** @var \Magento\Framework\Data\Form\FormKey $formKey */ $formKey = $objectManager->get(\Magento\Framework\Data\Form\FormKey::class); $product = $this->productRepository->get('simple_product_1'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch( sprintf( 'catalog/product_compare/add/product/%s/form_key/%s?nocookie=1', @@ -69,6 +73,8 @@ public function testAddAction() } /** + * Test comparing a product. + * * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testIndexActionAddProducts() @@ -83,12 +89,15 @@ public function testIndexActionAddProducts() } /** + * Test removing a product from compare list. + * * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testRemoveAction() { $this->_requireVisitorWithTwoProducts(); $product = $this->productRepository->get('simple_product_2'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId()); $this->assertSessionMessages( @@ -102,12 +111,15 @@ public function testRemoveAction() } /** + * Test removing a product from compare list of a registered customer. + * * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testRemoveActionWithSession() { $this->_requireCustomerWithTwoProducts(); $product = $this->productRepository->get('simple_product_1'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId()); $secondProduct = $this->productRepository->get('simple_product_2'); @@ -122,7 +134,7 @@ public function testRemoveActionWithSession() } /** - * testIndexActionDisplay + * Test getting a list of compared product. */ public function testIndexActionDisplay() { @@ -151,12 +163,13 @@ public function testIndexActionDisplay() } /** - * testClearAction + * Test clearing a list of compared products. */ public function testClearAction() { $this->_requireVisitorWithTwoProducts(); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('catalog/product_compare/clear'); $this->assertSessionMessages( @@ -170,12 +183,15 @@ public function testClearAction() } /** + * Test escaping a session message. + * * @magentoDataFixture Magento/Catalog/_files/product_simple_xss.php */ public function testRemoveActionProductNameXss() { $this->_prepareCompareListWithProductNameXss(); $product = $this->productRepository->get('product-with-xss'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('catalog/product_compare/remove/product/' . $product->getEntityId() . '?nocookie=1'); $this->assertSessionMessages( @@ -187,6 +203,9 @@ public function testRemoveActionProductNameXss() } /** + * Preparing compare list. + * + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function _prepareCompareListWithProductNameXss() @@ -212,7 +231,9 @@ protected function _prepareCompareListWithProductNameXss() } /** - * _requireVisitorWithNoProducts + * Preparing compare list. + * + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _requireVisitorWithNoProducts() { @@ -234,6 +255,9 @@ protected function _requireVisitorWithNoProducts() } /** + * Preparing compare list. + * + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function _requireVisitorWithTwoProducts() @@ -269,6 +293,9 @@ protected function _requireVisitorWithTwoProducts() } /** + * Preparing a compare list. + * + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function _requireCustomerWithTwoProducts() diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php index 82d39bbb7066a..c34120404a950 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php @@ -581,8 +581,11 @@ public function testGetOptions() '4-2-radio' => 40000.00 ]; foreach ($options as $option) { + if (!$option->getValues()) { + continue; + } foreach ($option->getValues() as $value) { - $this->assertEquals($expectedValue[$value->getSku()], floatval($value->getPrice())); + $this->assertEquals($expectedValue[$value->getSku()], (float)$value->getPrice()); } } } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php index 059b784978a22..61b549f7729d1 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php @@ -86,7 +86,18 @@ 'sku' => '4-2-radio', ], ] - ] + ], + [ + 'previous_group' => 'text', + 'title' => 'Test Field', + 'type' => 'field', + 'is_require' => 1, + 'sort_order' => 0, + 'price' => 1, + 'price_type' => 'fixed', + 'sku' => '1-text', + 'max_characters' => 100, + ], ]; $options = []; diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/Index/CouponPostTest.php b/dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/Index/CouponPostTest.php index 07141843793e4..3e99c5cad3c39 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/Index/CouponPostTest.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/Index/CouponPostTest.php @@ -6,6 +6,8 @@ namespace Magento\Checkout\Controller\Cart\Index; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoDbIsolation enabled */ @@ -26,6 +28,7 @@ public function testExecute() 'remove' => 0, 'coupon_code' => 'test' ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($inputData); $this->dispatch( 'checkout/cart/couponPost/' diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php b/dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php index 52156040b2800..fc85cc384a3db 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php @@ -11,13 +11,18 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Checkout\Model\Session; +use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\ResourceModel\CustomerRepository; use Magento\Framework\Data\Form\FormKey; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Quote\Model\Quote; +use Magento\Quote\Api\CartRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Request; use Magento\Customer\Model\Session as CustomerSession; use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection; use Magento\Sales\Model\ResourceModel\Order\Item\Collection as OrderItemCollection; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -25,6 +30,28 @@ */ class CartTest extends \Magento\TestFramework\TestCase\AbstractController { + /** @var CheckoutSession */ + private $checkoutSession; + + /** + * @inheritdoc + */ + protected function setUp() + { + parent::setUp(); + $this->checkoutSession = $this->_objectManager->get(CheckoutSession::class); + $this->_objectManager->addSharedInstance($this->checkoutSession, CheckoutSession::class); + } + + /** + * @inheritdoc + */ + protected function tearDown() + { + $this->_objectManager->removeSharedInstance(CheckoutSession::class); + parent::tearDown(); + } + /** * Test for \Magento\Checkout\Controller\Cart::configureAction() with simple product * @@ -32,8 +59,8 @@ class CartTest extends \Magento\TestFramework\TestCase\AbstractController */ public function testConfigureActionWithSimpleProduct() { - /** @var $session \Magento\Checkout\Model\Session */ - $session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class); + /** @var $session CheckoutSession */ + $session = $this->_objectManager->create(CheckoutSession::class); /** @var ProductRepositoryInterface $productRepository */ $productRepository = $this->_objectManager->create(ProductRepositoryInterface::class); @@ -63,19 +90,20 @@ public function testConfigureActionWithSimpleProduct() /** * Test for \Magento\Checkout\Controller\Cart::configureAction() with simple product and custom option * - * @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_and_custom_option.php + * @magentoDataFixture Magento/Checkout/_files/cart_with_simple_product_and_custom_options.php */ public function testConfigureActionWithSimpleProductAndCustomOption() { - /** @var $session \Magento\Checkout\Model\Session */ - $session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class); + /** @var Quote $quote */ + $quote = $this->getQuote('test_order_item_with_custom_options'); + $this->checkoutSession->setQuoteId($quote->getId()); /** @var ProductRepositoryInterface $productRepository */ $productRepository = $this->_objectManager->create(ProductRepositoryInterface::class); /** @var $product \Magento\Catalog\Model\Product */ - $product = $productRepository->get('simple'); + $product = $productRepository->get('simple_with_custom_options'); - $quoteItem = $this->_getQuoteItemIdByProductId($session->getQuote(), $product->getId()); + $quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId()); $this->assertNotNull($quoteItem, 'Cannot get quote item for simple product with custom option'); $this->dispatch( @@ -112,8 +140,8 @@ public function testConfigureActionWithSimpleProductAndCustomOption() */ public function testConfigureActionWithBundleProduct() { - /** @var $session \Magento\Checkout\Model\Session */ - $session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class); + /** @var $session CheckoutSession */ + $session = $this->_objectManager->create(CheckoutSession::class); /** @var ProductRepositoryInterface $productRepository */ $productRepository = $this->_objectManager->create(ProductRepositoryInterface::class); @@ -147,8 +175,8 @@ public function testConfigureActionWithBundleProduct() */ public function testConfigureActionWithDownloadableProduct() { - /** @var $session \Magento\Checkout\Model\Session */ - $session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class); + /** @var $session CheckoutSession */ + $session = $this->_objectManager->create(CheckoutSession::class); /** @var ProductRepositoryInterface $productRepository */ $productRepository = $this->_objectManager->create(ProductRepositoryInterface::class); @@ -201,8 +229,8 @@ public function testUpdatePostAction() $productId = $product->getId(); $originalQuantity = 1; $updatedQuantity = 2; - /** @var $checkoutSession \Magento\Checkout\Model\Session */ - $checkoutSession = $this->_objectManager->create(\Magento\Checkout\Model\Session::class); + /** @var $checkoutSession CheckoutSession */ + $checkoutSession = $this->_objectManager->create(CheckoutSession::class); $quoteItem = $this->_getQuoteItemIdByProductId($checkoutSession->getQuote(), $productId); /** @var FormKey $formKey */ @@ -212,6 +240,7 @@ public function testUpdatePostAction() 'update_cart_action' => 'update_qty', 'form_key' => $formKey->getFormKey(), ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); /** @var $customerSession \Magento\Customer\Model\Session */ $customerSession = $this->_objectManager->create(\Magento\Customer\Model\Session::class); @@ -235,11 +264,32 @@ public function testUpdatePostAction() $this->assertEquals($updatedQuantity, $quoteItem->getQty(), "Invalid quote item quantity"); } + /** + * Gets quote by reserved order id. + * + * @param string $reservedOrderId + * @return Quote + */ + private function getQuote($reservedOrderId) + { + /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ + $searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class); + $searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId) + ->create(); + + /** @var CartRepositoryInterface $quoteRepository */ + $quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class); + $items = $quoteRepository->getList($searchCriteria)->getItems(); + + return array_pop($items); + } + /** * Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id * * @param \Magento\Quote\Model\Quote $quote - * @param int $productId + * @param string|int $productId + * * @return \Magento\Quote\Model\Quote\Item|null */ private function _getQuoteItemIdByProductId($quote, $productId) @@ -274,6 +324,7 @@ public function testAddToCartSimpleProduct($area, $expectedPrice) 'isAjax' => 1 ]; \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($area); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $quote = $this->_objectManager->create(\Magento\Checkout\Model\Cart::class); @@ -301,6 +352,77 @@ public function addAddProductDataProvider() ]; } + /** + * Test for \Magento\Checkout\Controller\Cart\Add::execute() with simple product and activated redirect to cart + * + * @magentoDataFixture Magento/Catalog/_files/products.php + * @magentoConfigFixture current_store checkout/cart/redirect_to_cart 1 + * @magentoAppIsolation enabled + */ + public function testMessageAtAddToCartWithRedirect() + { + $formKey = $this->_objectManager->get(FormKey::class); + $postData = [ + 'qty' => '1', + 'product' => '1', + 'custom_price' => 1, + 'form_key' => $formKey->getFormKey(), + 'isAjax' => 1 + ]; + \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend'); + $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod('POST'); + + $this->dispatch('checkout/cart/add'); + + $this->assertEquals( + '{"backUrl":"http:\/\/localhost\/index.php\/checkout\/cart\/"}', + $this->getResponse()->getBody() + ); + + $this->assertSessionMessages( + $this->contains( + 'You added Simple Product to your shopping cart.' + ), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + } + + /** + * Test for \Magento\Checkout\Controller\Cart\Add::execute() with simple product and deactivated redirect to cart + * + * @magentoDataFixture Magento/Catalog/_files/products.php + * @magentoConfigFixture current_store checkout/cart/redirect_to_cart 0 + * @magentoAppIsolation enabled + */ + public function testMessageAtAddToCartWithoutRedirect() + { + $formKey = $this->_objectManager->get(FormKey::class); + $postData = [ + 'qty' => '1', + 'product' => '1', + 'custom_price' => 1, + 'form_key' => $formKey->getFormKey(), + 'isAjax' => 1 + ]; + \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend'); + $this->getRequest()->setPostValue($postData); + $this->getRequest()->setMethod('POST'); + + $this->dispatch('checkout/cart/add'); + + $this->assertFalse($this->getResponse()->isRedirect()); + $this->assertEquals('[]', $this->getResponse()->getBody()); + + $this->assertSessionMessages( + $this->contains( + "\n" . 'You added Simple Product to your ' . + 'shopping cart.' + ), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + } + /** * @covers \Magento\Checkout\Controller\Cart\Addgroup::execute() * diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_options.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_options.php new file mode 100644 index 0000000000000..22367979adcab --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/cart_with_simple_product_and_custom_options.php @@ -0,0 +1,47 @@ +create(ProductRepositoryInterface::class); +$product = $productRepository->get('simple_with_custom_options'); + +$options = []; +/** @var $option Option */ +foreach ($product->getOptions() as $option) { + switch ($option->getGroupByType()) { + case ProductCustomOptionInterface::OPTION_GROUP_SELECT: + $value = key($option->getValues()); + break; + default: + $value = 'test'; + break; + } + $options[$option->getId()] = $value; +} + +$requestInfo = new DataObject(['qty' => 1, 'options' => $options]); + +/** @var $cart \Magento\Checkout\Model\Cart */ +$quote = Bootstrap::getObjectManager()->create(Quote::class); +$quote->setReservedOrderId('test_order_item_with_custom_options'); +$quote->addProduct($product, $requestInfo); +$quote->save(); + +/** @var $objectManager \Magento\TestFramework\ObjectManager */ +$objectManager = Bootstrap::getObjectManager(); +$objectManager->removeSharedInstance(Session::class); diff --git a/dev/tests/integration/testsuite/Magento/Config/Controller/Adminhtml/System/ConfigTest.php b/dev/tests/integration/testsuite/Magento/Config/Controller/Adminhtml/System/ConfigTest.php index 2ad15fbea6c40..24b68e804cd57 100644 --- a/dev/tests/integration/testsuite/Magento/Config/Controller/Adminhtml/System/ConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Config/Controller/Adminhtml/System/ConfigTest.php @@ -7,12 +7,16 @@ namespace Magento\Config\Controller\Adminhtml\System; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml */ class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController { + /** + * Test Configuration page existing. + */ public function testEditAction() { $this->dispatch('backend/admin/system_config/edit'); @@ -20,6 +24,8 @@ public function testEditAction() } /** + * Test redirect after changing base URL. + * * @magentoAppIsolation enabled * @magentoDbIsolation enabled */ @@ -43,6 +49,8 @@ public function testChangeBaseUrl() )->setParam( 'section', 'web' + )->setMethod( + HttpRequest::METHOD_POST ); $this->dispatch('backend/admin/system_config/save'); @@ -60,7 +68,9 @@ public function testChangeBaseUrl() } /** - * Reset test framework default base url + * Reset test framework default base url. + * + * @param string $defaultHost */ protected function resetBaseUrl($defaultHost) { diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php index 4254a6ce9c71d..b71507ae43f9f 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php @@ -9,6 +9,7 @@ use Magento\Framework\Registry; use Magento\TestFramework\ObjectManager; use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml @@ -23,6 +24,7 @@ public function testSaveActionAssociatedProductIds() { $associatedProductIds = ['3', '14', '15', '92']; $associatedProductIdsJSON = json_encode($associatedProductIds); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'id' => 1, diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/CartTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/CartTest.php index 4e0b74ba0f901..0d93d3ad4f4ae 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/CartTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/CartTest.php @@ -9,6 +9,8 @@ */ namespace Magento\ConfigurableProduct\Controller; +use Magento\Framework\App\Request\Http as HttpRequest; + class CartTest extends \Magento\TestFramework\TestCase\AbstractController { /** @@ -85,6 +87,7 @@ public function testExecuteForConfigurableLastOption() 'remove' => 0, 'coupon_code' => 'test' ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($inputData); $this->dispatch( 'checkout/cart/couponPost/' diff --git a/dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php b/dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php index 2f89cb72b0cd9..c1255ae9b1aad 100644 --- a/dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php +++ b/dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php @@ -6,7 +6,7 @@ namespace Magento\Contact\Controller; -use Zend\Http\Request; +use Magento\Framework\App\Request\Http as HttpRequest; /** * Contact index controller test @@ -14,7 +14,7 @@ class IndexTest extends \Magento\TestFramework\TestCase\AbstractController { /** - * testPostAction + * Test contacting. */ public function testPostAction() { @@ -24,8 +24,7 @@ public function testPostAction() 'email' => 'user@example.com', 'hideit' => '', ]; - $this->getRequest()->setPostValue($params); - $this->getRequest()->setMethod(Request::METHOD_POST); + $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('contact/index/post'); $this->assertRedirect($this->stringContains('contact/index')); @@ -38,14 +37,16 @@ public function testPostAction() } /** + * Test validation. + * + * @param array $params For Request. + * @param string $expectedMessage Expected response. + * * @dataProvider dataInvalidPostAction - * @param array $params - * @param string $expectedMessage */ public function testInvalidPostAction($params, $expectedMessage) { - $this->getRequest()->setPostValue($params); - $this->getRequest()->setMethod(Request::METHOD_POST); + $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('contact/index/post'); $this->assertRedirect($this->stringContains('contact/index')); diff --git a/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRatesTest.php b/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRatesTest.php index c9f2ffad67644..fefd1a7b250c3 100644 --- a/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRatesTest.php +++ b/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRatesTest.php @@ -5,6 +5,8 @@ */ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency; +use Magento\Framework\App\Request\Http as HttpRequest; + class SaveRatesTest extends \Magento\TestFramework\TestCase\AbstractBackendController { @@ -43,6 +45,7 @@ public function testSaveAction() $rate = 1.0000; $request = $this->getRequest(); + $request->setMethod(HttpRequest::METHOD_POST); $request->setPostValue( 'rate', [ @@ -75,6 +78,7 @@ public function testSaveWithWarningAction() $rate = '0'; $request = $this->getRequest(); + $request->setMethod(HttpRequest::METHOD_POST); $request->setPostValue( 'rate', [ diff --git a/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/SaveTest.php b/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/SaveTest.php index 5217c3576a51d..2929f137be89f 100644 --- a/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/SaveTest.php @@ -5,10 +5,16 @@ */ namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol; +use Magento\Framework\App\Request\Http as HttpRequest; + class SaveTest extends \Magento\TestFramework\TestCase\AbstractBackendController { /** - * Test save action + * Test save action. + * + * @param string $currencyCode + * @param string $inputCurrencySymbol + * @param string $outputCurrencySymbol * * @magentoConfigFixture currency/options/allow USD * @magentoDbIsolation enabled @@ -31,6 +37,7 @@ public function testSaveAction($currencyCode, $inputCurrencySymbol, $outputCurre $currencyCode => $inputCurrencySymbol, ] ); + $request->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/admin/system_currencysymbol/save'); $this->assertRedirect(); diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php index 186d9c8f87dc2..921fa81fa6f23 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php @@ -22,6 +22,7 @@ use Magento\TestFramework\Request; use Magento\TestFramework\Response; use Zend\Stdlib\Parameters; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -56,7 +57,7 @@ public function testIndexAction() } /** - * @return void + * Test sign up form displaying. */ public function testCreateAction() { @@ -97,10 +98,8 @@ public function testForgotPasswordEmailMessageWithSpecialCharacters() { $email = 'customer@example.com'; - $this->getRequest() - ->setPostValue([ - 'email' => $email, - ]); + $this->getRequest()->setPostValue(['email' => $email]); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('customer/account/forgotPasswordPost'); $this->assertRedirect($this->stringContains('customer/account/')); @@ -377,10 +376,8 @@ public function testForgotPasswordPostAction() { $email = 'customer@example.com'; - $this->getRequest() - ->setPostValue([ - 'email' => $email, - ]); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); + $this->getRequest()->setPostValue(['email' => $email]); $this->dispatch('customer/account/forgotPasswordPost'); $this->assertRedirect($this->stringContains('customer/account/')); @@ -400,6 +397,7 @@ public function testForgotPasswordPostAction() */ public function testForgotPasswordPostWithBadEmailAction() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest() ->setPostValue([ 'email' => 'bad@email', diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php index 32a622d4aa654..92e104496fed8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php @@ -9,6 +9,7 @@ use Magento\Customer\Model\CustomerRegistry; use Magento\Framework\Data\Form\FormKey; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; class AddressTest extends \Magento\TestFramework\TestCase\AbstractController { @@ -19,7 +20,7 @@ class AddressTest extends \Magento\TestFramework\TestCase\AbstractController private $formKey; /** - * {@inheritDoc} + * @inheritDoc */ protected function setUp() { @@ -168,7 +169,7 @@ public function testFailedFormPostAction() public function testDeleteAction() { $this->getRequest()->setParam('id', 1); - $this->getRequest()->setParam('form_key', $this->formKey->getFormKey()); + $this->getRequest()->setParam('form_key', $this->formKey->getFormKey())->setMethod(HttpRequest::METHOD_POST); // we are overwriting the address coming from the fixture $this->dispatch('customer/address/delete'); @@ -186,7 +187,7 @@ public function testDeleteAction() public function testWrongAddressDeleteAction() { $this->getRequest()->setParam('id', 555); - $this->getRequest()->setParam('form_key', $this->formKey->getFormKey()); + $this->getRequest()->setParam('form_key', $this->formKey->getFormKey())->setMethod(HttpRequest::METHOD_POST); // we are overwriting the address coming from the fixture $this->dispatch('customer/address/delete'); diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php index 80b11a920e3fb..db1cc4995e676 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php @@ -7,6 +7,7 @@ use Magento\Framework\Message\MessageInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml @@ -25,6 +26,11 @@ class GroupTest extends \Magento\TestFramework\TestCase\AbstractBackendControlle /** @var \Magento\Customer\Api\GroupRepositoryInterface */ private $groupRepository; + /** + * @inheritDoc + * + * @throws \Magento\Framework\Exception\AuthenticationException + */ public function setUp() { parent::setUp(); @@ -33,12 +39,18 @@ public function setUp() $this->groupRepository = $objectManager->get(\Magento\Customer\Api\GroupRepositoryInterface::class); } + /** + * @inheritDoc + */ public function tearDown() { parent::tearDown(); //$this->session->unsCustomerGroupData(); } + /** + * Test new group form. + */ public function testNewActionNoCustomerGroupDataInSession() { $this->dispatch('backend/customer/group/new'); @@ -49,6 +61,9 @@ public function testNewActionNoCustomerGroupDataInSession() $this->assertContains($expected, $responseBody); } + /** + * Test form filling with data in session. + */ public function testNewActionWithCustomerGroupDataInSession() { /** @var \Magento\Customer\Api\Data\GroupInterfaceFactory $customerGroupFactory */ @@ -76,21 +91,27 @@ public function testNewActionWithCustomerGroupDataInSession() } /** + * Test calling delete without an ID. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testDeleteActionNoGroupId() { + $this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST); $this->dispatch('backend/customer/group/delete'); $this->assertRedirect($this->stringStartsWith(self::BASE_CONTROLLER_URL)); } /** + * Test deleting a group. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testDeleteActionExistingGroup() { $groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE); $this->getRequest()->setParam('id', $groupId); + $this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST); $this->dispatch('backend/customer/group/delete'); /** @@ -104,11 +125,14 @@ public function testDeleteActionExistingGroup() } /** + * Tet deleting with wrong ID. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testDeleteActionNonExistingGroupId() { $this->getRequest()->setParam('id', 10000); + $this->getRequest()->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST); $this->dispatch('backend/customer/group/delete'); /** @@ -122,6 +146,8 @@ public function testDeleteActionNonExistingGroupId() } /** + * Test saving a valid group. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testSaveActionExistingGroup() @@ -130,6 +156,7 @@ public function testSaveActionExistingGroup() $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID); $this->getRequest()->setParam('id', $groupId); $this->getRequest()->setParam('code', self::CUSTOMER_GROUP_CODE); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); @@ -161,9 +188,13 @@ public function testSaveActionExistingGroup() ); } + /** + * Test saving an invalid group. + */ public function testSaveActionCreateNewGroupWithoutCode() { $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); @@ -173,19 +204,26 @@ public function testSaveActionCreateNewGroupWithoutCode() ); } + /** + * Test saving an empty group. + */ public function testSaveActionForwardNewCreateNewGroup() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); $responseBody = $this->getResponse()->getBody(); $this->assertRegExp('/

\s*New Customer Group\s*<\/h1>/', $responseBody); } /** + * Test saving an existing group. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testSaveActionForwardNewEditExistingGroup() { $groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('id', $groupId); $this->dispatch('backend/customer/group/save'); @@ -193,10 +231,14 @@ public function testSaveActionForwardNewEditExistingGroup() $this->assertRegExp('/

\s*' . self::CUSTOMER_GROUP_CODE . '\s*<\/h1>/', $responseBody); } + /** + * Test using an invalid ID. + */ public function testSaveActionNonExistingGroupId() { $this->getRequest()->setParam('id', 10000); $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); @@ -211,6 +253,8 @@ public function testSaveActionNonExistingGroupId() } /** + * Test using existing code. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testSaveActionNewGroupWithExistingGroupCode() @@ -220,6 +264,7 @@ public function testSaveActionNewGroupWithExistingGroupCode() $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID); $this->getRequest()->setParam('code', self::CUSTOMER_GROUP_CODE); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); @@ -232,6 +277,8 @@ public function testSaveActionNewGroupWithExistingGroupCode() } /** + * Test saving an invalid group. + * * @magentoDataFixture Magento/Customer/_files/customer_group.php */ public function testSaveActionNewGroupWithoutGroupCode() @@ -240,6 +287,7 @@ public function testSaveActionNewGroupWithoutGroupCode() $originalCode = $this->groupRepository->getById($groupId)->getCode(); $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/group/save'); diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroupTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroupTest.php index 8ee12fa1aa8d5..761064ed61fcf 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroupTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroupTest.php @@ -9,6 +9,7 @@ use Magento\Backend\Model\Session; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\Message\MessageInterface; use Magento\TestFramework\Helper\Bootstrap; @@ -31,12 +32,20 @@ class MassAssignGroupTest extends AbstractBackendController */ protected $customerRepository; + /** + * @inheritDoc + * + * @throws \Magento\Framework\Exception\AuthenticationException + */ protected function setUp() { parent::setUp(); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); } + /** + * @inheritDoc + */ protected function tearDown() { /** @@ -69,7 +78,8 @@ public function testMassAssignGroupAction() 'selected' => [$customer->getId()] ]; - $this->getRequest()->setParams($params); + $this->getRequest()->setParams($params) + ->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/massAssignGroup'); $this->assertSessionMessages( self::equalTo(['A total of 1 record(s) were updated.']), @@ -103,7 +113,8 @@ public function testLargeGroupMassAssignGroupAction() 'selected' => $ids, ]; - $this->getRequest()->setParams($params); + $this->getRequest()->setParams($params) + ->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/massAssignGroup'); $this->assertSessionMessages( self::equalTo(['A total of 5 record(s) were updated.']), @@ -124,11 +135,9 @@ public function testLargeGroupMassAssignGroupAction() */ public function testMassAssignGroupActionNoCustomerIds() { - $params = [ - 'group' => 0, - 'namespace' => 'customer_listing', + $params = ['group'=> 0,'namespace'=> 'customer_listing', ]; - $this->getRequest()->setParams($params); + $this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/massAssignGroup'); $this->assertSessionMessages( $this->equalTo(['An item needs to be selected. Select and try again.']), diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassDeleteTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassDeleteTest.php index 940f7c84325f6..eea94bb3f9867 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassDeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassDeleteTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\Constraint\Constraint; use Magento\Framework\Message\MessageInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; use Magento\TestFramework\TestCase\AbstractBackendController; /** @@ -32,12 +33,20 @@ class MassDeleteTest extends AbstractBackendController */ private $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/index'; + /** + * @inheritDoc + * + * @throws \Magento\Framework\Exception\AuthenticationException + */ protected function setUp() { parent::setUp(); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); } + /** + * @inheritDoc + */ protected function tearDown() { /** @@ -106,7 +115,7 @@ private function massDeleteAssertions($ids, Constraint $constraint, $messageType 'namespace' => 'customer_listing', ]; - $this->getRequest()->setParams($requestData); + $this->getRequest()->setParams($requestData)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/massDelete'); $this->assertSessionMessages( $constraint, diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php index b5ca783d68cf2..eaaba639d49a8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Customer\Controller\Adminhtml\Index; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * ResetPassword controller test. * @@ -32,7 +34,7 @@ public function testResetPasswordSuccess() $this->passwordResetRequestEventCreate( \Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST ); - $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->getRequest()->setPostValue(['customer_id' => '1'])->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertSessionMessages( $this->equalTo(['The customer will receive an email with a link to reset password.']), @@ -55,7 +57,7 @@ public function testResetPasswordMinTimeError() $this->passwordResetRequestEventCreate( \Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST ); - $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->getRequest()->setPostValue(['customer_id' => '1'])->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertSessionMessages( $this->equalTo(['The customer will receive an email with a link to reset password.']), @@ -78,7 +80,7 @@ public function testResetPasswordLimitError() $this->passwordResetRequestEventCreate( \Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST ); - $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->getRequest()->setPostValue(['customer_id' => '1'])->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertSessionMessages( $this->equalTo(['The customer will receive an email with a link to reset password.']), @@ -103,7 +105,7 @@ public function testResetPasswordWithSecurityViolationException() $this->passwordResetRequestEventCreate( \Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST ); - $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->getRequest()->setPostValue(['customer_id' => '1'])->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertSessionMessages( $this->equalTo(['The customer will receive an email with a link to reset password.']), diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php index 6448816c9345c..4262967aa8d1a 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php @@ -12,6 +12,7 @@ use Magento\Customer\Controller\RegistryConstants; use Magento\Customer\Model\EmailNotification; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml @@ -45,7 +46,7 @@ class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendControlle protected $objectManager; /** - * {@inheritDoc} + * @inheritDoc */ protected function setUp() { @@ -71,7 +72,7 @@ protected function setUp() } /** - * {@inheritDoc} + * @inheritDoc */ protected function tearDown() { @@ -91,7 +92,7 @@ protected function tearDown() */ public function testSaveActionWithEmptyPostData() { - $this->getRequest()->setPostValue([]); + $this->getRequest()->setPostValue([])->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/save'); $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl)); } @@ -102,7 +103,7 @@ public function testSaveActionWithEmptyPostData() public function testSaveActionWithInvalidFormData() { $post = ['account' => ['middlename' => 'test middlename', 'group_id' => 1]]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/save'); /** * Check that errors was generated and set to session @@ -111,13 +112,13 @@ public function testSaveActionWithInvalidFormData() $this->logicalNot($this->isEmpty()), \Magento\Framework\Message\MessageInterface::TYPE_ERROR ); + /** @var \Magento\Backend\Model\Session $session */ + $session = $this->objectManager->get(\Magento\Backend\Model\Session::class); /** * Check that customer data were set to session */ - $this->assertEquals( - $post, - $this->objectManager->get(\Magento\Backend\Model\Session::class)->getCustomerFormData() - ); + $this->assertNotEmpty($session->getCustomerFormData()); + $this->assertArraySubset($post, $session->getCustomerFormData()); $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'new')); } @@ -138,7 +139,7 @@ public function testSaveActionWithInvalidCustomerAddressData() ], 'address' => ['_item1' => []], ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/save'); /** * Check that errors was generated and set to session @@ -150,7 +151,7 @@ public function testSaveActionWithInvalidCustomerAddressData() /** * Check that customer data were set to session */ - $this->assertEquals( + $this->assertArraySubset( $post, $this->objectManager->get(\Magento\Backend\Model\Session::class)->getCustomerFormData() ); @@ -187,7 +188,7 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData() ], ], ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('back', '1'); // Emulate setting customer data to session in editAction @@ -299,7 +300,7 @@ public function testSaveActionExistingCustomerAndExistingAddressData() ], 'subscription' => '', ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('id', 1); $this->dispatch('backend/customer/index/save'); @@ -365,7 +366,7 @@ public function testSaveActionExistingCustomerUnsubscribeNewsletter() ], 'subscription' => '0' ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('id', 1); $this->dispatch('backend/customer/index/save'); @@ -426,7 +427,7 @@ public function testSaveActionExistingCustomerChangeEmail() 'default_billing' => 1, ] ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('id', 1); $this->dispatch('backend/customer/index/save'); @@ -473,7 +474,7 @@ public function testInlineEditChangeEmail() ] ]; $this->getRequest()->setParam('ajax', true)->setParam('isAjax', true); - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('id', 1); $this->dispatch('backend/customer/index/inlineEdit'); @@ -499,7 +500,7 @@ public function testSaveActionCoreException() 'password' => 'password', ], ]; - $this->getRequest()->setPostValue($post); + $this->getRequest()->setPostValue($post)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/save'); /* * Check that error message is set @@ -508,7 +509,7 @@ public function testSaveActionCoreException() $this->equalTo(['A customer with the same email address already exists in an associated website.']), \Magento\Framework\Message\MessageInterface::TYPE_ERROR ); - $this->assertEquals( + $this->assertArraySubset( $post, Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getCustomerFormData() ); @@ -529,9 +530,9 @@ public function testEditAction() } /** - * Tests new action + * Test new customer form page. */ - public function testNewAction(): void + public function testNewAction() { $this->dispatch('backend/customer/index/edit'); $body = $this->getResponse()->getBody(); @@ -666,7 +667,7 @@ public function testValidateCustomerWithAddressSuccess() /** * set customer data */ - $this->getRequest()->setParams($customerData); + $this->getRequest()->setParams($customerData)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/validate'); $body = $this->getResponse()->getBody(); @@ -720,7 +721,7 @@ public function testValidateCustomerWithAddressFailure() /** * set customer data */ - $this->getRequest()->setPostValue($customerData); + $this->getRequest()->setPostValue($customerData)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/validate'); $body = $this->getResponse()->getBody(); @@ -737,6 +738,7 @@ public function testValidateCustomerWithAddressFailure() public function testResetPasswordActionNoCustomerId() { // No customer ID in post, will just get redirected to base + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl)); } @@ -747,6 +749,7 @@ public function testResetPasswordActionNoCustomerId() public function testResetPasswordActionBadCustomerId() { // Bad customer ID in post, will just get redirected to base + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue(['customer_id' => '789']); $this->dispatch('backend/customer/index/resetPassword'); $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl)); @@ -758,6 +761,7 @@ public function testResetPasswordActionBadCustomerId() public function testResetPasswordActionSuccess() { $this->getRequest()->setPostValue(['customer_id' => '1']); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/customer/index/resetPassword'); $this->assertSessionMessages( $this->equalTo(['The customer will receive an email with a link to reset password.']), diff --git a/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php b/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php index 5e8239586d76b..9961101dac7cb 100644 --- a/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php +++ b/dev/tests/integration/testsuite/Magento/Eav/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php @@ -9,7 +9,7 @@ use Magento\TestFramework\Helper\CacheCleaner; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\App\CacheInterface; -use Magento\Store\Api\StoreResolverInterface; +use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\Serialize\Serializer\Json as Serializer; use Magento\Eav\Model\Entity\Attribute; @@ -44,9 +44,9 @@ class DefaultFrontendTest extends \PHPUnit\Framework\TestCase private $cache; /** - * @var StoreResolverInterface + * @var StoreManagerInterface */ - private $storeResolver; + private $storeManager; /** * @var Serializer @@ -60,7 +60,7 @@ protected function setUp() $this->defaultFrontend = $this->objectManager->get(DefaultFrontend::class); $this->cache = $this->objectManager->get(CacheInterface::class); - $this->storeResolver = $this->objectManager->get(StoreResolverInterface::class); + $this->storeManager = $this->objectManager->get(StoreManagerInterface::class); $this->serializer = $this->objectManager->get(Serializer::class); $this->attribute = $this->objectManager->get(Attribute::class); @@ -99,6 +99,6 @@ private function getCacheKey() { return 'attribute-navigation-option-' . $this->defaultFrontend->getAttribute()->getAttributeCode() . '-' . - $this->storeResolver->getCurrentStoreId(); + $this->storeManager->getStore()->getId(); } } diff --git a/dev/tests/integration/testsuite/Magento/Elasticsearch/Controller/Adminhtml/Category/SaveTest.php b/dev/tests/integration/testsuite/Magento/Elasticsearch/Controller/Adminhtml/Category/SaveTest.php index b37392fff7609..fcd8226aec50c 100644 --- a/dev/tests/integration/testsuite/Magento/Elasticsearch/Controller/Adminhtml/Category/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/Elasticsearch/Controller/Adminhtml/Category/SaveTest.php @@ -80,6 +80,7 @@ public function testExecute() ]; $this->getRequest()->setPostValue($inputData); + $this->getRequest()->setMethod('POST'); $this->dispatch('backend/catalog/category/save'); $this->assertSessionMessages( self::equalTo(['You saved the category.']), diff --git a/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php b/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php index 431c705430819..89240f4ab3241 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php @@ -5,11 +5,21 @@ */ namespace Magento\Framework\App; +use Magento\Framework\App\Request\InvalidRequestException; +use Magento\Framework\App\Request\ValidatorInterface; +use Magento\Framework\Exception\NotFoundException; +use Magento\Framework\Phrase; +use PHPUnit\Framework\TestCase; +use Magento\Framework\App\Request\Http as HttpRequest; +use Magento\Framework\Controller\ResultInterface; +use Magento\TestFramework\Helper\Bootstrap; + /** * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @magentoAppArea frontend */ -class FrontControllerTest extends \PHPUnit\Framework\TestCase +class FrontControllerTest extends TestCase { /** * @var \Magento\Framework\ObjectManagerInterface @@ -17,28 +27,94 @@ class FrontControllerTest extends \PHPUnit\Framework\TestCase protected $_objectManager; /** - * @var \Magento\Framework\App\FrontController + * @var FrontController */ protected $_model; + /** + * @var ValidatorInterface + */ + private $fakeRequestValidator; + + /** + * @return ValidatorInterface + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + private function createRequestValidator(): ValidatorInterface + { + if (!$this->fakeRequestValidator) { + $this->fakeRequestValidator = new class implements ValidatorInterface { + /** + * @var bool + */ + public $valid; + + /** + * @inheritDoc + */ + public function validate( + RequestInterface $request, + ActionInterface $action + ): void { + if (!$this->valid) { + throw new InvalidRequestException(new NotFoundException(new Phrase('Not found'))); + } + } + }; + } + + return $this->fakeRequestValidator; + } + + /** + * @inheritDoc + */ protected function setUp() { - $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->_model = $this->_objectManager->create(\Magento\Framework\App\FrontController::class); + $this->_objectManager = Bootstrap::getObjectManager(); + $this->_model = $this->_objectManager->create( + FrontController::class, + ['requestValidator' => $this->createRequestValidator()] + ); } + /** + * Test dispatching an empty action. + */ public function testDispatch() { - if (!\Magento\TestFramework\Helper\Bootstrap::canTestHeaders()) { + if (!Bootstrap::canTestHeaders()) { + $this->markTestSkipped('Can\'t test dispatch process without sending headers'); + } + $this->fakeRequestValidator->valid = true; + $_SERVER['HTTP_HOST'] = 'localhost'; + $this->_objectManager->get(State::class)->setAreaCode('frontend'); + $request = $this->_objectManager->get(HttpRequest::class); + /* empty action */ + $request->setRequestUri('core/index/index'); + $this->assertInstanceOf( + ResultInterface::class, + $this->_model->dispatch($request) + ); + } + + /** + * Test request validator invalidating given request. + */ + public function testInvalidRequest() + { + if (!Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test dispatch process without sending headers'); } + $this->fakeRequestValidator->valid = false; $_SERVER['HTTP_HOST'] = 'localhost'; - $this->_objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend'); - $request = $this->_objectManager->get(\Magento\Framework\App\Request\Http::class); + $this->_objectManager->get(State::class)->setAreaCode('frontend'); + $request = $this->_objectManager->get(HttpRequest::class); /* empty action */ $request->setRequestUri('core/index/index'); $this->assertInstanceOf( - \Magento\Framework\Controller\ResultInterface::class, + ResultInterface::class, $this->_model->dispatch($request) ); } diff --git a/dev/tests/integration/testsuite/Magento/Framework/App/Request/HttpMethodValidatorTest.php b/dev/tests/integration/testsuite/Magento/Framework/App/Request/HttpMethodValidatorTest.php new file mode 100644 index 0000000000000..74aa5b8bfed05 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/App/Request/HttpMethodValidatorTest.php @@ -0,0 +1,110 @@ +validator = $objectManager->get(HttpMethodValidator::class); + $this->request = $objectManager->get(RequestInterface::class); + if (!$this->request instanceof HttpRequest) { + throw new \RuntimeException('We need HTTP request'); + } + $this->map = $objectManager->get(HttpMethodMap::class); + } + + /** + * @return array + */ + private function getMap(): array + { + $map = $this->map->getMap(); + if (count($map) < 2) { + throw new \RuntimeException( + 'We need at least 2 HTTP methods allowed' + ); + } + + $sorted = []; + foreach ($map as $method => $interface) { + $sorted[] = ['method' => $method, 'interface' => $interface]; + } + + return $sorted; + } + + /** + * Test positive case. + * + * @throws InvalidRequestException + */ + public function testAllowed() + { + $map = $this->getMap(); + + $action1 = $this->getMockForAbstractClass($map[0]['interface']); + $this->request->setMethod($map[0]['method']); + $this->validator->validate($this->request, $action1); + + $action2 = $this->getMockForAbstractClass(ActionInterface::class); + $this->validator->validate($this->request, $action2); + } + + /** + * Test negative case. + * + * @expectedException \Magento\Framework\App\Request\InvalidRequestException + */ + public function testNotAllowedMethod() + { + $this->request->setMethod('method' .rand(0, 1000)); + $action = $this->getMockForAbstractClass(ActionInterface::class); + + $this->validator->validate($this->request, $action); + } + + /** + * @expectedException \Magento\Framework\App\Request\InvalidRequestException + */ + public function testRestrictedMethod() + { + $map = $this->getMap(); + + $this->request->setMethod($map[1]['method']); + $action = $this->getMockForAbstractClass($map[0]['interface']); + + $this->validator->validate($this->request, $action); + } +} diff --git a/dev/tests/integration/testsuite/Magento/GiftMessage/Observer/SalesEventQuoteMergeTest.php b/dev/tests/integration/testsuite/Magento/GiftMessage/Observer/SalesEventQuoteMergeTest.php new file mode 100644 index 0000000000000..0902c35568ee3 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GiftMessage/Observer/SalesEventQuoteMergeTest.php @@ -0,0 +1,40 @@ +get(ManagerInterface::class); + /** @var Quote $sourceQuote */ + $sourceQuote = $objectManager->create(QuoteFactory::class)->create(); + $targetQuote = clone($sourceQuote); + $sourceQuote->setGiftMessageId($giftMessageId); + + $eventManager->dispatch( + 'sales_quote_merge_after', + [ + 'quote' => $targetQuote, + 'source' => $sourceQuote + ] + ); + + self::assertEquals($giftMessageId, $targetQuote->getGiftMessageId()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Integration/Controller/Adminhtml/IntegrationTest.php b/dev/tests/integration/testsuite/Magento/Integration/Controller/Adminhtml/IntegrationTest.php index 8011873577dc8..4da0c12c6087a 100644 --- a/dev/tests/integration/testsuite/Magento/Integration/Controller/Adminhtml/IntegrationTest.php +++ b/dev/tests/integration/testsuite/Magento/Integration/Controller/Adminhtml/IntegrationTest.php @@ -7,6 +7,7 @@ namespace Magento\Integration\Controller\Adminhtml; use Magento\TestFramework\Bootstrap; +use Magento\Framework\App\Request\Http as HttpRequest; /** * \Magento\Integration\Controller\Adminhtml\Integration @@ -20,6 +21,9 @@ class IntegrationTest extends \Magento\TestFramework\TestCase\AbstractBackendCon /** @var \Magento\Integration\Model\Integration */ private $_integration; + /** + * @inheritDoc + */ protected function setUp() { parent::setUp(); @@ -29,6 +33,9 @@ protected function setUp() $this->_integration = $integration->load('Fixture Integration', 'name'); } + /** + * Test view page. + */ public function testIndexAction() { $this->dispatch('backend/admin/integration/index'); @@ -44,6 +51,9 @@ public function testIndexAction() ); } + /** + * Test creation form. + */ public function testNewAction() { $this->dispatch('backend/admin/integration/new'); @@ -61,6 +71,9 @@ public function testNewAction() ); } + /** + * Test update form. + */ public function testEditAction() { $integrationId = $this->_integration->getId(); @@ -88,12 +101,16 @@ public function testEditAction() ); } + /** + * Test saving. + */ public function testSaveActionUpdateIntegration() { $integrationId = $this->_integration->getId(); $integrationName = $this->_integration->getName(); $this->getRequest()->setParam('id', $integrationId); $url = 'http://magento.ll/endpoint_url'; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'name' => $integrationName, @@ -111,10 +128,14 @@ public function testSaveActionUpdateIntegration() $this->assertRedirect($this->stringContains('backend/admin/integration/index/')); } + /** + * Test saving. + */ public function testSaveActionNewIntegration() { $url = 'http://magento.ll/endpoint_url'; $integrationName = md5(rand()); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'name' => $integrationName, diff --git a/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php b/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php new file mode 100644 index 0000000000000..9271e08942279 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php @@ -0,0 +1,76 @@ +objectManager = Bootstrap::getObjectManager(); + } + + /** + * @magentoConfigFixture default/newrelicreporting/general/enable 1 + * @magentoConfigFixture default/newrelicreporting/general/app_name beverly_hills + * @magentoConfigFixture default/newrelicreporting/general/separate_apps 1 + */ + public function testAppNameIsSetWhenConfiguredCorrectly() + { + $newRelicWrapper = $this->getMockBuilder(NewRelicWrapper::class) + ->setMethods(['setAppName']) + ->getMock(); + + $this->objectManager->configure([NewRelicWrapper::class => ['shared' => true]]); + $this->objectManager->addSharedInstance($newRelicWrapper, NewRelicWrapper::class); + + $newRelicWrapper->expects($this->once()) + ->method('setAppName') + ->with($this->equalTo('beverly_hills;beverly_hills_90210')); + + $state = $this->objectManager->get(State::class); + + $state->setAreaCode('90210'); + } + + /** + * @magentoConfigFixture default/newrelicreporting/general/enable 1 + * @magentoConfigFixture default/newrelicreporting/general/app_name beverly_hills + * @magentoConfigFixture default/newrelicreporting/general/separate_apps 0 + */ + public function testAppNameIsNotSetWhenDisabled() + { + $newRelicWrapper = $this->getMockBuilder(NewRelicWrapper::class) + ->setMethods(['setAppName']) + ->getMock(); + + $this->objectManager->configure([NewRelicWrapper::class => ['shared' => true]]); + $this->objectManager->addSharedInstance($newRelicWrapper, NewRelicWrapper::class); + + $newRelicWrapper->expects($this->never())->method('setAppName'); + + $state = $this->objectManager->get(State::class); + + $state->setAreaCode('90210'); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterQueueTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterQueueTest.php index 5c1a11756c1b1..7a0ac030d120b 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterQueueTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterQueueTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Newsletter\Controller\Adminhtml; +use Magento\Framework\App\Request\Http as HttpRequest; + /** * @magentoAppArea adminhtml */ @@ -15,6 +17,9 @@ class NewsletterQueueTest extends \Magento\TestFramework\TestCase\AbstractBacken */ protected $_model; + /** + * @inheritDoc + */ protected function setUp() { parent::setUp(); @@ -23,6 +28,9 @@ protected function setUp() ); } + /** + * @inheritDoc + */ protected function tearDown() { /** @@ -47,6 +55,7 @@ public function testSaveActionQueueTemplateAndVerifySuccessMessage() 'subject' => 'test subject', 'text' => 'newsletter text', ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postForQueue); // Loading by code, since ID will vary. template_code is not actually used to load anywhere else. diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterTemplateTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterTemplateTest.php index 50e89d92e434c..ae57703f9e8e2 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterTemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Adminhtml/NewsletterTemplateTest.php @@ -20,6 +20,9 @@ class NewsletterTemplateTest extends \Magento\TestFramework\TestCase\AbstractBac */ protected $model; + /** + * @inheritDoc + */ protected function setUp() { parent::setUp(); @@ -39,6 +42,9 @@ protected function setUp() ); } + /** + * @inheritDoc + */ protected function tearDown() { /** @@ -138,19 +144,6 @@ public function testSaveActionTemplateWithGetAndVerifyRedirect() $this->getRequest()->setMethod(\Zend\Http\Request::METHOD_GET)->setParam('id', $this->model->getId()); $this->dispatch('backend/newsletter/template/save'); - /** - * Check that errors was generated and set to session - */ - $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR); - - /** - * Check that correct redirect performed. - */ - $backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Backend\Model\UrlInterface::class - ); - $backendUrlModel->turnOffSecretKey(); - $url = $backendUrlModel->getUrl('newsletter'); - $this->assertRedirect($this->stringStartsWith($url)); + $this->assertEquals(404, $this->getResponse()->getStatusCode()); } } diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php index bd641dab26c09..cb83fa3abd857 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php @@ -293,6 +293,7 @@ public function testReturnFromPaypal() /** * The case when handling address data from Paypal button. * System's address fields are replacing from export Paypal data. + * Billing and Shipping address are the same * * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php * @magentoAppIsolation enabled @@ -307,18 +308,65 @@ public function testReturnFromPaypalButton() $this->checkoutModel->returnFromPaypal('token'); $shippingAddress = $quote->getShippingAddress(); - $prefix = ''; + $billingAddress = $quote->getBillingAddress(); + $exportedShippingData = $this->getExportedData()['shipping']; + + $this->assertEquals([$exportedShippingData['street']], $shippingAddress->getStreet()); + $this->assertEquals($exportedShippingData['firstname'], $shippingAddress->getFirstname()); + $this->assertEquals($exportedShippingData['city'], $shippingAddress->getCity()); + $this->assertEquals($exportedShippingData['telephone'], $shippingAddress->getTelephone()); + $this->assertEquals($exportedShippingData['email'], $shippingAddress->getEmail()); + + $this->assertEquals([$exportedShippingData['street']], $billingAddress->getStreet()); + $this->assertEquals($exportedShippingData['firstname'], $billingAddress->getFirstname()); + $this->assertEquals($exportedShippingData['city'], $billingAddress->getCity()); + $this->assertEquals($exportedShippingData['telephone'], $billingAddress->getTelephone()); + $this->assertEquals($exportedShippingData['email'], $billingAddress->getEmail()); + } + + /** + * The case when handling address data from Paypal button. + * System's address fields are replacing from export Paypal data. + * Billing and Shipping address are different + * + * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ + public function testReturnFromPaypalButtonWithReturnBillingAddress() + { + $quote = $this->getFixtureQuote(); + $this->paypalConfig->expects($this->exactly(2)) + ->method('getValue') + ->with('requireBillingAddress') + ->willReturn(1); + $this->prepareCheckoutModel($quote); + $quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1); + + $this->checkoutModel->returnFromPaypal('token'); - $this->assertEquals([$prefix . $this->getExportedData()['street']], $shippingAddress->getStreet()); - $this->assertEquals($prefix . $this->getExportedData()['firstname'], $shippingAddress->getFirstname()); - $this->assertEquals($prefix . $this->getExportedData()['city'], $shippingAddress->getCity()); - $this->assertEquals($prefix . $this->getExportedData()['telephone'], $shippingAddress->getTelephone()); - $this->assertEquals($prefix . $this->getExportedData()['email'], $shippingAddress->getEmail()); + $shippingAddress = $quote->getShippingAddress(); + $billingAddress = $quote->getBillingAddress(); + $exportedBillingData = $this->getExportedData()['billing']; + $exportedShippingData = $this->getExportedData()['shipping']; + + $this->assertEquals([$exportedShippingData['street']], $shippingAddress->getStreet()); + $this->assertEquals($exportedShippingData['firstname'], $shippingAddress->getFirstname()); + $this->assertEquals($exportedShippingData['city'], $shippingAddress->getCity()); + $this->assertEquals($exportedShippingData['telephone'], $shippingAddress->getTelephone()); + $this->assertEquals($exportedShippingData['email'], $shippingAddress->getEmail()); + + $this->assertEquals([$exportedBillingData['street']], $billingAddress->getStreet()); + $this->assertEquals($exportedBillingData['firstname'], $billingAddress->getFirstname()); + $this->assertEquals($exportedBillingData['city'], $billingAddress->getCity()); + $this->assertEquals($exportedBillingData['telephone'], $billingAddress->getTelephone()); + $this->assertEquals($exportedBillingData['email'], $billingAddress->getEmail()); } /** * The case when handling address data from the checkout. * System's address fields are not replacing from export PayPal data. + * Billing and Shipping address are the same * * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php * @magentoAppIsolation enabled @@ -326,20 +374,67 @@ public function testReturnFromPaypalButton() */ public function testReturnFromPaypalIfCheckout() { + $prefix = 'exported'; $quote = $this->getFixtureQuote(); - $this->prepareCheckoutModel($quote); + $this->prepareCheckoutModel($quote, $prefix); $quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0); + $originalShippingAddress = $quote->getShippingAddress(); + $originalBillingAddress = $quote->getBillingAddress(); + $this->checkoutModel->returnFromPaypal('token'); $shippingAddress = $quote->getShippingAddress(); + $billingAddress = $quote->getBillingAddress(); + + $this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet()); + $this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname()); + $this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity()); + $this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone()); + + $this->assertEquals($originalBillingAddress->getStreet(), $billingAddress->getStreet()); + $this->assertEquals($originalBillingAddress->getFirstname(), $billingAddress->getFirstname()); + $this->assertEquals($originalBillingAddress->getCity(), $billingAddress->getCity()); + $this->assertEquals($originalBillingAddress->getTelephone(), $billingAddress->getTelephone()); + } + /** + * The case when handling address data from the checkout. + * System's address fields are replacing billing address from export PayPal data. + * Billing and Shipping address are different + * + * @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ + public function testReturnFromPaypalIfCheckoutWithReturnBillingAddress() + { $prefix = 'exported'; + $quote = $this->getFixtureQuote(); + $this->paypalConfig->expects($this->exactly(2)) + ->method('getValue') + ->with('requireBillingAddress') + ->willReturn(1); + $this->prepareCheckoutModel($quote, $prefix); + $quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0); + + $originalShippingAddress = $quote->getShippingAddress(); + + $this->checkoutModel->returnFromPaypal('token'); - $this->assertNotEquals([$prefix . $this->getExportedData()['street']], $shippingAddress->getStreet()); - $this->assertNotEquals($prefix . $this->getExportedData()['firstname'], $shippingAddress->getFirstname()); - $this->assertNotEquals($prefix . $this->getExportedData()['city'], $shippingAddress->getCity()); - $this->assertNotEquals($prefix . $this->getExportedData()['telephone'], $shippingAddress->getTelephone()); + $shippingAddress = $quote->getShippingAddress(); + $billingAddress = $quote->getBillingAddress(); + $exportedBillingData = $this->getExportedData()['billing']; + + $this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet()); + $this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname()); + $this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity()); + $this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone()); + + $this->assertEquals([$prefix . $exportedBillingData['street']], $billingAddress->getStreet()); + $this->assertEquals($prefix . $exportedBillingData['firstname'], $billingAddress->getFirstname()); + $this->assertEquals($prefix . $exportedBillingData['city'], $billingAddress->getCity()); + $this->assertEquals($prefix . $exportedBillingData['telephone'], $billingAddress->getTelephone()); } /** @@ -363,7 +458,7 @@ public function testReturnFromPayPalForCustomerWithEmptyAddresses(): void $billingAddress = $quote->getBillingAddress(); - $this->performQuoteAddressAssertions($billingAddress, $this->getExportedData()); + $this->performQuoteAddressAssertions($billingAddress, $this->getExportedData()['billing']); } /** @@ -437,7 +532,7 @@ private function performQuoteAddressAssertions(Address $address, array $expected * * @param Quote $quote */ - private function prepareCheckoutModel(Quote $quote) + private function prepareCheckoutModel(Quote $quote, $prefix = '') { $this->checkoutModel = $this->objectManager->create( Checkout::class, @@ -448,11 +543,11 @@ private function prepareCheckoutModel(Quote $quote) ] ); - $exportedBillingAddress = $this->getExportedAddressFixture($this->getExportedData()); + $exportedBillingAddress = $this->getExportedAddressFixture($this->getExportedData()['billing'], $prefix); $this->api->method('getExportedBillingAddress') ->willReturn($exportedBillingAddress); - $exportedShippingAddress = $this->getExportedAddressFixture($this->getExportedData()); + $exportedShippingAddress = $this->getExportedAddressFixture($this->getExportedData()['shipping'], $prefix); $this->api->method('getExportedShippingAddress') ->willReturn($exportedShippingAddress); @@ -468,16 +563,30 @@ private function prepareCheckoutModel(Quote $quote) private function getExportedData(): array { return [ - 'email' => 'customer@example.com', - 'firstname' => 'John', - 'lastname' => 'Doe', - 'country' => 'US', - 'region' => 'Colorado', - 'region_id' => '13', - 'city' => 'Denver', - 'street' => '66 Pearl St', - 'postcode' => '80203', - 'telephone' => '555-555-555', + 'shipping' => [ + 'email' => 'customer@example.com', + 'firstname' => 'John', + 'lastname' => 'Doe', + 'country' => 'US', + 'region' => 'Colorado', + 'region_id' => '13', + 'city' => 'Denver', + 'street' => '66 Pearl St', + 'postcode' => '80203', + 'telephone' => '555-555-555' + ], + 'billing' => [ + 'email' => 'customer@example.com', + 'firstname' => 'Jane', + 'lastname' => 'Doe', + 'country' => 'US', + 'region' => 'Texas', + 'region_id' => '13', + 'city' => 'Austin', + 'street' => '1100 Congress Ave', + 'postcode' => '78701', + 'telephone' => '555-555-555' + ] ]; } diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php index 0b0071beb5133..356117f2b3dc8 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php @@ -3,10 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Quote\Model; +use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Model\Product\Type; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; /** * Class for testing QuoteManagement model @@ -14,79 +22,120 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase { /** - * Create order with product that has child items + * @var ObjectManager + */ + private $objectManager; + + /** + * @var CartManagementInterface + */ + private $cartManagement; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->objectManager = Bootstrap::getObjectManager(); + + $this->cartManagement = $this->objectManager->create(CartManagementInterface::class); + } + + /** + * Creates order with product that has child items. * * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/quote_with_bundle.php */ public function testSubmit() { - /** - * Preconditions: - * Load quote with Bundle product that has at least two child products - */ - $objectManager = Bootstrap::getObjectManager(); - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $objectManager->create(\Magento\Quote\Model\Quote::class); - $quote->load('test01', 'reserved_order_id'); - - /** Execute SUT */ - /** @var \Magento\Quote\Api\CartManagementInterface $model */ - $cartManagement = $objectManager->create(\Magento\Quote\Api\CartManagementInterface::class); - /** @var \Magento\Sales\Api\OrderRepositoryInterface $orderRepository */ - $orderRepository = $objectManager->create(\Magento\Sales\Api\OrderRepositoryInterface::class); - $orderId = $cartManagement->placeOrder($quote->getId()); + $quote = $this->getQuote('test01'); + $orderId = $this->cartManagement->placeOrder($quote->getId()); + + /** @var OrderRepositoryInterface $orderRepository */ + $orderRepository = $this->objectManager->create(OrderRepositoryInterface::class); $order = $orderRepository->get($orderId); - /** Check if SUT caused expected effects */ $orderItems = $order->getItems(); - $this->assertCount(3, $orderItems); + self::assertCount(3, $orderItems); foreach ($orderItems as $orderItem) { if ($orderItem->getProductType() == Type::TYPE_SIMPLE) { - $this->assertNotEmpty($orderItem->getParentItem(), 'Parent is not set for child product'); - $this->assertNotEmpty($orderItem->getParentItemId(), 'Parent is not set for child product'); + self::assertNotEmpty($orderItem->getParentItem(), 'Parent is not set for child product'); + self::assertNotEmpty($orderItem->getParentItemId(), 'Parent is not set for child product'); } } } /** - * Create order with product that has child items and one of them was deleted + * Tries to create order with product that has child items and one of them was deleted. * * @magentoAppArea adminhtml * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/quote_with_bundle.php + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Some of the products below do not have all the required options. */ public function testSubmitWithDeletedItem() { - /** - * Preconditions: - * Load quote with Bundle product that have at least to child products - */ - $objectManager = Bootstrap::getObjectManager(); - /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ - $productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); + /** @var ProductRepositoryInterface $productRepository */ + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); $product = $productRepository->get('simple-2'); $productRepository->delete($product); - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $objectManager->create(\Magento\Quote\Model\Quote::class); - $quote->load('test01', 'reserved_order_id'); - - /** Execute SUT */ - /** @var \Magento\Quote\Api\CartManagementInterface $model */ - $cartManagement = $objectManager->create(\Magento\Quote\Api\CartManagementInterface::class); - /** @var \Magento\Sales\Api\OrderRepositoryInterface $orderRepository */ - $orderRepository = $objectManager->create(\Magento\Sales\Api\OrderRepositoryInterface::class); - $orderId = $cartManagement->placeOrder($quote->getId()); - $order = $orderRepository->get($orderId); + $quote = $this->getQuote('test01'); - /** Check if SUT caused expected effects */ - $orderItems = $order->getItems(); - $this->assertCount(2, $orderItems); - foreach ($orderItems as $orderItem) { - if ($orderItem->getProductType() == Type::TYPE_SIMPLE) { - $this->assertNotEmpty($orderItem->getParentItem(), 'Parent is not set for child product'); - $this->assertNotEmpty($orderItem->getParentItemId(), 'Parent is not set for child product'); - } - } + $this->cartManagement->placeOrder($quote->getId()); + } + + /** + * Tries to create order with item of stock during checkout. + * + * @magentoDataFixture Magento/Sales/_files/quote.php + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Some of the products are out of stock. + * @magentoDbIsolation enabled + */ + public function testSubmitWithItemOutOfStock() + { + $this->makeProductOutOfStock('simple'); + $quote = $this->getQuote('test01'); + $this->cartManagement->placeOrder($quote->getId()); + } + + /** + * Gets quote by reserved order ID. + * + * @param string $reservedOrderId + * @return Quote + */ + private function getQuote(string $reservedOrderId): Quote + { + /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ + $searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class); + $searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId) + ->create(); + + /** @var CartRepositoryInterface $quoteRepository */ + $quoteRepository = $this->objectManager->get(CartRepositoryInterface::class); + $items = $quoteRepository->getList($searchCriteria) + ->getItems(); + + return array_pop($items); + } + + /** + * Makes provided product as out of stock. + * + * @param string $sku + * @return void + */ + private function makeProductOutOfStock(string $sku) + { + /** @var ProductRepositoryInterface $productRepository */ + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); + $product = $productRepository->get($sku); + $extensionAttributes = $product->getExtensionAttributes(); + $stockItem = $extensionAttributes->getStockItem(); + $stockItem->setIsInStock(false); + $productRepository->save($product); } } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php index b8446839c8c99..0af32b32c7d48 100644 --- a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php @@ -3,10 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Reports\Block\Adminhtml\Shopcart\Abandoned; use Magento\Quote\Model\Quote; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\View\LayoutInterface; /** * Test class for \Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid @@ -20,12 +23,12 @@ class GridTest extends \Magento\Reports\Block\Adminhtml\Shopcart\GridTestAbstrac /** * @return void */ - public function testGridContent() + public function testGridContent(): void { - /** @var \Magento\Framework\View\LayoutInterface $layout */ - $layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class); + /** @var LayoutInterface $layout */ + $layout = Bootstrap::getObjectManager()->get(LayoutInterface::class); /** @var Grid $grid */ - $grid = $layout->createBlock(\Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid::class); + $grid = $layout->createBlock(Grid::class); $grid->getRequest()->setParams(['filter' => base64_encode(urlencode('email=customer@example.com'))]); $result = $grid->getPreparedCollection(); @@ -35,4 +38,17 @@ public function testGridContent() $this->assertEquals('customer@example.com', $quote->getCustomerEmail()); $this->assertEquals(10.00, $quote->getSubtotal()); } + + /** + * @return void + */ + public function testPageSizeIsSetToNullWhenExportCsvFile(): void + { + /** @var LayoutInterface $layout */ + $layout = Bootstrap::getObjectManager()->get(LayoutInterface::class); + /** @var Grid $grid */ + $grid = $layout->createBlock(Grid::class); + $grid->getCsvFile(); + $this->assertNull($grid->getCollection()->getPageSize()); + } } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/SaveTest.php b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/SaveTest.php index b9573c99b4493..e2638b5df1f88 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/SaveTest.php @@ -8,6 +8,7 @@ use Magento\Backend\Model\Session\Quote; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\App\Request\Http; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\MessageInterface; use Magento\Quote\Api\CartRepositoryInterface; @@ -38,6 +39,7 @@ public function testExecuteWithPaymentOperation() 'email' => $email ] ]; + $this->getRequest()->setMethod(Http::METHOD_POST); $this->getRequest()->setPostValue(['order' => $data]); /** @var OrderService|MockObject $orderService */ diff --git a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/CreateTest.php index e071dde26a263..efb1b12fc60ed 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/CreateTest.php @@ -8,10 +8,13 @@ use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Backend\Model\Session\Quote; use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @magentoAppArea adminhtml * @magentoDbIsolation enabled + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CreateTest extends \Magento\TestFramework\TestCase\AbstractBackendController { @@ -20,6 +23,11 @@ class CreateTest extends \Magento\TestFramework\TestCase\AbstractBackendControll */ protected $productRepository; + /** + * @inheritDoc + * + * @throws \Magento\Framework\Exception\AuthenticationException + */ protected function setUp() { parent::setUp(); @@ -27,8 +35,12 @@ protected function setUp() ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); } + /** + * Test LoadBlock being dispatched. + */ public function testLoadBlockAction() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('block', ','); $this->getRequest()->setParam('json', 1); $this->dispatch('backend/sales/order_create/loadBlock'); @@ -46,6 +58,7 @@ public function testLoadBlockActionData() )->addProducts( [$product->getId() => ['qty' => 1]] ); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('block', 'data'); $this->getRequest()->setParam('json', 1); $this->dispatch('backend/sales/order_create/loadBlock'); @@ -57,10 +70,14 @@ public function testLoadBlockActionData() } /** + * @param string $block Block name. + * @param string $expected Contains HTML. + * * @dataProvider loadBlockActionsDataProvider */ public function testLoadBlockActions($block, $expected) { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('block', $block); $this->getRequest()->setParam('json', 1); $this->dispatch('backend/sales/order_create/loadBlock'); @@ -68,6 +85,9 @@ public function testLoadBlockActions($block, $expected) $this->assertContains($expected, $html); } + /** + * @return array + */ public function loadBlockActionsDataProvider() { return [ @@ -90,6 +110,7 @@ public function testLoadBlockActionItems() )->addProducts( [$product->getId() => ['qty' => 1]] ); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setParam('block', 'items'); $this->getRequest()->setParam('json', 1); $this->dispatch('backend/sales/order_create/loadBlock'); @@ -215,6 +236,11 @@ public function testConfigureProductToAddAction() $this->assertContains(sprintf('"productId":"%s"', $product->getEntityId()), $body); } + /** + * Test not allowing to save. + * + * @throws \Magento\Framework\Exception\LocalizedException + */ public function testDeniedSaveAction() { $this->_objectManager->configure( @@ -230,6 +256,7 @@ public function testDeniedSaveAction() \Magento\TestFramework\Helper\Bootstrap::getInstance() ->loadArea('adminhtml'); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/sales/order_create/save'); $this->assertEquals('403', $this->getResponse()->getHttpResponseCode()); } @@ -263,6 +290,7 @@ public function testSyncBetweenQuoteAddresses() 'region' => 'Kyivska', 'region_id' => 1 ]; + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'order' => ['billing_address' => $data], diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_cart_fixed_discount_rollback.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_cart_fixed_discount_rollback.php new file mode 100644 index 0000000000000..33a8b4285d8d7 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_cart_fixed_discount_rollback.php @@ -0,0 +1,17 @@ +get(\Magento\Framework\Registry::class); + +/** @var Magento\SalesRule\Model\Rule $rule */ +$rule = $registry->registry('cart_rule_fixed_discount_coupon'); +if ($rule) { + $rule->delete(); +} diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_code_with_wildcard_rollback.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_code_with_wildcard_rollback.php index 776c302210351..c9613c371bbe5 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_code_with_wildcard_rollback.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/coupon_code_with_wildcard_rollback.php @@ -14,8 +14,19 @@ $objectManager = Bootstrap::getObjectManager(); +/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ +$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); +$searchCriteria = $searchCriteriaBuilder->addFilter('name', '5$ fixed discount on whole cart') + ->create(); + +/** @var RuleRepositoryInterface $ruleRepository */ +$ruleRepository = Bootstrap::getObjectManager()->get(RuleRepositoryInterface::class); +$items = $ruleRepository->getList($searchCriteria) + ->getItems(); + +$salesRule = array_pop($items); + /** @var Rule $salesRule */ -$salesRule = getSalesRule('5$ fixed discount on whole cart'); if ($salesRule !== null) { /** @var RuleRepositoryInterface $ruleRepository */ $ruleRepository = $objectManager->get(RuleRepositoryInterface::class); @@ -29,18 +40,3 @@ $couponRepository = $objectManager->get(CouponRepositoryInterface::class); $couponRepository->deleteById($coupon->getCouponId()); } - -function getSalesRule(string $name) -{ - /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ - $searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); - $searchCriteria = $searchCriteriaBuilder->addFilter('name', $name) - ->create(); - - /** @var RuleRepositoryInterface $ruleRepository */ - $ruleRepository = Bootstrap::getObjectManager()->get(RuleRepositoryInterface::class); - $items = $ruleRepository->getList($searchCriteria) - ->getItems(); - - return array_pop($items); -} diff --git a/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php b/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php index 90ceaa4fcc5a0..e0a1321092a68 100644 --- a/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php +++ b/dev/tests/integration/testsuite/Magento/Store/App/Request/PathInfoProcessorTest.php @@ -14,7 +14,7 @@ class PathInfoProcessorTest extends \PHPUnit\Framework\TestCase /** * @var \Magento\Store\App\Request\PathInfoProcessor */ - protected $pathProcessor; + private $pathProcessor; protected function setUp() { @@ -31,7 +31,11 @@ public function testProcessNotValidStoreCode($pathInfo) { /** @var \Magento\Framework\App\RequestInterface $request */ $request = Bootstrap::getObjectManager()->create(\Magento\Framework\App\RequestInterface::class); - $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); + $info = $this->pathProcessor->process($request, $pathInfo); + $this->assertEquals($pathInfo, $info); } public function notValidStoreCodeDataProvider() @@ -46,7 +50,7 @@ public function notValidStoreCodeDataProvider() * @covers \Magento\Store\App\Request\PathInfoProcessor::process * @magentoDataFixture Magento/Store/_files/core_fixturestore.php */ - public function testProcessValidStoreCodeCase1() + public function testProcessValidStoreDisabledStoreUrl() { /** @var \Magento\Store\Model\Store $store */ $store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class); @@ -57,6 +61,7 @@ public function testProcessValidStoreCodeCase1() /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); $config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode()); $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); @@ -66,7 +71,7 @@ public function testProcessValidStoreCodeCase1() * @covers \Magento\Store\App\Request\PathInfoProcessor::process * @magentoDataFixture Magento/Store/_files/core_fixturestore.php */ - public function testProcessValidStoreCodeCase2() + public function testProcessValidStoreCodeCaseProcessStoreName() { /** @var \Magento\Store\Model\Store $store */ $store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class); @@ -77,6 +82,7 @@ public function testProcessValidStoreCodeCase2() /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); $this->assertEquals('/m/c/a', $this->pathProcessor->process($request, $pathInfo)); @@ -86,7 +92,7 @@ public function testProcessValidStoreCodeCase2() * @covers \Magento\Store\App\Request\PathInfoProcessor::process * @magentoDataFixture Magento/Store/_files/core_fixturestore.php */ - public function testProcessValidStoreCodeCase3() + public function testProcessValidStoreCodeWhenStoreIsDirectFrontNameWithFrontName() { /** @var \Magento\Store\Model\Store $store */ $store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class); @@ -100,9 +106,77 @@ public function testProcessValidStoreCodeCase3() /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); - $this->assertEquals('noroute', $request->getActionName()); + $this->assertEquals(\Magento\Framework\App\Router\Base::NO_ROUTE, $request->getActionName()); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + */ + public function testProcessValidStoreCodeWhenStoreCodeInUrlIsDisabledWithFrontName() + { + /** @var \Magento\Store\Model\Store $store */ + $store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class); + $store->load('fixturestore', 'code'); + + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create( + \Magento\Framework\App\RequestInterface::class, + ['directFrontNames' => ['someFrontName' => true]] + ); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); + $config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode()); + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php + */ + public function testProcessValidStoreCodeWhenStoreCodeisAdmin() + { + /** @var \Magento\Store\Model\Store $store */ + $store = Bootstrap::getObjectManager()->get(\Magento\Store\Model\Store::class); + $store->load('fixturestore', 'code'); + + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create( + \Magento\Framework\App\RequestInterface::class, + ['directFrontNames' => ['someFrontName' => true]] + ); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, true); + $config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode()); + $pathInfo = sprintf('/%s/m/c/a', 'admin'); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + } + + /** + * @covers \Magento\Store\App\Request\PathInfoProcessor::process + */ + public function testProcessValidStoreCodeWhenUrlConfigIsDisabled() + { + /** @var \Magento\Framework\App\RequestInterface $request */ + $request = Bootstrap::getObjectManager()->create( + \Magento\Framework\App\RequestInterface::class, + ['directFrontNames' => ['someFrontName' => true]] + ); + + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ + $config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); + $config->setValue(Store::XML_PATH_STORE_IN_URL, false); + $pathInfo = sprintf('/%s/m/c/a', 'whatever'); + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); + $this->assertEquals(null, $request->getActionName()); } } diff --git a/dev/tests/integration/testsuite/Magento/Swatches/Controller/Adminhtml/Product/AttributeTest.php b/dev/tests/integration/testsuite/Magento/Swatches/Controller/Adminhtml/Product/AttributeTest.php index 969d9530ae542..e222e6fda48d7 100644 --- a/dev/tests/integration/testsuite/Magento/Swatches/Controller/Adminhtml/Product/AttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Swatches/Controller/Adminhtml/Product/AttributeTest.php @@ -7,6 +7,8 @@ namespace Magento\Swatches\Controller\Adminhtml\Product; +use Magento\Framework\App\Request\Http as HttpRequest; +use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Exception\LocalizedException; /** @@ -17,6 +19,21 @@ */ class AttributeTest extends \Magento\TestFramework\TestCase\AbstractBackendController { + /** + * @var FormKey + */ + private $formKey; + + /** + * @inheritDoc + */ + protected function setUp() + { + parent::setUp(); + + $this->formKey = $this->_objectManager->get(FormKey::class); + } + /** * Generate random hex color. * @@ -112,7 +129,6 @@ private function getAttributePreset() : array { return [ 'serialized_options' => '[]', - 'form_key' => 'XxtpPYjm2YPYUlAt', 'frontend_label' => [ 0 => 'asdasd', 1 => '', @@ -175,7 +191,9 @@ public function testLargeOptionsDataSet( int $expectedOptionsCount, array $expectedLabels ) : void { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($attributeData); + $this->getRequest()->setPostValue('form_key', $this->formKey->getFormKey()); $this->dispatch('backend/catalog/product_attribute/save'); $entityTypeId = $this->_objectManager->create( \Magento\Eav\Model\Entity::class diff --git a/dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config/SaveTest.php b/dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config/SaveTest.php index 95fcf24894c87..cb684c0216889 100644 --- a/dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/Theme/Controller/Adminhtml/System/Design/Config/SaveTest.php @@ -6,6 +6,7 @@ namespace Magento\Theme\Controller\Adminhtml\System\Design\Config; +use Magento\Framework\App\Request\Http; use Magento\Framework\Data\Form\FormKey; use Magento\TestFramework\TestCase\AbstractBackendController; @@ -29,6 +30,9 @@ class SaveTest extends AbstractBackendController */ protected $uri = 'backend/theme/design_config/save'; + /** + * @inheritdoc + */ protected function setUp() { parent::setUp(); @@ -36,6 +40,7 @@ protected function setUp() $this->formKey = $this->_objectManager->get( FormKey::class ); + $this->httpMethod = Http::METHOD_POST; } /** @@ -107,12 +112,11 @@ private function getRequestParams() ]; } + /** + * @inheritDoc + */ public function testAclHasAccess() { - $this->getRequest()->setMethod( - \Zend\Http\Request::METHOD_POST - ); - $this->getRequest()->setParams( [ 'form_key' => $this->formKey->getFormKey() diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php index 995ec5f6bed85..9cf8fc43951d4 100644 --- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php +++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php @@ -6,6 +6,7 @@ namespace Magento\User\Controller\Adminhtml; +use Magento\Framework\App\Request\Http as HttpRequest; use Magento\TestFramework\Bootstrap; /** @@ -35,6 +36,7 @@ public function testIndexAction() */ public function testSaveActionNoData() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->dispatch('backend/admin/user/save'); $this->assertRedirect($this->stringContains('backend/admin/user/index/')); } @@ -55,6 +57,7 @@ public function testSaveActionWrongId() $userId = $user->getId(); $this->assertNotEmpty($userId, 'Broken fixture'); $user->delete(); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue('user_id', $userId); $this->dispatch('backend/admin/user/save'); $this->assertSessionMessages( @@ -72,6 +75,7 @@ public function testSaveActionWrongId() public function testSaveActionMissingCurrentAdminPassword() { $fixture = uniqid(); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'username' => $fixture, @@ -99,6 +103,7 @@ public function testSaveActionMissingCurrentAdminPassword() public function testSaveAction() { $fixture = uniqid(); + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'username' => $fixture, @@ -126,6 +131,7 @@ public function testSaveAction() */ public function testSaveActionDuplicateUser() { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue( [ 'username' => 'adminUser', @@ -147,13 +153,17 @@ public function testSaveActionDuplicateUser() } /** - * Verify password change properly updates fields when the request is valid + * Verify password change properly updates fields when the request is valid. + * + * @param array $postData + * @param bool $isPasswordCorrect * * @magentoDbIsolation enabled * @dataProvider saveActionPasswordChangeDataProvider */ public function testSaveActionPasswordChange($postData, $isPasswordCorrect) { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $this->getRequest()->setPostValue($postData); $this->dispatch('backend/admin/user/save'); diff --git a/dev/tests/integration/testsuite/Magento/Widget/Controller/Adminhtml/WidgetTest.php b/dev/tests/integration/testsuite/Magento/Widget/Controller/Adminhtml/WidgetTest.php index 26ed706e3eccb..f5b5fe533e108 100644 --- a/dev/tests/integration/testsuite/Magento/Widget/Controller/Adminhtml/WidgetTest.php +++ b/dev/tests/integration/testsuite/Magento/Widget/Controller/Adminhtml/WidgetTest.php @@ -15,7 +15,7 @@ class WidgetTest extends \Magento\TestFramework\TestCase\AbstractBackendControll */ public function testLoadOptionsAction() { - $this->getRequest()->setPostValue( + $this->getRequest()->setParam( 'widget', '{"widget_type":"Magento\\\\Cms\\\\Block\\\\Widget\\\\Page\\\\Link","values":{}}' ); diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php index 8edc916f2afd5..92eae7a3fe3d7 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Controller/IndexTest.php @@ -122,6 +122,7 @@ public function testAddActionProductNameXss() } /** + * @magentoDbIsolation disabled * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php */ public function testAllcartAction() diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php index 99f9aa4991b5e..b684da05dd254 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php @@ -6,6 +6,7 @@ namespace Magento\Wishlist\Model; use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; @@ -85,4 +86,39 @@ public function testAddNewItemInvalidWishlistItemConfiguration() ); $this->wishlist->addNewItem($product); } + + /** + * @magentoDbIsolation disabled + * @magentoDataFixture Magento/Wishlist/_files/wishlist.php + */ + public function testGetItemCollection() + { + $productSku = 'simple'; + $customerId = 1; + + $this->wishlist->loadByCustomerId($customerId, true); + $itemCollection = $this->wishlist->getItemCollection(); + /** @var \Magento\Wishlist\Model\Item $item */ + $item = $itemCollection->getFirstItem(); + $this->assertEquals($productSku, $item->getProduct()->getSku()); + } + + /** + * @magentoDbIsolation disabled + * @magentoDataFixture Magento/Wishlist/_files/wishlist.php + */ + public function testGetItemCollectionWithDisabledProduct() + { + $productSku = 'simple'; + $customerId = 1; + + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); + $product = $productRepository->get($productSku); + $product->setStatus(ProductStatus::STATUS_DISABLED); + $productRepository->save($product); + + $this->wishlist->loadByCustomerId($customerId, true); + $itemCollection = $this->wishlist->getItemCollection(); + $this->assertEmpty($itemCollection->getItems()); + } } diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_rollback.php b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_rollback.php new file mode 100644 index 0000000000000..61b5bbb7bd32f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_rollback.php @@ -0,0 +1,25 @@ +get(\Magento\Framework\Registry::class); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Wishlist\Model\Wishlist $wishlist */ +$wishlist = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class); +$wishlist->loadByCustomerId(1); +$wishlist->delete(); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); + +require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_rollback.php'; +require __DIR__ . '/../../../Magento/Customer/_files/customer_rollback.php'; diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_product_qty_increments_rollback.php b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_product_qty_increments_rollback.php new file mode 100644 index 0000000000000..91392fec6b721 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_product_qty_increments_rollback.php @@ -0,0 +1,25 @@ +get(\Magento\Framework\Registry::class); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Wishlist\Model\Wishlist $wishlist */ +$wishlist = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class); +$wishlist->loadByCustomerId(1); +$wishlist->delete(); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); + +require __DIR__ . '/../../../Magento/Catalog/_files/product_special_price_rollback.php'; +require __DIR__ . '/../../../Magento/Customer/_files/customer_rollback.php'; diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/view/product-ids-resolver.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/view/product-ids-resolver.test.js new file mode 100644 index 0000000000000..be92b6814da3b --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/view/product-ids-resolver.test.js @@ -0,0 +1,62 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint-disable max-nested-callbacks */ +define([ + 'squire', + 'jquery', + 'ko', + 'jquery/ui' +], function (Squire, $, ko) { + 'use strict'; + + var injector = new Squire(), + mocks = { + 'Magento_Catalog/js/product/view/product-ids': ko.observableArray([]) + }, + form = $( + '' + + '' + + '' + ), + productIdResolver; + + beforeAll(function (done) { + + injector.mock(mocks); + injector.require( + [ + 'Magento_Catalog/js/product/view/product-ids-resolver' + ], function (resolver) { + productIdResolver = resolver; + done(); + } + ); + }); + + describe('Magento_Catalog/js/product/view/product-ids-resolver', function () { + var dataProvider = [ + { + ids: [], + expected: ['1'] + }, + { + ids: ['2', '3'], + expected: ['2', '3', '1'] + }, + { + ids: ['3', '1', '5'], + expected: ['3', '1', '5'] + } + ]; + + dataProvider.forEach(function (data) { + it('resolved product id\'s', function () { + mocks['Magento_Catalog/js/product/view/product-ids'](data.ids); + expect(productIdResolver(form)).toEqual(data.expected); + }); + }); + }); +}); diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js index 8b4fae5a69461..7c21a8aae2f26 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js @@ -26,15 +26,18 @@ define([ 'items': [ { 'item_id': 1, - 'product_sku': 'bundle' + 'product_sku': 'bundle', + 'product_id': '1' }, { 'item_id': 5, - 'product_sku': 'simple' + 'product_sku': 'simple', + 'product_id': '5' }, { 'item_id': 7, - 'product_sku': 'configurable' + 'product_sku': 'configurable', + 'product_id': '7' } ] }, @@ -63,7 +66,9 @@ define([ sidebar._removeItemAfter(elem); expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); - expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', 'simple'); + expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', { + 'productIds': ['5'] + }); }); it('Cart item doesn\'t exists', function () { @@ -91,7 +96,7 @@ define([ sidebar._updateItemQtyAfter(elem); expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart'); - expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:updateCartItemQty', 'simple'); + expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:updateCartItemQty'); expect(sidebar._hideItemButton).toHaveBeenCalledWith(elem); }); diff --git a/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/AllPurposeAction.php b/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/AllPurposeAction.php new file mode 100644 index 0000000000000..fb5938be61328 --- /dev/null +++ b/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/AllPurposeAction.php @@ -0,0 +1,50 @@ +getFullQualifiedName(), true); + } catch (\Throwable $exception) { + //Couldn't load a class. + return; + } + + if (in_array(ActionInterface::class, $impl, true)) { + $methodsDefined = false; + foreach ($impl as $i) { + if (preg_match('/\\\Http[a-z]+ActionInterface$/i', $i)) { + $methodsDefined = true; + break; + } + } + if (!$methodsDefined) { + $this->addViolation($node, [$node->getFullQualifiedName()]); + } + } + } +} diff --git a/dev/tests/static/framework/Magento/CodeMessDetector/Test/Unit/Rule/Design/AllPurposeActionTest.php b/dev/tests/static/framework/Magento/CodeMessDetector/Test/Unit/Rule/Design/AllPurposeActionTest.php new file mode 100644 index 0000000000000..408853141e538 --- /dev/null +++ b/dev/tests/static/framework/Magento/CodeMessDetector/Test/Unit/Rule/Design/AllPurposeActionTest.php @@ -0,0 +1,134 @@ +createNodeMock($fakeAction); + $rule = new AllPurposeAction(); + $this->expectsRuleViolation($rule, $violates); + $rule->apply($node); + } + + /** + * @return array + */ + public function getCases(): array + { + return [ + [ + new class implements ActionInterface, HttpGetActionInterface { + /** + * @inheritDoc + */ + public function execute() + { + return null; + } + }, + false + ], + [ + new class implements ActionInterface { + /** + * @inheritDoc + */ + public function execute() + { + return null; + } + }, + true + ], + [ + new class implements HttpGetActionInterface { + /** + * @inheritDoc + */ + public function execute() + { + return null; + } + }, + false + ], + [ + new class { + + }, + false + ] + ]; + } + + /** + * @param object $dynamicObject + * + * @return ClassNode|MockObject + */ + private function createNodeMock($dynamicObject): MockObject + { + $node = $this->getMockBuilder(ClassNode::class) + ->disableOriginalConstructor() + ->disableProxyingToOriginalMethods() + ->setMethods([ + // disable name lookup from AST artifact + 'getNamespaceName', + 'getParentName', + 'getName', + 'getFullQualifiedName', + ]) + ->getMock(); + $node->expects($this->any()) + ->method('getFullQualifiedName') + ->willReturn(get_class($dynamicObject)); + + return $node; + } + + /** + * @param AllPurposeAction $rule + * @param bool $expects + * @return InvocationMocker + */ + private function expectsRuleViolation( + AllPurposeAction $rule, + bool $expects + ): InvocationMocker { + /** @var Report|MockObject $report */ + $report = $this->getMockBuilder(Report::class)->getMock(); + if ($expects) { + $violationExpectation = $this->atLeastOnce(); + } else { + $violationExpectation = $this->never(); + } + $invokation = $report->expects($violationExpectation) + ->method('addRuleViolation'); + $rule->setReport($report); + + return $invokation; + } +} diff --git a/dev/tests/static/framework/Magento/CodeMessDetector/resources/rulesets/design.xml b/dev/tests/static/framework/Magento/CodeMessDetector/resources/rulesets/design.xml index 61d4f7b3be81d..c9bfe4fe6e308 100644 --- a/dev/tests/static/framework/Magento/CodeMessDetector/resources/rulesets/design.xml +++ b/dev/tests/static/framework/Magento/CodeMessDetector/resources/rulesets/design.xml @@ -29,6 +29,31 @@ final class Foo } class Baz { final public function bad() {} +} + ]]> + + + + + ActionInterface +to restrict incoming requests by methods. + ]]> + + 2 + + + diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml index 76f76e2b23c56..fddb1e6fdfc14 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml @@ -47,5 +47,6 @@ + diff --git a/lib/internal/Magento/Framework/Amqp/Config.php b/lib/internal/Magento/Framework/Amqp/Config.php index 8fb827d9eb0d2..684c5cd38b1e4 100644 --- a/lib/internal/Magento/Framework/Amqp/Config.php +++ b/lib/internal/Magento/Framework/Amqp/Config.php @@ -131,10 +131,12 @@ public function __destruct() public function getValue($key) { $this->load(); - return isset($this->data[$key]) ? $this->data[$key] : null; + return $this->data[$key] ?? null; } /** + * Create amqp connection + * * @return AbstractConnection */ private function createConnection(): AbstractConnection diff --git a/lib/internal/Magento/Framework/App/Action/Forward.php b/lib/internal/Magento/Framework/App/Action/Forward.php index 7d6f956545b45..c81bc48ace4d5 100644 --- a/lib/internal/Magento/Framework/App/Action/Forward.php +++ b/lib/internal/Magento/Framework/App/Action/Forward.php @@ -10,6 +10,11 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\App\ResponseInterface; +/** + * Forward request further. + * + * @SuppressWarnings(PHPMD.AllPurposeAction) + */ class Forward extends AbstractAction { /** diff --git a/lib/internal/Magento/Framework/App/Action/HttpConnectActionInterface.php b/lib/internal/Magento/Framework/App/Action/HttpConnectActionInterface.php new file mode 100644 index 0000000000000..426fe584bade6 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Action/HttpConnectActionInterface.php @@ -0,0 +1,19 @@ +load(); - return isset($this->statuses[$cacheType]) ? (bool)$this->statuses[$cacheType] : false; + return (bool)($this->statuses[$cacheType] ?? false); } /** diff --git a/lib/internal/Magento/Framework/App/FrontController.php b/lib/internal/Magento/Framework/App/FrontController.php index b00cb3ed6090f..ba23e010e3e3f 100644 --- a/lib/internal/Magento/Framework/App/FrontController.php +++ b/lib/internal/Magento/Framework/App/FrontController.php @@ -14,6 +14,7 @@ use Magento\Framework\Message\ManagerInterface as MessageManager; use Magento\Framework\App\Action\AbstractAction; use Psr\Log\LoggerInterface; +use Magento\Framework\App\Request\Http as HttpRequest; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -45,6 +46,11 @@ class FrontController implements FrontControllerInterface */ private $logger; + /** + * @var bool + */ + private $validatedRequest = false; + /** * @param RouterListInterface $routerList * @param ResponseInterface $response @@ -72,13 +78,14 @@ public function __construct( /** * Perform action and generate response * - * @param RequestInterface $request + * @param RequestInterface|HttpRequest $request * @return ResponseInterface|ResultInterface * @throws \LogicException */ public function dispatch(RequestInterface $request) { \Magento\Framework\Profiler::start('routers_match'); + $this->validatedRequest = false; $routingCycleCounter = 0; $result = null; while (!$request->isDispatched() && $routingCycleCounter++ < 100) { @@ -109,44 +116,56 @@ public function dispatch(RequestInterface $request) } /** - * @param RequestInterface $request + * @param HttpRequest $request * @param ActionInterface $actionInstance * @throws NotFoundException * * @return ResponseInterface|ResultInterface */ private function processRequest( - RequestInterface $request, + HttpRequest $request, ActionInterface $actionInstance ) { $request->setDispatched(true); $this->response->setNoCacheHeaders(); - //Validating request. - try { - $this->requestValidator->validate( - $request, - $actionInstance - ); + $result = null; + + //Validating a request only once. + if (!$this->validatedRequest) { + try { + $this->requestValidator->validate( + $request, + $actionInstance + ); + } catch (InvalidRequestException $exception) { + //Validation failed - processing validation results. + $this->logger->debug( + 'Request validation failed for action "' + .get_class($actionInstance) .'"' + ); + $result = $exception->getReplaceResult(); + if ($messages = $exception->getMessages()) { + foreach ($messages as $message) { + $this->messages->addErrorMessage($message); + } + } + } + $this->validatedRequest = true; + } + //Validation did not produce a result to replace the action's. + if (!$result) { if ($actionInstance instanceof AbstractAction) { $result = $actionInstance->dispatch($request); } else { $result = $actionInstance->execute(); } - } catch (InvalidRequestException $exception) { - //Validation failed - processing validation results. - $this->logger->debug( - 'Request validation failed for action "' - .get_class($actionInstance) .'"' - ); - $result = $exception->getReplaceResult(); - if ($messages = $exception->getMessages()) { - foreach ($messages as $message) { - $this->messages->addErrorMessage($message); - } - } } + //handling redirect to 404 + if ($result instanceof NotFoundException) { + throw $result; + } return $result; } } diff --git a/lib/internal/Magento/Framework/App/Request/CompositeValidator.php b/lib/internal/Magento/Framework/App/Request/CompositeValidator.php new file mode 100644 index 0000000000000..2b5205fddc9c4 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Request/CompositeValidator.php @@ -0,0 +1,43 @@ +validators = $validators; + } + + /** + * @inheritDoc + */ + public function validate( + RequestInterface $request, + ActionInterface $action + ): void { + foreach ($this->validators as $validator) { + $validator->validate($request, $action); + } + } +} diff --git a/lib/internal/Magento/Framework/App/Request/Http.php b/lib/internal/Magento/Framework/App/Request/Http.php index 03a7200fbe203..4e709ed276954 100644 --- a/lib/internal/Magento/Framework/App/Request/Http.php +++ b/lib/internal/Magento/Framework/App/Request/Http.php @@ -95,6 +95,11 @@ class Http extends Request implements RequestContentInterface, RequestSafetyInte */ private $distroBaseUrl; + /** + * @var PathInfo + */ + private $pathInfoService; + /** * @param CookieReaderInterface $cookieReader * @param StringUtils $converter @@ -103,6 +108,7 @@ class Http extends Request implements RequestContentInterface, RequestSafetyInte * @param ObjectManagerInterface $objectManager * @param \Zend\Uri\UriInterface|string|null $uri * @param array $directFrontNames + * @param PathInfo|null $pathInfoService */ public function __construct( CookieReaderInterface $cookieReader, @@ -111,94 +117,71 @@ public function __construct( PathInfoProcessorInterface $pathInfoProcessor, ObjectManagerInterface $objectManager, $uri = null, - $directFrontNames = [] + $directFrontNames = [], + PathInfo $pathInfoService = null ) { parent::__construct($cookieReader, $converter, $uri); $this->routeConfig = $routeConfig; $this->pathInfoProcessor = $pathInfoProcessor; $this->objectManager = $objectManager; $this->directFrontNames = $directFrontNames; + $this->pathInfoService = $pathInfoService ?: \Magento\Framework\App\ObjectManager::getInstance()->get( + PathInfo::class + ); } /** - * Returns ORIGINAL_PATH_INFO. - * This value is calculated instead of reading PATH_INFO - * directly from $_SERVER due to cross-platform differences. + * Return the ORIGINAL_PATH_INFO. + * This value is calculated and processed from $_SERVER due to cross-platform differences. + * instead of reading PATH_INFO * * @return string */ public function getOriginalPathInfo() { if (empty($this->originalPathInfo)) { - $this->setPathInfo(); + $originalPathInfoFromRequest = $this->pathInfoService->getPathInfo( + $this->getRequestUri(), + $this->getBaseUrl() + ); + $this->originalPathInfo = (string)$this->pathInfoProcessor->process($this, $originalPathInfoFromRequest); + $this->requestString = $this->originalPathInfo + . $this->pathInfoService->getQueryString($this->getRequestUri()); } return $this->originalPathInfo; } /** - * Set the PATH_INFO string - * Set the ORIGINAL_PATH_INFO string - * - * @param string|null $pathInfo - * @return $this - */ - public function setPathInfo($pathInfo = null) - { - if ($pathInfo === null) { - $requestUri = $this->getRequestUri(); - if ('/' === $requestUri) { - return $this; - } - - $requestUri = $this->removeRepeatedSlashes($requestUri); - $parsedRequestUri = explode('?', $requestUri, 2); - $queryString = !isset($parsedRequestUri[1]) ? '' : '?' . $parsedRequestUri[1]; - $baseUrl = $this->getBaseUrl(); - $pathInfo = (string)substr($parsedRequestUri[0], (int)strlen($baseUrl)); - - if ($this->isNoRouteUri($baseUrl, $pathInfo)) { - $pathInfo = 'noroute'; - } - $pathInfo = $this->pathInfoProcessor->process($this, $pathInfo); - $this->originalPathInfo = (string)$pathInfo; - $this->requestString = $pathInfo . $queryString; - } - $this->pathInfo = (string)$pathInfo; - return $this; - } - - /** - * Remove repeated slashes from the start of the path. + * Return the path info * - * @param string $pathInfo * @return string */ - private function removeRepeatedSlashes($pathInfo) + public function getPathInfo() { - $firstChar = (string)substr($pathInfo, 0, 1); - if ($firstChar == '/') { - $pathInfo = '/' . ltrim($pathInfo, '/'); + if (empty($this->pathInfo)) { + $this->pathInfo = $this->getOriginalPathInfo(); } - - return $pathInfo; + return $this->pathInfo; } /** - * Check is URI should be marked as no route, helps route to 404 URI like `index.phpadmin`. + * Set the PATH_INFO string. + * + * Set the ORIGINAL_PATH_INFO string. * - * @param string $baseUrl - * @param string $pathInfo - * @return bool + * @param string|null $pathInfo + * @return $this */ - private function isNoRouteUri($baseUrl, $pathInfo) + public function setPathInfo($pathInfo = null) { - $firstChar = (string)substr($pathInfo, 0, 1); - return $baseUrl !== '' && !in_array($firstChar, ['/', '']); + $this->pathInfo = (string)$pathInfo; + return $this; } /** - * Check if code declared as direct access frontend name - * this mean what this url can be used without store code + * Check if code declared as direct access frontend name. + * + * This means what this url can be used without store code. * * @param string $code * @return bool @@ -284,8 +267,7 @@ public function getControllerModule() } /** - * Collect properties changed by _forward in protected storage - * before _forward was called first time. + * Collect properties changed by _forward in protected storage before _forward was called first time. * * @return $this */ @@ -427,6 +409,8 @@ public function getFullActionName($delimiter = '_') } /** + * Sleep + * * @return array */ public function __sleep() @@ -435,7 +419,7 @@ public function __sleep() } /** - * {@inheritdoc} + * @inheritdoc */ public function isSafeMethod() { diff --git a/lib/internal/Magento/Framework/App/Request/HttpMethodMap.php b/lib/internal/Magento/Framework/App/Request/HttpMethodMap.php new file mode 100644 index 0000000000000..4e7216954b0d4 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Request/HttpMethodMap.php @@ -0,0 +1,68 @@ +map = $this->processMap($map); + } + + /** + * Filter given map. + * + * @param array $map + * @throws \InvalidArgumentException + * + * @return string[] + */ + private function processMap(array $map): array + { + $filtered = []; + foreach ($map as $method => $interface) { + $interface = trim(preg_replace('/^\\\+/', '', $interface)); + if (!(interface_exists($interface) || class_exists($interface))) { + throw new \InvalidArgumentException( + "Interface '$interface' does not exist" + ); + } + if (!$method) { + throw new \InvalidArgumentException('Invalid method given'); + } + + $filtered[$method] = $interface; + } + + return $filtered; + } + + /** + * Where keys are methods' names and values are interfaces' names. + * + * @return string[] + * + * @see \Zend\Http\Request Has list of methods as METHOD_* constants. + */ + public function getMap(): array + { + return $this->map; + } +} diff --git a/lib/internal/Magento/Framework/App/Request/HttpMethodValidator.php b/lib/internal/Magento/Framework/App/Request/HttpMethodValidator.php new file mode 100644 index 0000000000000..d3eb514caad1e --- /dev/null +++ b/lib/internal/Magento/Framework/App/Request/HttpMethodValidator.php @@ -0,0 +1,96 @@ +map = $map; + $this->log = $logger; + } + + /** + * Create exception when invalid HTTP method used. + * + * @param Http $request + * @param ActionInterface $action + * @throws InvalidRequestException + * + * @return void + */ + private function throwException( + Http $request, + ActionInterface $action + ): void { + $uri = $request->getRequestUri(); + $method = $request->getMethod(); + if ($action instanceof InterceptorInterface) { + $actionClass = get_parent_class($action); + } else { + $actionClass = get_class($action); + } + $this->log->debug( + "URI '$uri'' cannot be accessed with $method method ($actionClass)" + ); + + throw new InvalidRequestException( + new NotFoundException(new Phrase('Page not found.')) + ); + } + + /** + * @inheritDoc + */ + public function validate( + RequestInterface $request, + ActionInterface $action + ): void { + if ($request instanceof Http) { + $method = $request->getMethod(); + $map = $this->map->getMap(); + //If we don't have an interface for the HTTP method or + //the action has HTTP method limitations and doesn't allow the + //received one then the request is invalid. + if (!array_key_exists($method, $map) + || (array_intersect($map, class_implements($action, true)) + && !$action instanceof $map[$method] + ) + ) { + $this->throwException($request, $action); + } + } + } +} diff --git a/lib/internal/Magento/Framework/App/Request/InvalidRequestException.php b/lib/internal/Magento/Framework/App/Request/InvalidRequestException.php index 3d408b0050686..f15ce494e9bb4 100644 --- a/lib/internal/Magento/Framework/App/Request/InvalidRequestException.php +++ b/lib/internal/Magento/Framework/App/Request/InvalidRequestException.php @@ -10,6 +10,7 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Exception\RuntimeException; use Magento\Framework\Phrase; @@ -29,8 +30,9 @@ class InvalidRequestException extends RuntimeException private $messages; /** - * @param ResponseInterface|ResultInterface $replaceResult Use this result - * instead of calling action instance. + * @param ResponseInterface|ResultInterface|NotFoundException $replaceResult + * Use this result instead of calling an action instance, + * if NotFoundException is given the the default 404 mechanism will be triggered. * @param Phrase[]|null $messages Messages to show to client * as error messages. */ @@ -43,7 +45,7 @@ public function __construct($replaceResult, ?array $messages = null) } /** - * @return ResponseInterface|ResultInterface + * @return ResponseInterface|ResultInterface|NotFoundException */ public function getReplaceResult() { diff --git a/lib/internal/Magento/Framework/App/Request/PathInfo.php b/lib/internal/Magento/Framework/App/Request/PathInfo.php new file mode 100644 index 0000000000000..76a12d6aefe98 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Request/PathInfo.php @@ -0,0 +1,80 @@ +removeRepeatedSlashes($requestUri); + $parsedRequestUri = explode('?', $requestUri, 2); + $pathInfo = (string)substr(current($parsedRequestUri), (int)strlen($baseUrl)); + + if ($this->isNoRouteUri($baseUrl, $pathInfo)) { + $pathInfo = \Magento\Framework\App\Router\Base::NO_ROUTE; + } + return $pathInfo; + } + + /** + * Get query string using from the request URI + * + * @param string $requestUri + * @return string + */ + public function getQueryString(string $requestUri) : string + { + $requestUri = $this->removeRepeatedSlashes($requestUri); + $parsedRequestUri = explode('?', $requestUri, 2); + $queryString = !isset($parsedRequestUri[1]) ? '' : '?' . $parsedRequestUri[1]; + return $queryString; + } + + /** + * Remove repeated slashes from the start of the path. + * + * @param string $pathInfo + * @return string + */ + private function removeRepeatedSlashes($pathInfo) : string + { + $firstChar = (string)substr($pathInfo, 0, 1); + if ($firstChar == '/') { + $pathInfo = '/' . ltrim($pathInfo, '/'); + } + + return $pathInfo; + } + + /** + * Check is URI should be marked as no route, helps route to 404 URI like `index.phpadmin`. + * + * @param string $baseUrl + * @param string $pathInfo + * @return bool + */ + private function isNoRouteUri($baseUrl, $pathInfo) : bool + { + $firstChar = (string)substr($pathInfo, 0, 1); + return $baseUrl !== '' && !in_array($firstChar, ['/', '']); + } +} diff --git a/lib/internal/Magento/Framework/App/Router/Base.php b/lib/internal/Magento/Framework/App/Router/Base.php index ed9def8e1cf55..f810adcfd3491 100644 --- a/lib/internal/Magento/Framework/App/Router/Base.php +++ b/lib/internal/Magento/Framework/App/Router/Base.php @@ -8,11 +8,18 @@ namespace Magento\Framework\App\Router; /** + * Base router implementation. + * * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Base implements \Magento\Framework\App\RouterInterface { + /** + * No route constant used for request + */ + const NO_ROUTE = 'noroute'; + /** * @var \Magento\Framework\App\ActionFactory */ @@ -303,7 +310,7 @@ protected function matchAction(\Magento\Framework\App\RequestInterface $request, if ($actionInstance === null) { return null; } - $action = 'noroute'; + $action = self::NO_ROUTE; } // set values only after all the checks are done @@ -333,6 +340,7 @@ public function getActionClassName($module, $actionPath) /** * Check that request uses https protocol if it should. + * * Function redirects user to correct URL if needed. * * @param \Magento\Framework\App\RequestInterface $request diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpMethodMapTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpMethodMapTest.php new file mode 100644 index 0000000000000..6215da3ae901d --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpMethodMapTest.php @@ -0,0 +1,49 @@ + '\\Throwable', 'method2' => 'DateTime'] + ); + $this->assertEquals( + ['method1' => \Throwable::class, 'method2' => \DateTime::class], + $map->getMap() + ); + } + + /** + * Test validation of interface names. + * + * @expectedException \InvalidArgumentException + */ + public function testExisting() + { + new HttpMethodMap(['method1' => 'NonExistingClass']); + } + + /** + * Test validation of method names. + * + * @expectedException \InvalidArgumentException + */ + public function testMethod() + { + new HttpMethodMap([\Throwable::class]); + } +} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php index 62445d4244fb7..535e74e9a3bdb 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php @@ -10,32 +10,41 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Request\Http; +/** + * @SuppressWarnings(PHPMD.TooManyMethods) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ class HttpTest extends \PHPUnit\Framework\TestCase { /** * @var \Magento\Framework\App\Request\Http */ - protected $_model; + private $model; /** * @var \Magento\Framework\App\Route\ConfigInterface\Proxy | \PHPUnit_Framework_MockObject_MockObject */ - protected $_routerListMock; + private $routerListMock; /** * @var \Magento\Framework\App\Request\PathInfoProcessorInterface | \PHPUnit_Framework_MockObject_MockObject */ - protected $_infoProcessorMock; + private $infoProcessorMock; + + /** + * @var \Magento\Framework\App\Request\PathInfo + */ + private $pathInfo; /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager | \PHPUnit_Framework_MockObject_MockObject */ - protected $objectManagerMock; + private $objectManagerMock; /** * @var \Magento\Framework\Stdlib\StringUtils | \PHPUnit_Framework_MockObject_MockObject */ - protected $converterMock; + private $converterMock; /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager @@ -49,12 +58,12 @@ class HttpTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $this->_routerListMock = $this->createPartialMock( + $this->routerListMock = $this->createPartialMock( \Magento\Framework\App\Route\ConfigInterface\Proxy::class, ['getRouteFrontName', 'getRouteByFrontName', '__wakeup'] ); - $this->_infoProcessorMock = $this->createMock(\Magento\Framework\App\Request\PathInfoProcessorInterface::class); - $this->_infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1)); + $this->infoProcessorMock = $this->createMock(\Magento\Framework\App\Request\PathInfoProcessorInterface::class); + $this->infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1)); $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class); $this->converterMock = $this->getMockBuilder(\Magento\Framework\Stdlib\StringUtils::class) ->disableOriginalConstructor() @@ -66,6 +75,7 @@ protected function setUp() $this->serverArray = $_SERVER; $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->pathInfo = $this->objectManager->getObject(\Magento\Framework\App\Request\PathInfo::class); } public function tearDown() @@ -81,8 +91,9 @@ private function getModel($uri = null, $appConfigMock = true) $model = $this->objectManager->getObject( \Magento\Framework\App\Request\Http::class, [ - 'routeConfig' => $this->_routerListMock, - 'pathInfoProcessor' => $this->_infoProcessorMock, + 'routeConfig' => $this->routerListMock, + 'pathInfoProcessor' => $this->infoProcessorMock, + 'pathInfoService' => $this->pathInfo, 'objectManager' => $this->objectManagerMock, 'converter' => $this->converterMock, 'uri' => $uri, @@ -100,91 +111,91 @@ private function getModel($uri = null, $appConfigMock = true) public function testGetOriginalPathInfoWithTestUri() { $uri = 'http://test.com/value?key=value'; - $this->_model = $this->getModel($uri); - $this->assertEquals('/value', $this->_model->getOriginalPathInfo()); + $this->model = $this->getModel($uri); + $this->assertEquals('/value', $this->model->getOriginalPathInfo()); } public function testGetOriginalPathInfoWithEmptyUri() { - $this->_model = $this->getModel(); - $this->assertEmpty($this->_model->getOriginalPathInfo()); + $this->model = $this->getModel(); + $this->assertEmpty($this->model->getOriginalPathInfo()); } public function testGetBasePathWithPath() { - $this->_model = $this->getModel(); - $this->_model->setBasePath('http:\/test.com\one/two'); - $this->assertEquals('http://test.com/one/two', $this->_model->getBasePath()); + $this->model = $this->getModel(); + $this->model->setBasePath('http:\/test.com\one/two'); + $this->assertEquals('http://test.com/one/two', $this->model->getBasePath()); } public function testGetBasePathWithoutPath() { - $this->_model = $this->getModel(); - $this->_model->setBasePath(null); - $this->assertEquals('/', $this->_model->getBasePath()); + $this->model = $this->getModel(); + $this->model->setBasePath(null); + $this->assertEquals('/', $this->model->getBasePath()); } public function testSetRouteNameWithRouter() { $router = $this->createMock(\Magento\Framework\App\Route\ConfigInterface::class); - $this->_routerListMock->expects($this->any())->method('getRouteFrontName')->will($this->returnValue($router)); - $this->_model = $this->getModel(); - $this->_model->setRouteName('RouterName'); - $this->assertEquals('RouterName', $this->_model->getRouteName()); + $this->routerListMock->expects($this->any())->method('getRouteFrontName')->will($this->returnValue($router)); + $this->model = $this->getModel(); + $this->model->setRouteName('RouterName'); + $this->assertEquals('RouterName', $this->model->getRouteName()); } public function testSetRouteNameWithNullRouterValue() { - $this->_model = $this->getModel(); - $this->_routerListMock->expects($this->once())->method('getRouteFrontName')->will($this->returnValue(null)); - $this->_model->setRouteName('RouterName'); + $this->model = $this->getModel(); + $this->routerListMock->expects($this->once())->method('getRouteFrontName')->will($this->returnValue(null)); + $this->model->setRouteName('RouterName'); } public function testGetFrontName() { $uri = 'http://test.com/one/two'; - $this->_model = $this->getModel($uri); - $this->assertEquals('one', $this->_model->getFrontName()); + $this->model = $this->getModel($uri); + $this->assertEquals('one', $this->model->getFrontName()); } public function testGetRouteNameWithNullValueRouteName() { - $this->_model = $this->getModel(); - $this->_model->setRouteName('RouteName'); - $this->assertEquals('RouteName', $this->_model->getRouteName()); + $this->model = $this->getModel(); + $this->model->setRouteName('RouteName'); + $this->assertEquals('RouteName', $this->model->getRouteName()); } public function testGetRouteName() { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); $expected = 'RouteName'; - $this->_model->setRouteName($expected); - $this->assertEquals($expected, $this->_model->getRouteName()); + $this->model->setRouteName($expected); + $this->assertEquals($expected, $this->model->getRouteName()); } public function testGetFullActionName() { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); /* empty request */ - $this->assertEquals('__', $this->_model->getFullActionName()); - $this->_model->setRouteName('test')->setControllerName('controller')->setActionName('action'); - $this->assertEquals('test/controller/action', $this->_model->getFullActionName('/')); + $this->assertEquals('__', $this->model->getFullActionName()); + $this->model->setRouteName('test')->setControllerName('controller')->setActionName('action'); + $this->assertEquals('test/controller/action', $this->model->getFullActionName('/')); } public function testInitForward() { - $expected = $this->_initForward(); - $this->assertEquals($expected, $this->_model->getBeforeForwardInfo()); + $expected = $this->initForward(); + $this->assertEquals($expected, $this->model->getBeforeForwardInfo()); } public function testGetBeforeForwardInfo() { - $beforeForwardInfo = $this->_initForward(); - $this->assertNull($this->_model->getBeforeForwardInfo('not_existing_forward_info_key')); + $beforeForwardInfo = $this->initForward(); + $this->assertNull($this->model->getBeforeForwardInfo('not_existing_forward_info_key')); foreach (array_keys($beforeForwardInfo) as $key) { - $this->assertEquals($beforeForwardInfo[$key], $this->_model->getBeforeForwardInfo($key)); + $this->assertEquals($beforeForwardInfo[$key], $this->model->getBeforeForwardInfo($key)); } - $this->assertEquals($beforeForwardInfo, $this->_model->getBeforeForwardInfo()); + $this->assertEquals($beforeForwardInfo, $this->model->getBeforeForwardInfo()); } /** @@ -192,9 +203,9 @@ public function testGetBeforeForwardInfo() * * @return array Contents of $_beforeForwardInfo */ - protected function _initForward() + private function initForward() { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); $beforeForwardInfo = [ 'params' => ['one' => '111', 'two' => '222'], 'action_name' => 'ActionName', @@ -202,36 +213,36 @@ protected function _initForward() 'module_name' => 'ModuleName', 'route_name' => 'RouteName' ]; - $this->_model->setParams($beforeForwardInfo['params']); - $this->_model->setActionName($beforeForwardInfo['action_name']); - $this->_model->setControllerName($beforeForwardInfo['controller_name']); - $this->_model->setModuleName($beforeForwardInfo['module_name']); - $this->_model->setRouteName($beforeForwardInfo['route_name']); - $this->_model->initForward(); + $this->model->setParams($beforeForwardInfo['params']); + $this->model->setActionName($beforeForwardInfo['action_name']); + $this->model->setControllerName($beforeForwardInfo['controller_name']); + $this->model->setModuleName($beforeForwardInfo['module_name']); + $this->model->setRouteName($beforeForwardInfo['route_name']); + $this->model->initForward(); return $beforeForwardInfo; } public function testIsAjax() { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); - $this->assertFalse($this->_model->isAjax()); + $this->assertFalse($this->model->isAjax()); - $this->_model->clearParams(); - $this->_model->setParam('ajax', 1); - $this->assertTrue($this->_model->isAjax()); + $this->model->clearParams(); + $this->model->setParam('ajax', 1); + $this->assertTrue($this->model->isAjax()); - $this->_model->clearParams(); - $this->_model->setParam('isAjax', 1); - $this->assertTrue($this->_model->isAjax()); + $this->model->clearParams(); + $this->model->setParam('isAjax', 1); + $this->assertTrue($this->model->isAjax()); - $this->_model->clearParams(); - $this->_model->getHeaders()->addHeaderLine('X-Requested-With', 'XMLHttpRequest'); - $this->assertTrue($this->_model->isAjax()); + $this->model->clearParams(); + $this->model->getHeaders()->addHeaderLine('X-Requested-With', 'XMLHttpRequest'); + $this->assertTrue($this->model->isAjax()); - $this->_model->getHeaders()->clearHeaders(); - $this->_model->getHeaders()->addHeaderLine('X-Requested-With', 'NotXMLHttpRequest'); - $this->assertFalse($this->_model->isAjax()); + $this->model->getHeaders()->clearHeaders(); + $this->model->getHeaders()->addHeaderLine('X-Requested-With', 'NotXMLHttpRequest'); + $this->assertFalse($this->model->isAjax()); } /** @@ -243,8 +254,8 @@ public function testGetDistroBaseUrl($serverVariables, $expectedResult) { $originalServerValue = $_SERVER; $_SERVER = $serverVariables; - $this->_model = $this->getModel(); - $this->assertEquals($expectedResult, $this->_model->getDistroBaseUrl()); + $this->model = $this->getModel(); + $this->assertEquals($expectedResult, $this->model->getDistroBaseUrl()); $_SERVER = $originalServerValue; } @@ -338,7 +349,7 @@ public function serverVariablesProvider() */ public function testIsSecure($isSecure, $serverHttps, $headerOffloadKey, $headerOffloadValue, $configCall) { - $this->_model = $this->getModel(null, false); + $this->model = $this->getModel(null, false); $configOffloadHeader = 'Header-From-Proxy'; $configMock = $this->getMockBuilder(\Magento\Framework\App\Config::class) ->disableOriginalConstructor() @@ -351,13 +362,13 @@ public function testIsSecure($isSecure, $serverHttps, $headerOffloadKey, $header ScopeConfigInterface::SCOPE_TYPE_DEFAULT )->willReturn($configOffloadHeader); - $this->objectManager->setBackwardCompatibleProperty($this->_model, 'appConfig', $configMock); - $this->objectManager->setBackwardCompatibleProperty($this->_model, 'sslOffloadHeader', null); + $this->objectManager->setBackwardCompatibleProperty($this->model, 'appConfig', $configMock); + $this->objectManager->setBackwardCompatibleProperty($this->model, 'sslOffloadHeader', null); - $this->_model->getServer()->set($headerOffloadKey, $headerOffloadValue); - $this->_model->getServer()->set('HTTPS', $serverHttps); + $this->model->getServer()->set($headerOffloadKey, $headerOffloadValue); + $this->model->getServer()->set('HTTPS', $serverHttps); - $this->assertSame($isSecure, $this->_model->isSecure()); + $this->assertSame($isSecure, $this->model->isSecure()); } /** @@ -367,9 +378,9 @@ public function testIsSecure($isSecure, $serverHttps, $headerOffloadKey, $header */ public function testIsSafeMethodTrue($httpMethod) { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); $_SERVER['REQUEST_METHOD'] = $httpMethod; - $this->assertEquals(true, $this->_model->isSafeMethod()); + $this->assertEquals(true, $this->model->isSafeMethod()); } /** @@ -379,9 +390,9 @@ public function testIsSafeMethodTrue($httpMethod) */ public function testIsSafeMethodFalse($httpMethod) { - $this->_model = $this->getModel(); + $this->model = $this->getModel(); $_SERVER['REQUEST_METHOD'] = $httpMethod; - $this->assertEquals(false, $this->_model->isSafeMethod()); + $this->assertEquals(false, $this->model->isSafeMethod()); } /** @@ -449,12 +460,25 @@ public function isSecureDataProvider() * @param string $basePath$ * @param string $expected */ - public function testSetPathInfo($requestUri, $basePath, $expected) + public function testGetPathInfo($requestUri, $basePath, $expected) + { + $this->model = $this->getModel($requestUri); + $this->model->setBaseUrl($basePath); + $this->assertEquals($expected, $this->model->getPathInfo()); + $this->assertEquals($expected, $this->model->getOriginalPathInfo()); + } + + public function testSetPathInfo() { - $this->_model = $this->getModel($requestUri); - $this->_model->setBaseUrl($basePath); - $this->_model->setPathInfo(); - $this->assertEquals($expected, $this->_model->getPathInfo()); + $requestUri = 'http://svr.com//module/route/mypage/myproduct?param1=1'; + $basePath = '/module/route/'; + $this->model = $this->getModel($requestUri); + $this->model->setBaseUrl($basePath); + $expected = '/mypage/myproduct'; + $this->assertEquals($expected, $this->model->getOriginalPathInfo()); + $this->model->setPathInfo('http://svr.com/something/route?param1=1'); + $this->assertEquals('http://svr.com/something/route?param1=1', $this->model->getPathInfo()); + $this->assertEquals($expected, $this->model->getOriginalPathInfo()); } /** diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index 39a0479f7540e..c438edf3aa9ac 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -50,6 +50,8 @@ public function __construct( } /** + * Returns buttons translation + * * @return array */ protected function getButtonTranslations() @@ -64,6 +66,8 @@ protected function getButtonTranslations() } /** + * Returns JS config + * * @return bool|string * @throws \InvalidArgumentException */ @@ -80,8 +84,9 @@ protected function getJsonConfig() /** * Fetch config options from plugin. If $key is passed, return only that option key's value + * * @param string $pluginName - * @param null $key + * @param string|null $key * @return mixed all options or single option if $key is passed; null if nonexistent */ public function getPluginConfigOptions($pluginName, $key = null) @@ -101,13 +106,15 @@ public function getPluginConfigOptions($pluginName, $key = null) $pluginOptions = $plugins[$pluginArrIndex]['options']; if ($key !== null) { - return isset($pluginOptions[$key]) ? $pluginOptions[$key] : null; + return $pluginOptions[$key] ?? null; } else { return $pluginOptions; } } /** + * Returns element html + * * @return string * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -200,6 +207,8 @@ public function getElementHtml() } /** + * Returns theme + * * @return mixed */ public function getTheme() @@ -343,6 +352,8 @@ protected function _checkPluginButtonOptions($pluginOptions) } /** + * Convert options + * * Convert options by replacing template constructions ( like {{var_name}} ) * with data from this element object * @@ -389,6 +400,7 @@ protected function _getButtonHtml($data) /** * Wraps Editor HTML into div if 'use_container' config option is set to true + * * If 'no_display' config option is set to true, the div will be invisible * * @param string $html HTML code to wrap @@ -463,6 +475,8 @@ public function isHidden() } /** + * Is Toggle Button Visible + * * @return bool */ protected function isToggleButtonVisible() diff --git a/lib/internal/Magento/Framework/Filter/Template/Tokenizer/Variable.php b/lib/internal/Magento/Framework/Filter/Template/Tokenizer/Variable.php index 67c2d17abe208..574ef9faf74a5 100644 --- a/lib/internal/Magento/Framework/Filter/Template/Tokenizer/Variable.php +++ b/lib/internal/Magento/Framework/Filter/Template/Tokenizer/Variable.php @@ -313,6 +313,6 @@ public function getNumber() if (!$this->isNumeric()) { $this->prev(); } - return floatval($value); + return (float)$value; } } diff --git a/lib/internal/Magento/Framework/GraphQl/Schema/Type/Entity/DefaultMapper.php b/lib/internal/Magento/Framework/GraphQl/Schema/Type/Entity/DefaultMapper.php index 7e3f2ac6db638..cacc1f9e28c02 100644 --- a/lib/internal/Magento/Framework/GraphQl/Schema/Type/Entity/DefaultMapper.php +++ b/lib/internal/Magento/Framework/GraphQl/Schema/Type/Entity/DefaultMapper.php @@ -26,10 +26,10 @@ public function __construct(array $map = []) } /** - * {@inheritDoc} + * @inheritdoc */ public function getMappedTypes(string $entityName) : array { - return isset($this->map[$entityName]) ? $this->map[$entityName] : []; + return $this->map[$entityName] ?? []; } } diff --git a/lib/internal/Magento/Framework/GraphQl/Schema/Type/Enum/DefaultDataMapper.php b/lib/internal/Magento/Framework/GraphQl/Schema/Type/Enum/DefaultDataMapper.php index f7b39ba64207b..f560fcb0de774 100644 --- a/lib/internal/Magento/Framework/GraphQl/Schema/Type/Enum/DefaultDataMapper.php +++ b/lib/internal/Magento/Framework/GraphQl/Schema/Type/Enum/DefaultDataMapper.php @@ -26,10 +26,10 @@ public function __construct(array $map) } /** - * {@inheritDoc} + * @inheritdoc */ public function getMappedEnums(string $enumName) : array { - return isset($this->map[$enumName]) ? $this->map[$enumName] : []; + return $this->map[$enumName] ?? []; } } diff --git a/lib/internal/Magento/Framework/MessageQueue/Config.php b/lib/internal/Magento/Framework/MessageQueue/Config.php index e29b5d06bee6c..9a925e1417c12 100644 --- a/lib/internal/Magento/Framework/MessageQueue/Config.php +++ b/lib/internal/Magento/Framework/MessageQueue/Config.php @@ -30,18 +30,16 @@ public function __construct(Config\Data $queueConfigData) } /** - * {@inheritdoc} + * @inheritdoc */ public function getExchangeByTopic($topicName) { $publisherConfig = $this->getPublisherConfigByTopic($topicName); - return isset($publisherConfig[ConfigInterface::PUBLISHER_EXCHANGE]) - ? $publisherConfig[ConfigInterface::PUBLISHER_EXCHANGE] - : null; + return $publisherConfig[ConfigInterface::PUBLISHER_EXCHANGE] ?? null; } /** - * {@inheritdoc} + * @inheritdoc */ public function getQueuesByTopic($topic) { @@ -67,7 +65,7 @@ public function getQueuesByTopic($topic) } /** - * {@inheritdoc} + * @inheritdoc */ public function getConnectionByTopic($topic) { @@ -76,13 +74,11 @@ public function getConnectionByTopic($topic) } catch (\Magento\Framework\Exception\LocalizedException $e) { return null; } - return isset($publisherConfig[ConfigInterface::PUBLISHER_CONNECTION]) - ? $publisherConfig[ConfigInterface::PUBLISHER_CONNECTION] - : null; + return $publisherConfig[ConfigInterface::PUBLISHER_CONNECTION] ?? null; } /** - * {@inheritdoc} + * @inheritdoc */ public function getConnectionByConsumer($consumer) { @@ -98,7 +94,7 @@ public function getConnectionByConsumer($consumer) } /** - * {@inheritdoc} + * @inheritdoc */ public function getMessageSchemaType($topic) { @@ -109,7 +105,7 @@ public function getMessageSchemaType($topic) } /** - * {@inheritdoc} + * @inheritdoc */ public function getConsumerNames() { @@ -118,7 +114,7 @@ public function getConsumerNames() } /** - * {@inheritdoc} + * @inheritdoc */ public function getConsumer($name) { @@ -127,7 +123,7 @@ public function getConsumer($name) } /** - * {@inheritdoc} + * @inheritdoc */ public function getBinds() { @@ -135,7 +131,7 @@ public function getBinds() } /** - * {@inheritdoc} + * @inheritdoc */ public function getPublishers() { @@ -143,7 +139,7 @@ public function getPublishers() } /** - * {@inheritdoc} + * @inheritdoc */ public function getConsumers() { @@ -151,7 +147,7 @@ public function getConsumers() } /** - * {@inheritdoc} + * @inheritdoc */ public function getTopic($name) { @@ -159,7 +155,7 @@ public function getTopic($name) } /** - * {@inheritdoc} + * @inheritdoc */ public function getPublisher($name) { @@ -167,7 +163,7 @@ public function getPublisher($name) } /** - * {@inheritdoc} + * @inheritdoc */ public function getResponseQueueName($topicName) { diff --git a/lib/internal/Magento/Framework/MessageQueue/Consumer/Config/Env/Reader.php b/lib/internal/Magento/Framework/MessageQueue/Consumer/Config/Env/Reader.php index aa318ba5f19cf..a75aa1ea8ead2 100644 --- a/lib/internal/Magento/Framework/MessageQueue/Consumer/Config/Env/Reader.php +++ b/lib/internal/Magento/Framework/MessageQueue/Consumer/Config/Env/Reader.php @@ -33,8 +33,6 @@ public function __construct(\Magento\Framework\MessageQueue\Config\Reader\Env $e public function read($scope = null) { $configData = $this->envConfig->read($scope); - return isset($configData[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_CONSUMERS]) - ? $configData[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_CONSUMERS] - : []; + return $configData[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_CONSUMERS] ?? []; } } diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Real.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Real.php index cdb740ea0a92d..e0728b9a34fee 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Real.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Real.php @@ -39,7 +39,7 @@ class Real implements FactoryInterface * Constructor. * * @param ObjectManagerInterface $objectManager - * @param string $className + * @param string $className */ public function __construct( ObjectManagerInterface $objectManager, @@ -50,7 +50,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function create(array $data) { @@ -63,7 +63,7 @@ public function create(array $data) } if (isset($data['default'])) { - $data['default'] = floatval($data['default']); + $data['default'] = (float)$data['default']; } return $this->objectManager->create($this->className, $data); diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Schema.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Schema.php index 3e68b985283cf..fbbe188d127ae 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Schema.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Schema.php @@ -63,14 +63,15 @@ public function addTable(Table $table) /** * Retrieve table by it name. + * * Return false if table is not present in schema. * - * @param $name + * @param string $name * @return bool|Table */ public function getTableByName($name) { $name = $this->resourceConnection->getTableName($name); - return isset($this->tables[$name]) ? $this->tables[$name] : false; + return $this->tables[$name] ?? false; } } diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Table.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Table.php index 4f020b1a0320f..b4e1e978ea674 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Table.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Table.php @@ -87,11 +87,11 @@ class Table extends GenericElement implements * @param string $engine * @param string $charset * @param string $collation + * @param string $onCreate * @param string|null $comment * @param array $columns * @param array $indexes * @param array $constraints - * @param string $onCreate * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -123,6 +123,7 @@ public function __construct( /** * Return different table constraints. + * * It can be constraint like unique key or reference to another table, etc * * @return Constraint[] @@ -133,12 +134,14 @@ public function getConstraints() } /** + * Returns constraint by name + * * @param string $name * @return Constraint | bool */ public function getConstraintByName($name) { - return isset($this->constraints[$name]) ? $this->constraints[$name] : false; + return $this->constraints[$name] ?? false; } /** @@ -160,6 +163,8 @@ public function getReferenceConstraints() } /** + * Returns primary constraint + * * As primary constraint always have one name * and can be only one for table * it name is allocated into it constraint @@ -168,9 +173,7 @@ public function getReferenceConstraints() */ public function getPrimaryConstraint() { - return isset($this->constraints[Internal::PRIMARY_NAME]) ? - $this->constraints[Internal::PRIMARY_NAME] : - false; + return $this->constraints[Internal::PRIMARY_NAME] ?? false; } /** @@ -191,16 +194,19 @@ public function getInternalConstraints() : array } /** + * Returns index by name + * * @param string $name * @return Index | bool */ public function getIndexByName($name) { - return isset($this->indexes[$name]) ? $this->indexes[$name] : false; + return $this->indexes[$name] ?? false; } /** * Return all columns. + * * Note, table always must have columns * * @return Column[] @@ -231,6 +237,8 @@ public function getResource() } /** + * Add constraints + * * This is workaround, as any DTO object couldnt be changed after instantiation. * However there is case, when we have 2 tables with constraints in different tables, * that depends to each other table. So we need to setup DTO first and only then pass @@ -280,6 +288,7 @@ public function getColumnByName($nameOrId) /** * Retrieve elements by specific type + * * Allowed types: columns, constraints, indexes... * * @param string $type @@ -295,6 +304,8 @@ public function getElementsByType($type) } /** + * Add indexes + * * This is workaround, as any DTO object couldnt be changed after instantiation. * However there is case, when we depends on column definition we need modify our indexes * @@ -314,6 +325,8 @@ public function getElementType() } /** + * Returns engine name + * * @return string */ public function getEngine(): string @@ -356,6 +369,8 @@ public function getCollation() : string } /** + * Returns name without prefix + * * @return string */ public function getNameWithoutPrefix(): string @@ -364,6 +379,8 @@ public function getNameWithoutPrefix(): string } /** + * Returns comment + * * @return null|string */ public function getComment() diff --git a/lib/web/images/logo.svg b/lib/web/images/logo.svg index 013d6e7c5a107..e4f627809b627 100644 --- a/lib/web/images/logo.svg +++ b/lib/web/images/logo.svg @@ -1 +1 @@ - \ No newline at end of file +Magento-an-Adobe-Company-logo-horizontal diff --git a/lib/web/images/magento-logo.svg b/lib/web/images/magento-logo.svg index 0d5cc0e6233d6..e4f627809b627 100644 --- a/lib/web/images/magento-logo.svg +++ b/lib/web/images/magento-logo.svg @@ -1 +1 @@ - \ No newline at end of file +Magento-an-Adobe-Company-logo-horizontal diff --git a/lib/web/mage/adminhtml/tools.js b/lib/web/mage/adminhtml/tools.js index ed4bab7102ae5..27f6efcfc5876 100644 --- a/lib/web/mage/adminhtml/tools.js +++ b/lib/web/mage/adminhtml/tools.js @@ -348,7 +348,7 @@ var Fieldset = { }, saveState: function (url, parameters) { new Ajax.Request(url, { - method: 'get', + method: 'post', parameters: Object.toQueryString(parameters), loaderArea: false }); diff --git a/pub/errors/default/images/logo.gif b/pub/errors/default/images/logo.gif index f1f7fcaf4f020..0cca183e08da2 100644 Binary files a/pub/errors/default/images/logo.gif and b/pub/errors/default/images/logo.gif differ diff --git a/setup/performance-toolkit/benchmark.jmx b/setup/performance-toolkit/benchmark.jmx index 7e9ed5377f154..3b74af8a111d6 100644 --- a/setup/performance-toolkit/benchmark.jmx +++ b/setup/performance-toolkit/benchmark.jmx @@ -4940,7 +4940,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -5306,7 +5306,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -6821,7 +6821,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -7187,7 +7187,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -8139,7 +8139,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -8505,7 +8505,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -9963,7 +9963,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -10329,7 +10329,7 @@ vars.put("totalProductsAdded", String.valueOf(productsAdded)); - You added ${product_name} to your shopping cart. + You added ${product_name} to your shopping cart. Assertion.response_data false @@ -32071,7 +32071,15 @@ vars.put("new_parent_category_id", props.get("admin_category_ids_list").get(cate - + + + true + ${admin_form_key} + = + true + form_key + + @@ -32080,7 +32088,7 @@ vars.put("new_parent_category_id", props.get("admin_category_ids_list").get(cate ${request_protocol} ${base_path}${admin_path}/catalog/category/delete/id/${admin_category_id}/ - GET + POST true false true diff --git a/setup/pub/images/magento-logo.svg b/setup/pub/images/magento-logo.svg index 6dcc79d33b294..e4f627809b627 100644 --- a/setup/pub/images/magento-logo.svg +++ b/setup/pub/images/magento-logo.svg @@ -1,18 +1 @@ - - - - - - - - - - - - - - - - - - +Magento-an-Adobe-Company-logo-horizontal