From b2b8acecde8f875ff1a7e52b47c0797627b94ca3 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Wed, 2 Nov 2016 11:34:12 +0200 Subject: [PATCH 01/10] MAGETWO-59564: [Github] MAGE_MODE is changed back to default if database config is changed with setup:config:set - for 2.0.x --- .../Magento/Setup/Model/ConfigGenerator.php | 5 ++++- .../Test/Unit/Model/ConfigGeneratorTest.php | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index c2a209234e9df..5e5f42c74a145 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -237,7 +237,10 @@ public function createXFrameConfig() public function createModeConfig() { $configData = new ConfigData(ConfigFilePool::APP_ENV); - $configData->set(State::PARAM_MODE, State::MODE_DEFAULT); + if ($this->deploymentConfig->get(State::PARAM_MODE) === null) { + $configData->set(State::PARAM_MODE, State::MODE_DEFAULT); + } + return $configData; } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 985763b27ebdd..a593439681f98 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -8,6 +8,7 @@ use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\App\State; class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase { @@ -58,4 +59,24 @@ public function testCreateCacheHostsConfig() $configData = $this->model->createCacheHostsConfig($data); $this->assertEquals($expectedData, $configData->getData()[ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS]); } + + public function testCreateModeConfig() + { + $this->deploymentConfigMock->expects($this->once()) + ->method('get') + ->with(State::PARAM_MODE) + ->willReturn(null); + $configData = $this->model->createModeConfig(); + $this->assertSame(State::MODE_DEFAULT, $configData->getData()[State::PARAM_MODE]); + } + + public function testCreateModeConfigIfAlreadySet() + { + $this->deploymentConfigMock->expects($this->once()) + ->method('get') + ->with(State::PARAM_MODE) + ->willReturn(State::MODE_PRODUCTION); + $configData = $this->model->createModeConfig(); + $this->assertSame([], $configData->getData()); + } } From e99019e1e634714668dcc2ad99c1130593285610 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Thu, 3 Nov 2016 11:12:00 +0200 Subject: [PATCH 02/10] MAGETWO-58892: [GitHub] IndexerHandlerFactory: Indexer Object cast to String - 2.0 --- .../Model/Indexer/IndexerHandlerFactory.php | 6 +- .../Indexer/IndexerHandlerFactoryTest.php | 173 ++++++++++++++++++ 2 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/IndexerHandlerFactoryTest.php diff --git a/app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php b/app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php index bb2df11c9083d..58be7fcb1bcb9 100644 --- a/app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php +++ b/app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php @@ -75,12 +75,14 @@ public function create(array $data = []) $indexer = $this->_objectManager->create($this->handlers[$currentHandler], $data); if (!$indexer instanceof IndexerInterface) { - throw new \InvalidArgumentException($indexer . ' doesn\'t implement \Magento\Framework\IndexerInterface'); + throw new \InvalidArgumentException( + $currentHandler . ' indexer handler doesn\'t implement ' . IndexerInterface::class + ); } if ($indexer && !$indexer->isAvailable()) { throw new \LogicException( - 'Indexer handler is not available: ' . $indexer + 'Indexer handler is not available: ' . $currentHandler ); } return $indexer; diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/IndexerHandlerFactoryTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/IndexerHandlerFactoryTest.php new file mode 100644 index 0000000000000..417eb63d08ab4 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/IndexerHandlerFactoryTest.php @@ -0,0 +1,173 @@ +objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->getMockForAbstractClass(); + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMockForAbstractClass(); + } + + public function testCreate() + { + $configPath = 'config_path'; + $currentHandler = 'current_handler'; + $currentHandlerClass = 'current_handler_class'; + $handlers = [ + $currentHandler => $currentHandlerClass, + ]; + $data = ['data']; + + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with($configPath, ScopeInterface::SCOPE_STORE) + ->willReturn($currentHandler); + + $indexerMock = $this->getMockBuilder(IndexerInterface::class) + ->getMockForAbstractClass(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with($currentHandlerClass, $data) + ->willReturn($indexerMock); + + $indexerMock->expects($this->once()) + ->method('isAvailable') + ->willReturn(true); + + $this->model = new IndexerHandlerFactory( + $this->objectManagerMock, + $this->scopeConfigMock, + $configPath, + $handlers + ); + + $this->assertEquals($indexerMock, $this->model->create($data)); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage There is no such indexer handler: current_handler + */ + public function testCreateWithoutHandlers() + { + $configPath = 'config_path'; + $currentHandler = 'current_handler'; + $handlers = []; + $data = ['data']; + + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with($configPath, ScopeInterface::SCOPE_STORE) + ->willReturn($currentHandler); + + $this->model = new IndexerHandlerFactory( + $this->objectManagerMock, + $this->scopeConfigMock, + $configPath, + $handlers + ); + + $this->model->create($data); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage current_handler indexer handler doesn't implement + */ + public function testCreateWithWrongHandler() + { + $configPath = 'config_path'; + $currentHandler = 'current_handler'; + $currentHandlerClass = 'current_handler_class'; + $handlers = [ + $currentHandler => $currentHandlerClass, + ]; + $data = ['data']; + + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with($configPath, ScopeInterface::SCOPE_STORE) + ->willReturn($currentHandler); + + $indexerMock = $this->getMockBuilder(\stdClass::class) + ->getMockForAbstractClass(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with($currentHandlerClass, $data) + ->willReturn($indexerMock); + + $this->model = new IndexerHandlerFactory( + $this->objectManagerMock, + $this->scopeConfigMock, + $configPath, + $handlers + ); + + $this->model->create($data); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Indexer handler is not available: current_handler + */ + public function testCreateWithoutAvailableHandler() + { + $configPath = 'config_path'; + $currentHandler = 'current_handler'; + $currentHandlerClass = 'current_handler_class'; + $handlers = [ + $currentHandler => $currentHandlerClass, + ]; + $data = ['data']; + + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with($configPath, ScopeInterface::SCOPE_STORE) + ->willReturn($currentHandler); + + $indexerMock = $this->getMockBuilder(IndexerInterface::class) + ->getMockForAbstractClass(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with($currentHandlerClass, $data) + ->willReturn($indexerMock); + + $indexerMock->expects($this->once()) + ->method('isAvailable') + ->willReturn(false); + + $this->model = new IndexerHandlerFactory( + $this->objectManagerMock, + $this->scopeConfigMock, + $configPath, + $handlers + ); + + $this->model->create($data); + } +} From a06ddf01d7fd6c352ea6664383fae493188d6b6d Mon Sep 17 00:00:00 2001 From: DianaRusin Date: Fri, 4 Nov 2016 11:52:33 -0400 Subject: [PATCH 03/10] MAGETWO-59172: Disable email communication set to yes: email did get sent --- .../Model/Mail/TransportInterfacePlugin.php | 51 +++++++++++++++++++ app/code/Magento/Email/Model/Template.php | 23 ++------- .../Email/Test/Unit/Model/TemplateTest.php | 19 +------ app/code/Magento/Email/etc/di.xml | 3 ++ .../Magento/Newsletter/Model/Template.php | 8 ++- .../Test/Unit/Model/TemplateTest.php | 51 +++++++++++++++++++ 6 files changed, 114 insertions(+), 41 deletions(-) create mode 100755 app/code/Magento/Email/Model/Mail/TransportInterfacePlugin.php diff --git a/app/code/Magento/Email/Model/Mail/TransportInterfacePlugin.php b/app/code/Magento/Email/Model/Mail/TransportInterfacePlugin.php new file mode 100755 index 0000000000000..02c1fee1b0745 --- /dev/null +++ b/app/code/Magento/Email/Model/Mail/TransportInterfacePlugin.php @@ -0,0 +1,51 @@ +scopeConfig = $scopeConfig; + } + + /** + * Omit email sending if disabled + * + * @param TransportInterface $subject + * @param \Closure $proceed + * @return void + * @throws MailException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundSendMessage( + TransportInterface $subject, + \Closure $proceed + ) { + if (!$this->scopeConfig->isSetFlag(self::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)) { + $proceed(); + } + } +} diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 6ab1539db4d88..0a66d4fb20763 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -5,26 +5,11 @@ */ namespace Magento\Email\Model; -use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; /** * Template model * - * Example: - * - * // Loading of template - * \Magento\Email\Model\TemplateFactory $templateFactory - * $templateFactory->create()->load($this->_scopeConfig->getValue( - * 'path_to_email_template_id_config', - * \Magento\Store\Model\ScopeInterface::SCOPE_STORE - * )); - * $variables = array( - * 'someObject' => $this->_coreResourceEmailTemplate - * 'someString' => 'Some string value' - * ); - * $emailTemplate->send('some@domain.com', 'Name Of User', $variables); - * * @method \Magento\Email\Model\ResourceModel\Template _getResource() * @method \Magento\Email\Model\ResourceModel\Template getResource() * @method string getTemplateCode() @@ -63,6 +48,8 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ /** * Config path to mail sending setting that shows if email communications are disabled + * @deprecated + * @see \Magento\Email\Model\Mail\TransportInterfacePlugin::XML_PATH_SYSTEM_SMTP_DISABLE */ const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable'; @@ -196,8 +183,7 @@ public function setId($value) */ public function isValidForSend() { - return !$this->scopeConfig->isSetFlag(Template::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE) - && $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject(); + return $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject(); } /** @@ -344,7 +330,8 @@ public function beforeSave() if ($this->_getResource()->checkCodeUsage($this)) { throw new \Magento\Framework\Exception\MailException(__('Duplicate Of Template Name')); } - return parent::beforeSave(); + parent::beforeSave(); + return $this; } /** diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index 3fe540beeac00..305a8ccd9a26b 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -5,7 +5,6 @@ */ namespace Magento\Email\Test\Unit\Model; -use Magento\Email\Model\Template\Filter; use Magento\Framework\App\Area; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\TemplateTypesInterface; @@ -426,18 +425,13 @@ public function testGetAndSetId() } /** - * @param $isSMTPDisabled bool * @param $senderName string * @param $senderEmail string * @param $templateSubject string * @dataProvider isValidForSendDataProvider */ - public function testIsValidForSend($isSMTPDisabled, $senderName, $senderEmail, $templateSubject, $expectedValue) + public function testIsValidForSend($senderName, $senderEmail, $templateSubject, $expectedValue) { - $this->scopeConfig->expects($this->once()) - ->method('isSetFlag') - ->with('system/smtp/disable', ScopeInterface::SCOPE_STORE) - ->will($this->returnValue($isSMTPDisabled)); $model = $this->getModelMock(['getSenderName', 'getSenderEmail', 'getTemplateSubject']); $model->expects($this->any()) ->method('getSenderName') @@ -455,35 +449,24 @@ public function isValidForSendDataProvider() { return [ 'should be valid' => [ - 'isSMTPDisabled' => false, 'senderName' => 'sender name', 'senderEmail' => 'email@example.com', 'templateSubject' => 'template subject', 'expectedValue' => true ], - 'no smtp so not valid' => [ - 'isSMTPDisabled' => true, - 'senderName' => 'sender name', - 'senderEmail' => 'email@example.com', - 'templateSubject' => 'template subject', - 'expectedValue' => false - ], 'no sender name so not valid' => [ - 'isSMTPDisabled' => false, 'senderName' => '', 'senderEmail' => 'email@example.com', 'templateSubject' => 'template subject', 'expectedValue' => false ], 'no sender email so not valid' => [ - 'isSMTPDisabled' => false, 'senderName' => 'sender name', 'senderEmail' => '', 'templateSubject' => 'template subject', 'expectedValue' => false ], 'no subject so not valid' => [ - 'isSMTPDisabled' => false, 'senderName' => 'sender name', 'senderEmail' => 'email@example.com', 'templateSubject' => '', diff --git a/app/code/Magento/Email/etc/di.xml b/app/code/Magento/Email/etc/di.xml index 8f45f50531737..6224089d2628f 100644 --- a/app/code/Magento/Email/etc/di.xml +++ b/app/code/Magento/Email/etc/di.xml @@ -21,4 +21,7 @@ Magento\Framework\Url + + + diff --git a/app/code/Magento/Newsletter/Model/Template.php b/app/code/Magento/Newsletter/Model/Template.php index 53f7e5e5852f7..183178d9e9717 100644 --- a/app/code/Magento/Newsletter/Model/Template.php +++ b/app/code/Magento/Newsletter/Model/Template.php @@ -174,7 +174,8 @@ public function validate() public function beforeSave() { $this->validate(); - return parent::beforeSave(); + parent::beforeSave(); + return $this; } /** @@ -238,9 +239,6 @@ protected function getFilterFactory() */ public function isValidForSend() { - return !$this->scopeConfig->isSetFlag( - \Magento\Email\Model\Template::XML_PATH_SYSTEM_SMTP_DISABLE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) && $this->getTemplateSenderName() && $this->getTemplateSenderEmail() && $this->getTemplateSubject(); + return $this->getTemplateSenderName() && $this->getTemplateSenderEmail() && $this->getTemplateSubject(); } } diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php index 0bf24fdf4c483..0644d4b4df895 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php @@ -379,4 +379,55 @@ public function getProcessedTemplateDataProvider() ], ]; } + + /** + * @param $senderName string + * @param $senderEmail string + * @param $templateSubject string + * @dataProvider isValidForSendDataProvider + */ + public function testIsValidForSend($senderName, $senderEmail, $templateSubject, $expectedValue) + { + $model = $this->getModelMock(['getTemplateSenderName', 'getTemplateSenderEmail', 'getTemplateSubject']); + $model->expects($this->any()) + ->method('getTemplateSenderName') + ->will($this->returnValue($senderName)); + $model->expects($this->any()) + ->method('getTemplateSenderEmail') + ->will($this->returnValue($senderEmail)); + $model->expects($this->any()) + ->method('getTemplateSubject') + ->will($this->returnValue($templateSubject)); + $this->assertEquals($expectedValue, $model->isValidForSend()); + } + + public function isValidForSendDataProvider() + { + return [ + 'should be valid' => [ + 'senderName' => 'sender name', + 'senderEmail' => 'email@example.com', + 'templateSubject' => 'template subject', + 'expectedValue' => true + ], + 'no sender name so not valid' => [ + 'senderName' => '', + 'senderEmail' => 'email@example.com', + 'templateSubject' => 'template subject', + 'expectedValue' => false + ], + 'no sender email so not valid' => [ + 'senderName' => 'sender name', + 'senderEmail' => '', + 'templateSubject' => 'template subject', + 'expectedValue' => false + ], + 'no subject so not valid' => [ + 'senderName' => 'sender name', + 'senderEmail' => 'email@example.com', + 'templateSubject' => '', + 'expectedValue' => false + ], + ]; + } } From 53209aa0bcbe20efb0cdc965a3bc0839e8649bd9 Mon Sep 17 00:00:00 2001 From: lestare Date: Mon, 7 Nov 2016 03:50:50 -0500 Subject: [PATCH 04/10] MAGETWO-58377: PayPal Payflow Pro always using USD (even if this currency is absent on your store) - for 2.0 --- .../Paypal/Model/Payflow/Transparent.php | 26 +++++++++++-------- .../Unit/Model/Payflow/TransparentTest.php | 5 +++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Payflow/Transparent.php b/app/code/Magento/Paypal/Model/Payflow/Transparent.php index e1c7e42b93535..a9973cf8b4a7a 100644 --- a/app/code/Magento/Paypal/Model/Payflow/Transparent.php +++ b/app/code/Magento/Paypal/Model/Payflow/Transparent.php @@ -5,16 +5,16 @@ */ namespace Magento\Paypal\Model\Payflow; -use Magento\Framework\DataObject; -use Magento\Paypal\Model\Payflowpro; -use Magento\Sales\Model\Order\Payment; -use Magento\Paypal\Model\Payflow\Service\Gateway; use Magento\Framework\Exception\LocalizedException; -use Magento\Payment\Model\Method\TransparentInterface; -use Magento\Payment\Model\Method\ConfigInterfaceFactory; use Magento\Framework\Exception\State\InvalidTransitionException; +use Magento\Payment\Model\InfoInterface; +use Magento\Payment\Model\Method\ConfigInterfaceFactory; +use Magento\Payment\Model\Method\TransparentInterface; +use Magento\Paypal\Model\Payflow\Service\Gateway; use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface; use Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidator; +use Magento\Paypal\Model\Payflowpro; +use Magento\Sales\Model\Order\Payment; /** * Payflow Pro payment gateway model @@ -112,23 +112,27 @@ public function validate() /** * Performs authorize transaction * - * @param \Magento\Payment\Model\InfoInterface|Object $payment + * @param InfoInterface|Object $payment * @param float $amount * @return $this * @throws InvalidTransitionException * @throws LocalizedException */ - public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount) + public function authorize(InfoInterface $payment, $amount) { + /** @var Payment $payment */ $request = $this->buildBasicRequest(); + /** @var \Magento\Sales\Model\Order $order */ $order = $payment->getOrder(); $this->addRequestOrderInfo($request, $order); $request = $this->fillCustomerContacts($order, $request); - $request->setTrxtype(self::TRXTYPE_AUTH_ONLY); - $request->setOrigid($payment->getAdditionalInformation('pnref')); - $request->setAmt(round($amount, 2)); + $token = $payment->getAdditionalInformation('pnref'); + $request->setData('trxtype', self::TRXTYPE_AUTH_ONLY); + $request->setData('origid', $token); + $request->setData('amt', round($amount, 2)); + $request->setData('currency', $order->getBaseCurrencyCode()); $response = $this->postRequest($request, $this->getConfig()); $this->processErrors($response); diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php index 90c5567e6bbd6..645adb355401f 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php @@ -121,7 +121,7 @@ protected function initializationAuthorizeMock() $this->orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') ->setMethods([ 'getCustomerId', 'getBillingAddress', 'getShippingAddress', 'getCustomerEmail', - 'getId', 'getIncrementId' + 'getId', 'getIncrementId', 'getBaseCurrencyCode' ]) ->disableOriginalConstructor() ->getMock(); @@ -163,6 +163,9 @@ protected function buildRequestData() $this->paymentMock->expects($this->once()) ->method('getOrder') ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('getBaseCurrencyCode') + ->willReturn('USD'); $this->orderMock->expects($this->once()) ->method('getBillingAddress') ->willReturn($this->addressBillingMock); From 061a7f752ced0c84a14e071eb8360f1984603457 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Mon, 7 Nov 2016 11:08:53 +0200 Subject: [PATCH 05/10] MAGETWO-59035: [Backport] [GITHUB] Broken File Type Custom Option #5434 - 2.0 --- .../Model/Product/Option/Type/File.php | 18 +++++-- .../Model/Product/Option/Type/FileTest.php | 49 +++++++++++++------ app/code/Magento/Catalog/etc/di.xml | 3 ++ app/code/Magento/Catalog/etc/frontend/di.xml | 3 -- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index d974174ef7088..70c20a4e31490 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -5,6 +5,7 @@ */ namespace Magento\Catalog\Model\Product\Option\Type; +use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Exception\LocalizedException; use Magento\Catalog\Model\Product\Exception as ProductException; @@ -69,17 +70,23 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $validatorFile; + /** + * @var Filesystem + */ + private $filesystem; + /** * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Quote\Model\Quote\Item\OptionFactory $itemOptionFactory - * @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder - * @param \Magento\Framework\Escaper $escaper * @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase * @param File\ValidatorInfo $validatorInfo * @param File\ValidatorFile $validatorFile + * @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder + * @param \Magento\Framework\Escaper $escaper * @param array $data - * @throws \Magento\Framework\Exception\FileSystemException + * @param Filesystem $filesystem + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, @@ -90,12 +97,15 @@ public function __construct( \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile, \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder, \Magento\Framework\Escaper $escaper, - array $data = [] + array $data = [], + Filesystem $filesystem = null ) { $this->_itemOptionFactory = $itemOptionFactory; $this->_urlBuilder = $urlBuilder; $this->_escaper = $escaper; $this->_coreFileStorageDatabase = $coreFileStorageDatabase; + $this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class); + $this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $this->validatorInfo = $validatorInfo; $this->validatorFile = $validatorFile; parent::__construct($checkoutSession, $scopeConfig, $data); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php index 211a6fc59bfc6..6682b29547632 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php @@ -5,6 +5,12 @@ */ namespace Magento\Catalog\Test\Unit\Model\Product\Option\Type; +use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use Magento\Framework\Filesystem\DriverPool; + class FileTest extends \PHPUnit_Framework_TestCase { /** @@ -13,7 +19,7 @@ class FileTest extends \PHPUnit_Framework_TestCase protected $objectManager; /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $rootDirectory; @@ -22,17 +28,29 @@ class FileTest extends \PHPUnit_Framework_TestCase */ protected $coreFileStorageDatabase; - public function setUp() + /** + * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject + */ + private $filesystemMock; + + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->rootDirectory = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface') + $this->filesystemMock = $this->getMockBuilder(Filesystem::class) ->disableOriginalConstructor() - ->setMethods(['isFile', 'isReadable', 'getAbsolutePath']) - ->getMockForAbstractClass(); + ->getMock(); + + $this->rootDirectory = $this->getMockBuilder(ReadInterface::class) + ->getMock(); + + $this->filesystemMock->expects($this->once()) + ->method('getDirectoryRead') + ->with(DirectoryList::MEDIA, DriverPool::FILE) + ->willReturn($this->rootDirectory); $this->coreFileStorageDatabase = $this->getMock( - 'Magento\MediaStorage\Helper\File\Storage\Database', + \Magento\MediaStorage\Helper\File\Storage\Database::class, ['copyFile'], [], '', @@ -46,28 +64,29 @@ public function setUp() protected function getFileObject() { return $this->objectManager->getObject( - 'Magento\Catalog\Model\Product\Option\Type\File', + \Magento\Catalog\Model\Product\Option\Type\File::class, [ - 'saleableItem' => $this->rootDirectory, - 'priceCurrency' => $this->coreFileStorageDatabase + 'filesystem' => $this->filesystemMock, + 'coreFileStorageDatabase' => $this->coreFileStorageDatabase ] ); } public function testCopyQuoteToOrder() { - $optionMock = $this->getMockBuilder( - 'Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface' - )->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass(); + $optionMock = $this->getMockBuilder(OptionInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getValue']) + ->getMockForAbstractClass(); $quotePath = '/quote/path/path/uploaded.file'; $orderPath = '/order/path/path/uploaded.file'; $optionMock->expects($this->any()) ->method('getValue') - ->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath])); + ->will($this->returnValue(serialize(['quote_path' => $quotePath, 'order_path' => $orderPath]))); - $this->rootDirectory->expects($this->any()) + $this->rootDirectory->expects($this->once()) ->method('isFile') ->with($this->equalTo($quotePath)) ->will($this->returnValue(true)); @@ -89,7 +108,7 @@ public function testCopyQuoteToOrder() $fileObject->setData('configuration_item_option', $optionMock); $this->assertInstanceOf( - 'Magento\Catalog\Model\Product\Option\Type\File', + \Magento\Catalog\Model\Product\Option\Type\File::class, $fileObject->copyQuoteToOrder() ); } diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 224f349a10571..e8b088b19cb16 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -540,4 +540,7 @@ + + + diff --git a/app/code/Magento/Catalog/etc/frontend/di.xml b/app/code/Magento/Catalog/etc/frontend/di.xml index d9a656908038c..815b3ee71f940 100644 --- a/app/code/Magento/Catalog/etc/frontend/di.xml +++ b/app/code/Magento/Catalog/etc/frontend/di.xml @@ -11,9 +11,6 @@ Magento\Framework\Data\Collection\Db\FetchStrategy\Cache - - - true From 0b9e1f6ab3af6f2d81b7960fa0fe1f945b50bff8 Mon Sep 17 00:00:00 2001 From: DianaRusin Date: Mon, 7 Nov 2016 04:55:20 -0500 Subject: [PATCH 06/10] MAGETWO-58498: Newsletter need to confirm doesn't work - for 2.0 --- .../Magento/Newsletter/Model/Subscriber.php | 10 +++++- .../Test/Unit/Model/SubscriberTest.php | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index a208274a2cc8d..4fd538bf0ae77 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -548,11 +548,17 @@ protected function _updateCustomerSubscription($customerId, $subscribe) $sendInformationEmail = false; $status = self::STATUS_SUBSCRIBED; + $isConfirmNeed = $this->_scopeConfig->getValue( + self::XML_PATH_CONFIRMATION_FLAG, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) == 1 ? true : false; if ($subscribe) { if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED == $this->customerAccountManagement->getConfirmationStatus($customerId) ) { $status = self::STATUS_UNCONFIRMED; + } else if ($isConfirmNeed) { + $status = self::STATUS_NOT_ACTIVE; } } else { $status = self::STATUS_UNSUBSCRIBED; @@ -587,7 +593,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe) $sendSubscription = $sendInformationEmail; if ($sendSubscription === null xor $sendSubscription) { try { - if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) { + if ($isConfirmNeed) { + $this->sendConfirmationRequestEmail(); + } else if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) { $this->sendUnsubscriptionEmail(); } elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) { $this->sendConfirmationSuccessEmail(); diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php index fdf4abf5b87b4..f41ba048c9614 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php @@ -256,6 +256,37 @@ public function testSubscribeCustomerById() $this->subscriber->subscribeCustomerById($customerId); } + + public function testSubscribeCustomerById1() + { + $customerId = 1; + $customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) + ->getMock(); + $this->customerRepository->expects($this->atLeastOnce()) + ->method('getById') + ->with($customerId)->willReturn($customerDataMock); + $this->resource->expects($this->atLeastOnce()) + ->method('loadByCustomerData') + ->with($customerDataMock) + ->willReturn( + [ + 'subscriber_id' => 1, + 'subscriber_status' => 3 + ] + ); + $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); + $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); + $customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id'); + $customerDataMock->expects($this->once())->method('getEmail')->willReturn('email'); + $this->sendEmailCheck(); + $this->customerAccountManagement->expects($this->once()) + ->method('getConfirmationStatus') + ->willReturn(\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_NOT_REQUIRED); + $this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true); + + $this->subscriber->subscribeCustomerById($customerId); + $this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus()); + } public function testUnsubscribe() { From 893ba7e9e5552a7de4abb87f3041a3e7e2daf4bf Mon Sep 17 00:00:00 2001 From: lestare Date: Mon, 7 Nov 2016 07:45:40 -0500 Subject: [PATCH 07/10] MAGETWO-60464: There is no Scope Selector on Product Grid - for 2.0 --- .../Adminhtml/Product/MassStatus.php | 25 ++- .../Adminhtml/Product/MassStatusTest.php | 151 ++++++++++++++---- .../Unit/Controller/Adminhtml/ProductTest.php | 4 + 3 files changed, 140 insertions(+), 40 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php index 1f3345ee2f807..fe1cde2a26a0f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php @@ -6,16 +6,17 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; -use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; use Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Catalog\Model\Indexer\Product\Price\Processor; +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; use Magento\Framework\Controller\ResultFactory; use Magento\Ui\Component\MassAction\Filter; -use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product { /** - * @var \Magento\Catalog\Model\Indexer\Product\Price\Processor + * @var Processor */ protected $_productPriceIndexerProcessor; @@ -32,22 +33,23 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product protected $collectionFactory; /** - * @param Action\Context $context + * @param Context $context * @param Builder $productBuilder - * @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor + * @param Processor $productPriceIndexerProcessor * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, + Context $context, Product\Builder $productBuilder, - \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor, + Processor $productPriceIndexerProcessor, Filter $filter, CollectionFactory $collectionFactory ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; $this->_productPriceIndexerProcessor = $productPriceIndexerProcessor; + parent::__construct($context, $productBuilder); } @@ -82,6 +84,14 @@ public function execute() $storeId = (int) $this->getRequest()->getParam('store', 0); $status = (int) $this->getRequest()->getParam('status'); + /** @var array $filters */ + $filters = (array) $this->getRequest()->getParam('filters', []); + + if (isset($filters['store_id'])) { + /** @var int $storeId */ + $storeId = (int) $filters['store_id']; + } + try { $this->_validateMassStatus($productIds, $status); $this->_objectManager->get('Magento\Catalog\Model\Product\Action') @@ -96,6 +106,7 @@ public function execute() /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php index 60bdb8c836583..9742250b2d4f7 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php @@ -6,80 +6,165 @@ */ namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product; -class MassStatusTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Catalog\Controller\Adminhtml\Product\Builder; +use Magento\Catalog\Controller\Adminhtml\Product\MassStatus; +use Magento\Catalog\Model\Indexer\Product\Price\Processor; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Action; +use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; +use Magento\Framework\App\Request\Http; +use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\ObjectManager\ObjectManager as Manager; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Ui\Component\MassAction\Filter; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class MassStatusTest extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $priceProcessor; + private $priceProcessorMock; + + /** + * @var \Magento\Catalog\Controller\Adminhtml\Product\MassStatus + */ + private $action; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $abstractDbMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $filterMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $requestMock; - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\View\Result\Redirect */ - protected $resultRedirect; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $actionMock; protected function setUp() { - $this->priceProcessor = $this->getMockBuilder('Magento\Catalog\Model\Indexer\Product\Price\Processor') + $objectManagerMock = $this->getMockBuilder(Manager::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManagerHelper = new ObjectManager($this); + $this->priceProcessorMock = $this->getMockBuilder(Processor::class) ->disableOriginalConstructor()->getMock(); - $productBuilder = $this->getMockBuilder('Magento\Catalog\Controller\Adminhtml\Product\Builder')->setMethods([ - 'build', - ])->disableOriginalConstructor()->getMock(); + $productBuilderMock = $this->getMockBuilder(Builder::class)->setMethods([ + 'build', + ])->disableOriginalConstructor()->getMock(); - $product = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor() + $this->requestMock = $this->getMockBuilder(Http::class)->setMethods( + ['getParam', 'getPost', 'getFullActionName', 'getPostValue'] + )->disableOriginalConstructor()->getMock(); + + $productMock = $this->getMockBuilder(Product::class)->disableOriginalConstructor() ->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock(); - $product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); - $product->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); - $productBuilder->expects($this->any())->method('build')->will($this->returnValue($product)); + $productMock->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); + $productMock->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); + $productBuilderMock->expects($this->any())->method('build')->will($this->returnValue($productMock)); - $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + $resultRedirectMock = $this->getMockBuilder(Redirect::class) ->disableOriginalConstructor() ->getMock(); - $resultFactory = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') + $resultFactory = $this->getMockBuilder(ResultFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $resultFactory->expects($this->atLeastOnce()) ->method('create') - ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT) - ->willReturn($this->resultRedirect); + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($resultRedirectMock); - $abstractDbMock = $this->getMockBuilder('Magento\Framework\Data\Collection\AbstractDb') + $this->abstractDbMock = $this->getMockBuilder(AbstractDb::class) ->disableOriginalConstructor() ->setMethods(['getAllIds', 'getResource']) ->getMock(); - $abstractDbMock->expects($this->any()) + $this->abstractDbMock->expects($this->any()) ->method('getAllIds') ->willReturn([]); - $filterMock = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter') + $this->filterMock = $this->getMockBuilder(Filter::class) ->disableOriginalConstructor() ->setMethods(['getCollection']) ->getMock(); - $filterMock->expects($this->any()) + $this->filterMock->expects($this->any()) ->method('getCollection') - ->willReturn($abstractDbMock); - - $collectionFactoryMock = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory') + ->willReturn($this->abstractDbMock); + $this->actionMock = $this->getMockBuilder(Action::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManagerMock->expects($this->any())->method('get')->willReturn($this->actionMock); + $collectionFactoryMock = $this->getMockBuilder(ProductCollectionFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $collectionFactoryMock->expects($this->any()) ->method('create') - ->willReturn($abstractDbMock); - - $additionalParams = ['resultFactory' => $resultFactory]; - $this->action = new \Magento\Catalog\Controller\Adminhtml\Product\MassStatus( - $this->initContext($additionalParams), - $productBuilder, - $this->priceProcessor, - $filterMock, - $collectionFactoryMock + ->willReturn($this->abstractDbMock); + $this->requestMock = $this->getMockBuilder(Http::class)->setMethods( + ['getParam', 'getPost', 'getFullActionName', 'getPostValue'] + )->disableOriginalConstructor()->getMock(); + + $this->action = $objectManagerHelper->getObject( + MassStatus::class, + [ + 'objectManager' => $objectManagerMock, + 'request' => $this->requestMock, + 'productBuilder' => $productBuilderMock, + 'filter' => $this->filterMock, + 'productPriceIndexerProcessor' => $this->priceProcessorMock, + 'collectionFactory' => $collectionFactoryMock, + 'resultFactory' => $resultFactory + ] ); + } public function testMassStatusAction() { - $this->priceProcessor->expects($this->once())->method('reindexList'); + $storeId = 1; + $status = Status::STATUS_DISABLED; + $filters = [ + 'store_id' => 2, + ]; + + $productIds = [3]; + + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->willReturn($this->abstractDbMock); + $this->abstractDbMock->expects($this->once()) + ->method('getAllIds') + ->willReturn($productIds); + $this->requestMock->expects($this->exactly(3)) + ->method('getParam') + ->willReturnMap([ + ['store', 0, $storeId], + ['status', null, $status], + ['filters', [], $filters] + ]); + $this->actionMock->expects($this->once()) + ->method('updateAttributes'); + $this->priceProcessorMock->expects($this->once()) + ->method('reindexList'); + $this->action->execute(); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php index 13c89a0d34151..54257c4dfc95e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php @@ -9,12 +9,16 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $context; + /** @var \Magento\Catalog\Controller\Product */ protected $action; + /** @var \Magento\Framework\View\Layout */ protected $layout; + /** @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ protected $session; + /** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */ protected $request; From 226634671975ccf1e77a5b8e21409d8763787508 Mon Sep 17 00:00:00 2001 From: lestare Date: Tue, 8 Nov 2016 08:25:52 -0500 Subject: [PATCH 08/10] MAGETWO-58377: PayPal Payflow Pro always using USD (even if this currency is absent on your store) - for 2.0 --- app/code/Magento/Paypal/Model/Payflow/Transparent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Payflow/Transparent.php b/app/code/Magento/Paypal/Model/Payflow/Transparent.php index a9973cf8b4a7a..c3328d1fcccdf 100644 --- a/app/code/Magento/Paypal/Model/Payflow/Transparent.php +++ b/app/code/Magento/Paypal/Model/Payflow/Transparent.php @@ -5,6 +5,7 @@ */ namespace Magento\Paypal\Model\Payflow; +use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\State\InvalidTransitionException; use Magento\Payment\Model\InfoInterface; @@ -14,7 +15,6 @@ use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface; use Magento\Paypal\Model\Payflow\Service\Response\Validator\ResponseValidator; use Magento\Paypal\Model\Payflowpro; -use Magento\Sales\Model\Order\Payment; /** * Payflow Pro payment gateway model @@ -120,7 +120,7 @@ public function validate() */ public function authorize(InfoInterface $payment, $amount) { - /** @var Payment $payment */ + /** @var DataObject $request */ $request = $this->buildBasicRequest(); /** @var \Magento\Sales\Model\Order $order */ From 23fca8f2fecd07ef9bd8c9add2e37ddd25242e25 Mon Sep 17 00:00:00 2001 From: RomaKis Date: Wed, 9 Nov 2016 10:55:51 +0200 Subject: [PATCH 09/10] MAGETWO-58833: [Backport] Order comments history shows time of comment twice - for 2.0.x --- .../Adminhtml/Order/View/Tab/History.php | 8 +-- .../Adminhtml/Order/View/Tab/HistoryTest.php | 62 ++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php index 8a6674aa154b0..51fb11927dbb2 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php @@ -157,13 +157,11 @@ public function getItemCreatedAt(array $item, $dateType = 'date', $format = \Int if (!isset($item['created_at'])) { return ''; } - $date = $item['created_at'] instanceof \DateTimeInterface - ? $item['created_at'] - : new \DateTime($item['created_at']); if ('date' === $dateType) { - return $this->_localeDate->formatDateTime($date, $format, $format); + return $this->formatDate($item['created_at'], $format); } - return $this->_localeDate->formatDateTime($date, \IntlDateFormatter::NONE, $format); + + return $this->formatTime($item['created_at'], $format); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php index 79b349feabd88..1f8edb11e4f5f 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php @@ -30,6 +30,17 @@ class HistoryTest extends \PHPUnit_Framework_TestCase */ protected $coreRegistryMock; + /** + * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeDateMock; + + /** + * @var \Magento\Backend\Block\Template\Context|\PHPUnit_Framework_MockObject_MockObject + */ + protected $contextMock; + + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -37,11 +48,25 @@ protected function setUp() $this->coreRegistryMock = $this->getMock('Magento\Framework\Registry', [], [], '', false); $this->adminHelperMock = $this->getMock('\Magento\Sales\Helper\Admin', [], [], '', false); + $this->contextMock = $this->getMockBuilder(\Magento\Backend\Block\Template\Context::class) + ->disableOriginalConstructor() + ->setMethods(['getLocaleDate']) + ->getMock(); + + $this->localeDateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) + ->getMock(); + + $this->contextMock->expects($this->any())->method('getLocaleDate')->will( + $this->returnValue($this->localeDateMock) + ); + $this->commentsHistory = $this->objectManager->getObject( 'Magento\Sales\Block\Adminhtml\Order\View\Tab\History', [ 'adminHelper' => $this->adminHelperMock, - 'registry' => $this->coreRegistryMock + 'registry' => $this->coreRegistryMock, + 'context' => $this->contextMock, + 'localeDate' => $this->localeDateMock ] ); } @@ -63,4 +88,39 @@ public function testGetItemCommentIsNotSet() $this->adminHelperMock->expects($this->never())->method('escapeHtmlWithLinks'); $this->assertEquals('', $this->commentsHistory->getItemComment($item)); } + + public function testGetItemCreatedAtDate() + { + $date = new \DateTime; + $item = ['created_at' => $date ]; + + $this->localeDateMock->expects($this->once()) + ->method('formatDateTime') + ->with($date, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE) + ->willReturn('date'); + + $this->assertEquals('date', $this->commentsHistory->getItemCreatedAt($item)); + } + + public function testGetItemCreatedAtTime() + { + $date = new \DateTime; + $item = ['created_at' => $date ]; + + $this->localeDateMock->expects($this->once()) + ->method('formatDateTime') + ->with($date, \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM) + ->willReturn('time'); + + $this->assertEquals('time', $this->commentsHistory->getItemCreatedAt($item, 'time')); + } + + public function testGetItemCreatedAtEmpty() + { + $item = ['title' => "Test" ]; + + $this->localeDateMock->expects($this->never())->method('formatDateTime'); + $this->assertEquals('', $this->commentsHistory->getItemCreatedAt($item)); + $this->assertEquals('', $this->commentsHistory->getItemCreatedAt($item, 'time')); + } } From c40ff4738eb0c46228a083dcf612bf468d353b7f Mon Sep 17 00:00:00 2001 From: RomaKis Date: Wed, 9 Nov 2016 11:52:55 +0200 Subject: [PATCH 10/10] MAGETWO-60247: [Backport] Default Billing Address and Default Shipping Address checkboxes on Customer page are saved incorrectly - 2.0 --- .../Controller/Adminhtml/Index/Save.php | 8 +- .../Controller/Adminhtml/Index/SaveTest.php | 113 +++++------------- 2 files changed, 35 insertions(+), 86 deletions(-) diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 59ff3c159b189..3e2b2f61b707f 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -72,7 +72,10 @@ protected function _extractData( $scope = null ) { $metadataForm = $this->getMetadataForm($entityType, $formCode, $scope); + + /** @var array $formData */ $formData = $metadataForm->extractData($this->getRequest(), $scope); + $formData = $metadataForm->compactData($formData); // Initialize additional attributes /** @var \Magento\Framework\DataObject $object */ @@ -82,11 +85,6 @@ protected function _extractData( $formData[$attributeCode] = isset($requestData[$attributeCode]) ? $requestData[$attributeCode] : false; } - $result = $metadataForm->compactData($formData); - - // Re-initialize additional attributes - $formData = array_replace($formData, $result); - // Unset unused attributes $formAttributes = $metadataForm->getAttributes(); foreach ($formAttributes as $attribute) { diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php index d450feaaf7020..1ad6a0cd090b7 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php @@ -291,32 +291,28 @@ public function testExecuteWithExistentCustomer() ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ + $compactedData = [ 'entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, + CustomerInterface::DEFAULT_BILLING => 2, + CustomerInterface::DEFAULT_SHIPPING => 2, ]; - $addressFilteredData = [ + $addressExtractedData = [ 'entity_id' => $addressId, - 'default_billing' => 'true', - 'default_shipping' => 'true', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id', ]; - $addressDataToCompact = [ + $addressCompactedData = [ 'entity_id' => $addressId, 'default_billing' => 'true', 'default_shipping' => 'true', @@ -417,11 +413,11 @@ public function testExecuteWithExistentCustomer() $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($compactedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -432,11 +428,11 @@ public function testExecuteWithExistentCustomer() $customerAddressFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'address/' . $addressId) - ->willReturn($addressFilteredData); + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('compactData') - ->with($addressDataToCompact) - ->willReturn($addressFilteredData); + ->with($addressExtractedData) + ->willReturn($addressCompactedData); $customerAddressFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -606,8 +602,6 @@ public function testExecuteWithNewCustomer() '_template_' => '_template_', $addressId => [ 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', @@ -616,31 +610,12 @@ public function testExecuteWithNewCustomer() ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - ]; - $addressFilteredData = [ + $addressExtractedData = [ 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', - 'code' => 'value', - 'coolness' => false, - 'region' => 'region', - 'region_id' => 'region_id', - ]; - $addressDataToCompact = [ - 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', @@ -720,11 +695,11 @@ public function testExecuteWithNewCustomer() $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -735,11 +710,11 @@ public function testExecuteWithNewCustomer() $customerAddressFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'address/' . $addressId) - ->willReturn($addressFilteredData); + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('compactData') - ->with($addressDataToCompact) - ->willReturn($addressFilteredData); + ->with($addressExtractedData) + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -893,18 +868,10 @@ public function testExecuteWithNewCustomerAndValidationException() ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ $attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface') @@ -954,11 +921,11 @@ public function testExecuteWithNewCustomerAndValidationException() $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -1045,18 +1012,10 @@ public function testExecuteWithNewCustomerAndLocalizedException() ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ $attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface') @@ -1106,11 +1065,11 @@ public function testExecuteWithNewCustomerAndLocalizedException() $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -1197,17 +1156,9 @@ public function testExecuteWithNewCustomerAndException() ], 'subscription' => $subscription, ]; - $filteredData = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - ]; - $dataToCompact = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ @@ -1258,11 +1209,11 @@ public function testExecuteWithNewCustomerAndException() $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes);