Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExtendTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ExtendTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $registry;
14 
16  protected $formFactory;
17 
20 
22  protected $object;
23 
24  protected function setUp()
25  {
26  $this->registry = $this->getMockBuilder(\Magento\Framework\Registry::class)
27  ->disableOriginalConstructor()
28  ->getMock();
29  $this->formFactory = $this->getMockBuilder(
30  \Magento\Framework\Data\FormFactory::class
31  )->disableOriginalConstructor()->getMock();
32  $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33  $this->object = $this->objectManagerHelper->getObject(
34  \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend::class,
35  ['registry' => $this->registry, 'formFactory' => $this->formFactory]
36  );
37  }
38 
42  public function getProduct()
43  {
44  $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock();
45  $this->registry->expects($this->once())
46  ->method('registry')
47  ->with('product')
48  ->will(
49  $this->returnValue($product)
50  );
51  return $product;
52  }
53 
54  public function testGetExtendedElement()
55  {
56  $switchAttributeCode = 'test_code';
57  $form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock();
58  $hasKey = new \PHPUnit\Framework\Constraint\ArrayHasKey('value');
59  $form->expects($this->once())->method('addField')->with(
61  'select',
62  $hasKey
63  );
64 
65  $this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form));
66  $product = $this->getProduct();
67  $product->expects($this->once())->method('getData')->with($switchAttributeCode)->will(
68  $this->returnValue(123)
69  );
70  $this->object->setIsDisabledField(true);
71  $this->object->getExtendedElement($switchAttributeCode);
72  }
73 }
$switchAttributeCode
Definition: extend.phtml:15