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 ())->method ('registry ' )->with ('product ' )->will (
44
+ $ this ->returnValue ($ product )
45
+ );
46
+ return $ product ;
47
+ }
48
+
49
+ public function testGetExtendedElement ()
50
+ {
51
+ $ switchAttributeCode = 'test_code ' ;
52
+ $ form = $ this ->getMockBuilder (\Magento \Framework \Data \Form::class)->disableOriginalConstructor ()->getMock ();
53
+ $ and = new \PHPUnit_Framework_Constraint_And ();
54
+ $ and ->setConstraints (
55
+ [
56
+ new \PHPUnit_Framework_Constraint_ArrayHasKey ('value ' )
57
+ ]
58
+ );
59
+ $ form ->expects ($ this ->once ())->method ('addField ' )->with (
60
+ $ switchAttributeCode ,
61
+ 'select ' ,
62
+ $ and
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
+ }
0 commit comments