|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes; |
| 7 | + |
| 8 | +use Magento\Catalog\Model\Product; |
| 9 | + |
| 10 | +class ExtendTest extends \PHPUnit_Framework_TestCase |
| 11 | +{ |
| 12 | + /** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject */ |
| 13 | + protected $registry; |
| 14 | + |
| 15 | + /** @var \Magento\Framework\Data\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ |
| 16 | + protected $formFactory; |
| 17 | + |
| 18 | + /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ |
| 19 | + protected $objectManagerHelper; |
| 20 | + |
| 21 | + /** @var \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend */ |
| 22 | + protected $object; |
| 23 | + |
| 24 | + public function setUp() |
| 25 | + { |
| 26 | + $this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock( |
| 27 | + ); |
| 28 | + $this->formFactory = $this->getMockBuilder('Magento\\Framework\\Data\\FormFactory')->disableOriginalConstructor( |
| 29 | + )->getMock(); |
| 30 | + $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 31 | + $this->object = $this->objectManagerHelper->getObject( |
| 32 | + 'Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Attributes\\Extend', |
| 33 | + ['registry' => $this->registry, 'formFactory' => $this->formFactory] |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @return \PHPUnit_Framework_MockObject_MockObject |
| 39 | + */ |
| 40 | + public function getProduct() |
| 41 | + { |
| 42 | + $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock(); |
| 43 | + $this->registry->expects($this->once()) |
| 44 | + ->method('registry') |
| 45 | + ->with('product') |
| 46 | + ->will( |
| 47 | + $this->returnValue($product) |
| 48 | + ); |
| 49 | + return $product; |
| 50 | + } |
| 51 | + |
| 52 | + public function testGetExtendedElement() |
| 53 | + { |
| 54 | + $switchAttributeCode = 'test_code'; |
| 55 | + $form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock(); |
| 56 | + $and = new \PHPUnit_Framework_Constraint_And(); |
| 57 | + $and->setConstraints( |
| 58 | + [ |
| 59 | + new \PHPUnit_Framework_Constraint_ArrayHasKey('value') |
| 60 | + ] |
| 61 | + ); |
| 62 | + $form->expects($this->once())->method('addField')->with( |
| 63 | + $switchAttributeCode, |
| 64 | + 'select', |
| 65 | + $and |
| 66 | + ); |
| 67 | + |
| 68 | + $this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form)); |
| 69 | + $product = $this->getProduct(); |
| 70 | + $product->expects($this->once())->method('getData')->with($switchAttributeCode)->will( |
| 71 | + $this->returnValue(123) |
| 72 | + ); |
| 73 | + $this->object->setIsDisabledField(true); |
| 74 | + $this->object->getExtendedElement($switchAttributeCode); |
| 75 | + } |
| 76 | +} |
0 commit comments