From 4fab755a553afed12e842e9418eee6f34fed890d Mon Sep 17 00:00:00 2001 From: okarpenko Date: Mon, 13 Jul 2015 14:40:55 +0300 Subject: [PATCH 1/2] MAGETWO-40041: Increase code coverage for South Team Modules --- .../Design/Wysiwyg/Files/DeleteFilesTest.php | 104 ++++++++++++++++++ .../Design/Wysiwyg/Files/DeleteFolderTest.php | 71 ++++++++++++ .../System/Design/Wysiwyg/Files/IndexTest.php | 39 +++++++ .../Design/Wysiwyg/Files/OnInsertTest.php | 59 ++++++++++ 4 files changed, 273 insertions(+) create mode 100644 app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFilesTest.php create mode 100644 app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolderTest.php create mode 100644 app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/IndexTest.php create mode 100644 app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsertTest.php 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 0000000000000..2a69f64be343e --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFilesTest.php @@ -0,0 +1,104 @@ +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 0000000000000..9bd042cfe2e58 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/DeleteFolderTest.php @@ -0,0 +1,71 @@ +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 0000000000000..63884649f39f4 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/IndexTest.php @@ -0,0 +1,39 @@ +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 0000000000000..0061013ed728c --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/System/Design/Wysiwyg/Files/OnInsertTest.php @@ -0,0 +1,59 @@ +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(); + } +} From 0e4359909e46eb2ef25fedc9e35482ba37b04d68 Mon Sep 17 00:00:00 2001 From: Maxim Medinskiy Date: Tue, 14 Jul 2015 15:20:01 +0300 Subject: [PATCH 2/2] MAGETWO-40041: Increase code coverage for South Team Modules --- .../Wishlist/Test/Unit/Model/ItemTest.php | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php index 76b46f13538da..f31a0ced59d61 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 @@ public function testRemoveOptionByCode($code, $option) $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 @@ public function getOptionsDataProvider() ->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 @@ public function testCompareOptionsNegativeOptionsTwoHaveNotOption() $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()); + } }