|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product; |
| 7 | + |
| 8 | +use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper; |
| 9 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 10 | + |
| 11 | +class ValidateTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest |
| 12 | +{ |
| 13 | + /** @var \Magento\Catalog\Controller\Adminhtml\Product\Validate */ |
| 14 | + protected $action; |
| 15 | + /** @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ |
| 16 | + protected $resultPage; |
| 17 | + /** @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject */ |
| 18 | + protected $resultForward; |
| 19 | + /** @var \Magento\Catalog\Controller\Adminhtml\Product\Builder|\PHPUnit_Framework_MockObject_MockObject */ |
| 20 | + protected $productBuilder; |
| 21 | + /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */ |
| 22 | + protected $product; |
| 23 | + /** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */ |
| 24 | + protected $resultRedirectFactory; |
| 25 | + /** @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ |
| 26 | + protected $resultRedirect; |
| 27 | + /** @var Helper|\PHPUnit_Framework_MockObject_MockObject */ |
| 28 | + protected $initializationHelper; |
| 29 | + /** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */ |
| 30 | + protected $productFactory; |
| 31 | + /** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */ |
| 32 | + protected $resultJson; |
| 33 | + /** @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject */ |
| 34 | + protected $resultJsonFactory; |
| 35 | + |
| 36 | + protected function setUp() |
| 37 | + { |
| 38 | + $this->productBuilder = $this->getMock( |
| 39 | + 'Magento\Catalog\Controller\Adminhtml\Product\Builder', |
| 40 | + ['build'], |
| 41 | + [], |
| 42 | + '', |
| 43 | + false |
| 44 | + ); |
| 45 | + $this->product = $this->getMockBuilder('Magento\Catalog\Model\Product')->disableOriginalConstructor() |
| 46 | + ->setMethods([ |
| 47 | + 'addData', 'getSku', 'getTypeId', 'getStoreId', '__sleep', '__wakeup', 'getAttributes', |
| 48 | + 'setAttributeSetId', |
| 49 | + ]) |
| 50 | + ->getMock(); |
| 51 | + $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); |
| 52 | + $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); |
| 53 | + $this->product->expects($this->any())->method('getAttributes')->will($this->returnValue([])); |
| 54 | + $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product)); |
| 55 | + |
| 56 | + $this->resultPage = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') |
| 57 | + ->disableOriginalConstructor() |
| 58 | + ->getMock(); |
| 59 | + |
| 60 | + $resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') |
| 61 | + ->disableOriginalConstructor() |
| 62 | + ->setMethods(['create']) |
| 63 | + ->getMock(); |
| 64 | + $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage); |
| 65 | + |
| 66 | + $this->resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') |
| 67 | + ->disableOriginalConstructor() |
| 68 | + ->getMock(); |
| 69 | + $resultForwardFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') |
| 70 | + ->disableOriginalConstructor() |
| 71 | + ->setMethods(['create']) |
| 72 | + ->getMock(); |
| 73 | + $resultForwardFactory->expects($this->any()) |
| 74 | + ->method('create') |
| 75 | + ->willReturn($this->resultForward); |
| 76 | + $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->layout); |
| 77 | + $this->resultRedirectFactory = $this->getMock( |
| 78 | + 'Magento\Backend\Model\View\Result\RedirectFactory', |
| 79 | + ['create'], |
| 80 | + [], |
| 81 | + '', |
| 82 | + false |
| 83 | + ); |
| 84 | + $this->resultRedirect = $this->getMock( |
| 85 | + 'Magento\Backend\Model\View\Result\Redirect', |
| 86 | + [], |
| 87 | + [], |
| 88 | + '', |
| 89 | + false |
| 90 | + ); |
| 91 | + $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect); |
| 92 | + |
| 93 | + $this->initializationHelper = $this->getMock( |
| 94 | + 'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper', |
| 95 | + [], |
| 96 | + [], |
| 97 | + '', |
| 98 | + false |
| 99 | + ); |
| 100 | + |
| 101 | + $this->productFactory = $this->getMockBuilder('Magento\Catalog\Model\ProductFactory') |
| 102 | + ->disableOriginalConstructor() |
| 103 | + ->setMethods(['create']) |
| 104 | + ->getMock(); |
| 105 | + $this->productFactory->expects($this->any())->method('create')->willReturn($this->product); |
| 106 | + |
| 107 | + $this->resultJson = $this->getMock('Magento\Framework\Controller\Result\JSON', [], [], '', false); |
| 108 | + $this->resultJsonFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') |
| 109 | + ->disableOriginalConstructor() |
| 110 | + ->setMethods(['create']) |
| 111 | + ->getMock(); |
| 112 | + $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson); |
| 113 | + |
| 114 | + $this->action = (new ObjectManagerHelper($this))->getObject( |
| 115 | + 'Magento\Catalog\Controller\Adminhtml\Product\Validate', |
| 116 | + [ |
| 117 | + 'context' => $this->initContext(), |
| 118 | + 'productBuilder' => $this->productBuilder, |
| 119 | + 'resultPageFactory' => $resultPageFactory, |
| 120 | + 'resultForwardFactory' => $resultForwardFactory, |
| 121 | + 'resultRedirectFactory' => $this->resultRedirectFactory, |
| 122 | + 'initializationHelper' => $this->initializationHelper, |
| 123 | + 'resultJsonFactory' => $this->resultJsonFactory, |
| 124 | + 'productFactory' => $this->productFactory, |
| 125 | + ] |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @return void |
| 131 | + */ |
| 132 | + public function testAttributeSetIsObtainedFromPost() |
| 133 | + { |
| 134 | + $this->request->expects($this->any())->method('getPost')->willReturnMap([['set', null, 9]]); |
| 135 | + |
| 136 | + $this->product->expects($this->once())->method('setAttributeSetId')->with(9); |
| 137 | + |
| 138 | + $this->action->execute(); |
| 139 | + } |
| 140 | +} |
0 commit comments