diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index c4969c8a280d0373513797e8ee6c34ca1f6a210e..cad13566790df2a0385c7394e5bbc04d84db9c39 100755 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -1413,7 +1413,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract */ protected function _processSaveData($saveData) { - extract($saveData); + extract($saveData, EXTR_SKIP); /** * Import variables into the current symbol table from save data array * diff --git a/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php b/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php index f760294d0ca6c6b8f36c214ed2efc47ed618f34f..44cd56531af469e2b8a80a734fcfeaa9400b27fc 100644 --- a/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php +++ b/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php @@ -40,7 +40,8 @@ class PlaceOrder extends \Magento\Paypal\Controller\Express\AbstractExpress $order = $this->_checkout->getOrder(); if ($order) { $this->_getCheckoutSession()->setLastOrderId($order->getId()) - ->setLastRealOrderId($order->getIncrementId()); + ->setLastRealOrderId($order->getIncrementId()) + ->setLastOrderStatus($order->getStatus()); } $this->_eventManager->dispatch( diff --git a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFilesTest.php b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFilesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2a69f64be343ee3f155b2862cc2f227b5ad3b1b5 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFilesTest.php @@ -0,0 +1,104 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class DeleteFilesTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */ + protected $controller; + + /** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/ + protected $objectManager; + + /** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */ + protected $storage; + + /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $request; + + /** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ + protected $response; + + public function setUp() + { + $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); + $this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false); + $this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); + $this->request = $this->getMockForAbstractClass( + 'Magento\Framework\App\RequestInterface', + [], + '', + false, + false, + true, + ['isPost', 'getParam'] + ); + + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->controller = $helper->getObject( + 'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFiles', + [ + 'objectManager' => $this->objectManager, + 'request' => $this->request, + 'response' => $this->response, + ] + ); + } + + public function testExecuteWithWrongRequest() + { + $this->request->expects($this->once()) + ->method('isPost') + ->willReturn(false); + + $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); + $jsonData->expects($this->once()) + ->method('jsonEncode') + ->with(['error' => true, 'message' => 'Wrong request']) + ->willReturn('{"error":"true","message":"Wrong request"}'); + + $this->objectManager->expects($this->once()) + ->method('get') + ->with('Magento\Framework\Json\Helper\Data') + ->willReturn($jsonData); + + $this->response->expects($this->once()) + ->method('representJson') + ->with('{"error":"true","message":"Wrong request"}'); + + $this->controller->execute(); + } + + public function testExecute() + { + $this->request->expects($this->once()) + ->method('isPost') + ->willReturn(true); + $this->request->expects($this->once()) + ->method('getParam') + ->with('files') + ->willReturn('{"files":"file"}'); + + $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); + $jsonData->expects($this->once()) + ->method('jsonDecode') + ->with('{"files":"file"}') + ->willReturn(['files' => 'file']); + $this->objectManager->expects($this->at(0)) + ->method('get') + ->with('Magento\Framework\Json\Helper\Data') + ->willReturn($jsonData); + $this->objectManager->expects($this->at(1)) + ->method('get') + ->with('Magento\Theme\Model\Wysiwyg\Storage') + ->willReturn($this->storage); + $this->storage->expects($this->once()) + ->method('deleteFile') + ->with('file'); + + $this->controller->execute(); + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolderTest.php b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9bd042cfe2e5864a6f86e5afa848ad63b9ca1a79 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolderTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class DeleteFolderTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */ + protected $controller; + + /** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/ + protected $objectManager; + + /** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ + protected $response; + + /** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */ + protected $storage; + + /** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */ + protected $storageHelper; + + public function setUp() + { + $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); + $this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); + $this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false); + $this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false); + + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->controller = $helper->getObject( + 'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFolder', + [ + 'objectManager' => $this->objectManager, + 'response' => $this->response, + 'storage' => $this->storageHelper + ] + ); + } + + public function testExecute() + { + $this->storageHelper->expects($this->once()) + ->method('getCurrentPath') + ->willReturn('/current/path/'); + + $this->objectManager->expects($this->at(0)) + ->method('get') + ->with('Magento\Theme\Model\Wysiwyg\Storage') + ->willReturn($this->storage); + $this->storage->expects($this->once()) + ->method('deleteDirectory') + ->with('/current/path/') + ->willThrowException(new \Exception('Message')); + + $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); + $jsonData->expects($this->once()) + ->method('jsonEncode') + ->with(['error' => true, 'message' => 'Message']) + ->willReturn('{"error":"true","message":"Message"}'); + + $this->objectManager->expects($this->at(1)) + ->method('get') + ->with('Magento\Framework\Json\Helper\Data') + ->willReturn($jsonData); + + $this->controller->execute(); + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/IndexTest.php b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/IndexTest.php new file mode 100644 index 0000000000000000000000000000000000000000..63884649f39f4baf66a5886619757abb381a529a --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/IndexTest.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class IndexTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */ + protected $controller; + + /** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $view; + + public function setUp() + { + $this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false); + + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->controller = $helper->getObject( + 'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\Index', + [ + 'view' => $this->view, + ] + ); + } + + public function testExecute() + { + $this->view ->expects($this->once()) + ->method('loadLayout') + ->with('overlay_popup'); + $this->view ->expects($this->once()) + ->method('renderLayout'); + + $this->controller->execute(); + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsertTest.php b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsertTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0061013ed728c00cc216b889f9dcd4ec2b4e28c4 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsertTest.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files; + +class OnInsertTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */ + protected $controller; + + /** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $view; + + /** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject */ + protected $objectManager; + + /** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */ + protected $storageHelper; + + /** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ + protected $response; + + public function setUp() + { + $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); + $this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false); + $this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false); + $this->response = $this->getMock('Magento\Framework\App\Response\Http', ['setBody'], [], '', false); + + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->controller = $helper->getObject( + 'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\OnInsert', + [ + 'objectManager' => $this->objectManager, + 'view' => $this->view, + 'response' => $this->response + ] + ); + } + + public function testExecute() + { + $this->objectManager->expects($this->once()) + ->method('get') + ->with('Magento\Theme\Helper\Storage') + ->willReturn($this->storageHelper); + $this->storageHelper + ->expects($this->once()) + ->method('getRelativeUrl') + ->willReturn('http://relative.url/'); + $this->response->expects($this->once()) + ->method('setBody') + ->with('http://relative.url/'); + + $this->controller->execute(); + } +} diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php index 76b46f13538da68b31514bce752b669cda2b9194..f31a0ced59d6143fc7f1db6a97f1f3d6338f2423 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php @@ -165,7 +165,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase $this->model->addOption($option); $this->assertEquals(1, count($this->model->getOptions())); $this->model->removeOption($code); - $actualOptions = $this->model->getOptions(); + $actualOptions = $this->model->getOptions(); $actualOption = array_pop($actualOptions); $this->assertTrue($actualOption->isDeleted()); } @@ -185,7 +185,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase ->getMock(); return [ ['first_key', ['code' => 'first_key', 'value' => 'first_data']], - ['second_key',$optionMock], + ['second_key', $optionMock], ['third_key', new \Magento\Framework\Object(['code' => 'third_key', 'product' => $productMock])], ]; } @@ -262,4 +262,63 @@ class ItemTest extends \PHPUnit_Framework_TestCase $this->assertFalse($result); } + + public function testSetAndSaveItemOptions() + { + $this->assertEmpty($this->model->getOptions()); + $firstOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option') + ->disableOriginalConstructor() + ->setMethods(['getCode', 'isDeleted', 'delete', '__wakeup']) + ->getMock(); + $firstOptionMock->expects($this->any()) + ->method('getCode') + ->willReturn('first_code'); + $firstOptionMock->expects($this->any()) + ->method('isDeleted') + ->willReturn(true); + $firstOptionMock->expects($this->once()) + ->method('delete'); + + $secondOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option') + ->disableOriginalConstructor() + ->setMethods(['getCode', 'save', '__wakeup']) + ->getMock(); + $secondOptionMock->expects($this->any()) + ->method('getCode') + ->willReturn('second_code'); + $secondOptionMock->expects($this->once()) + ->method('save'); + + $this->model->setOptions([$firstOptionMock, $secondOptionMock]); + $this->assertNull($this->model->isOptionsSaved()); + $this->model->saveItemOptions(); + $this->assertTrue($this->model->isOptionsSaved()); + } + + public function testGetProductWithException() + { + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', __('Cannot specify product.')); + $this->model->getProduct(); + } + + public function testGetProduct() + { + $productId = 1; + $storeId = 0; + $this->model->setData('product_id', $productId); + $this->model->setData('store_id', $storeId); + $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') + ->disableOriginalConstructor() + ->getMock(); + $productMock->expects($this->any()) + ->method('setFinalPrice') + ->with(null); + $productMock->expects($this->any()) + ->method('setCustomOprtions') + ->with([]); + $this->productRepository->expects($this->once()) + ->method('getById') + ->willReturn($productMock); + $this->assertEquals($productMock, $this->model->getProduct()); + } }