11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Catalog \Model \Product \Option \Type \DefaultType ;
13
13
use Magento \Framework \DataObject ;
14
+ use Magento \Framework \EntityManager \EntityMetadataInterface ;
15
+ use Magento \Framework \EntityManager \MetadataPool ;
14
16
use Magento \Framework \Exception \LocalizedException ;
15
17
use Magento \Framework \Serialize \Serializer \Json ;
16
18
@@ -38,7 +40,7 @@ class TypeTest extends \PHPUnit_Framework_TestCase
38
40
/**
39
41
* @var \Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
40
42
*/
41
- protected $ bundleCollection ;
43
+ protected $ bundleCollectionFactory ;
42
44
43
45
/**
44
46
* @var \Magento\Catalog\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
@@ -75,6 +77,11 @@ class TypeTest extends \PHPUnit_Framework_TestCase
75
77
*/
76
78
private $ priceCurrency ;
77
79
80
+ /**
81
+ * @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
82
+ */
83
+ private $ metadataPool ;
84
+
78
85
/**
79
86
* @var Json
80
87
*/
@@ -85,7 +92,7 @@ class TypeTest extends \PHPUnit_Framework_TestCase
85
92
*/
86
93
protected function setUp ()
87
94
{
88
- $ this ->bundleCollection =
95
+ $ this ->bundleCollectionFactory =
89
96
$ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Selection \CollectionFactory::class)
90
97
->setMethods (
91
98
[
@@ -148,21 +155,26 @@ protected function setUp()
148
155
->disableOriginalConstructor ()
149
156
->getMock ();
150
157
158
+ $ this ->metadataPool = $ this ->getMockBuilder (MetadataPool::class)
159
+ ->disableOriginalConstructor ()
160
+ ->getMock ();
161
+
151
162
$ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
152
163
$ this ->model = $ objectHelper ->getObject (
153
164
\Magento \Bundle \Model \Product \Type::class,
154
165
[
155
166
'bundleModelSelection ' => $ this ->bundleModelSelection ,
156
167
'bundleFactory ' => $ this ->bundleFactory ,
157
- 'bundleCollection ' => $ this ->bundleCollection ,
168
+ 'bundleCollection ' => $ this ->bundleCollectionFactory ,
158
169
'bundleOption ' => $ this ->bundleOptionFactory ,
159
170
'catalogData ' => $ this ->catalogData ,
160
171
'storeManager ' => $ this ->storeManager ,
161
172
'stockRegistry ' => $ this ->stockRegistry ,
162
173
'stockState ' => $ this ->stockState ,
163
174
'catalogProduct ' => $ this ->catalogProduct ,
164
175
'priceCurrency ' => $ this ->priceCurrency ,
165
- 'serializer ' => $ this ->serializer
176
+ 'serializer ' => $ this ->serializer ,
177
+ 'metadataPool ' => $ this ->metadataPool ,
166
178
]
167
179
);
168
180
}
@@ -1935,6 +1947,7 @@ public function testGetSelectionsByIds()
1935
1947
$ storeId = 2 ;
1936
1948
$ websiteId = 1 ;
1937
1949
$ storeFilter = 'store_filter ' ;
1950
+ $ this ->expectProductEntityMetadata ();
1938
1951
$ productMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
1939
1952
->disableOriginalConstructor ()
1940
1953
->getMock ();
@@ -1984,7 +1997,7 @@ public function testGetSelectionsByIds()
1984
1997
->method ('getWebsiteId ' )
1985
1998
->will ($ this ->returnValue ($ websiteId ));
1986
1999
1987
- $ this ->bundleCollection ->expects ($ this ->once ())
2000
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())
1988
2001
->method ('create ' )
1989
2002
->will ($ this ->returnValue ($ usedSelectionsMock ));
1990
2003
@@ -2155,9 +2168,11 @@ public function testIsSalableWithRequiredOptionsTrue()
2155
2168
$ option3 ->method ('getId ' )
2156
2169
->willReturn (30 );
2157
2170
2171
+ $ this ->expectProductEntityMetadata ();
2172
+
2158
2173
$ optionCollectionMock = $ this ->getOptionCollectionMock ([$ option1 , $ option2 , $ option3 ]);
2159
2174
$ selectionCollectionMock = $ this ->getSelectionCollectionMock ([$ option1 , $ option2 ]);
2160
- $ this ->bundleCollection ->expects ($ this ->atLeastOnce ())
2175
+ $ this ->bundleCollectionFactory ->expects ($ this ->atLeastOnce ())
2161
2176
->method ('create ' )
2162
2177
->will ($ this ->returnValue ($ selectionCollectionMock ));
2163
2178
@@ -2196,8 +2211,9 @@ public function testIsSalableWithEmptySelectionsCollection()
2196
2211
$ option = $ this ->getRequiredOptionMock (1 , 10 );
2197
2212
$ optionCollectionMock = $ this ->getOptionCollectionMock ([$ option ]);
2198
2213
$ selectionCollectionMock = $ this ->getSelectionCollectionMock ([]);
2214
+ $ this ->expectProductEntityMetadata ();
2199
2215
2200
- $ this ->bundleCollection ->expects ($ this ->once ())
2216
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())
2201
2217
->method ('create ' )
2202
2218
->will ($ this ->returnValue ($ selectionCollectionMock ));
2203
2219
@@ -2220,6 +2236,7 @@ public function testIsSalableWithNonSalableRequiredOptions()
2220
2236
$ option1 = $ this ->getRequiredOptionMock (10 , 10 );
2221
2237
$ option2 = $ this ->getRequiredOptionMock (20 , 10 );
2222
2238
$ optionCollectionMock = $ this ->getOptionCollectionMock ([$ option1 , $ option2 ]);
2239
+ $ this ->expectProductEntityMetadata ();
2223
2240
2224
2241
$ selection1 = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
2225
2242
->setMethods (['isSalable ' ])
@@ -2242,7 +2259,7 @@ public function testIsSalableWithNonSalableRequiredOptions()
2242
2259
$ selectionCollectionMock1 = $ this ->getSelectionCollectionMock ([$ selection1 ]);
2243
2260
$ selectionCollectionMock2 = $ this ->getSelectionCollectionMock ([$ selection2 ]);
2244
2261
2245
- $ this ->bundleCollection ->expects ($ this ->exactly (2 ))
2262
+ $ this ->bundleCollectionFactory ->expects ($ this ->exactly (2 ))
2246
2263
->method ('create ' )
2247
2264
->will ($ this ->onConsecutiveCalls (
2248
2265
$ selectionCollectionMock1 ,
@@ -2438,14 +2455,15 @@ public function testGetSelectionsCollection()
2438
2455
]
2439
2456
)
2440
2457
->getMock ();
2458
+ $ this ->expectProductEntityMetadata ();
2441
2459
$ store = $ this ->getMockBuilder (\Magento \Store \Model \Store::class)
2442
2460
->disableOriginalConstructor ()
2443
2461
->setMethods (['getWebsiteId ' ])
2444
2462
->getMock ();
2445
2463
2446
2464
$ product ->expects ($ this ->once ())->method ('getStoreId ' )->willReturn ('store_id ' );
2447
2465
$ selectionCollection = $ this ->getSelectionCollection ();
2448
- $ this ->bundleCollection ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2466
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2449
2467
$ this ->storeManager ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ store );
2450
2468
$ store ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn ('website_id ' );
2451
2469
$ selectionCollection ->expects ($ this ->any ())->method ('joinPrices ' )->with ('website_id ' )->willReturnSelf ();
@@ -2496,6 +2514,7 @@ public function testGetProductsToPurchaseByReqGroups()
2496
2514
$ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
2497
2515
->disableOriginalConstructor ()
2498
2516
->getMock ();
2517
+ $ this ->expectProductEntityMetadata ();
2499
2518
$ resourceClassName = \Magento \Framework \Model \ResourceModel \Db \Collection \AbstractCollection::class;
2500
2519
$ dbResourceMock = $ this ->getMockBuilder ($ resourceClassName )
2501
2520
->setMethods (['getItems ' ])
@@ -2506,7 +2525,7 @@ public function testGetProductsToPurchaseByReqGroups()
2506
2525
->setMethods (['getId ' , 'getRequired ' ])
2507
2526
->getMock ();
2508
2527
$ selectionCollection = $ this ->getSelectionCollection ();
2509
- $ this ->bundleCollection ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2528
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2510
2529
2511
2530
$ selectionItem = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
2512
2531
->disableOriginalConstructor ()
@@ -2554,6 +2573,7 @@ public function testHasOptions()
2554
2573
->disableOriginalConstructor ()
2555
2574
->setMethods (['_wakeup ' , 'hasData ' , 'getData ' , 'setData ' , 'getId ' , 'getStoreId ' ])
2556
2575
->getMock ();
2576
+ $ this ->expectProductEntityMetadata ();
2557
2577
$ optionCollection = $ this ->getMockBuilder (\Magento \Bundle \Model \ResourceModel \Option \Collection::class)
2558
2578
->disableOriginalConstructor ()
2559
2579
->setMethods (['getAllIds ' ])
@@ -2563,7 +2583,7 @@ public function testHasOptions()
2563
2583
->expects ($ this ->any ())
2564
2584
->method ('getSize ' )
2565
2585
->willReturn (1 );
2566
- $ this ->bundleCollection ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2586
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ selectionCollection );
2567
2587
2568
2588
$ product ->expects ($ this ->any ())->method ('getStoreId ' )->willReturn (0 );
2569
2589
$ product ->expects ($ this ->once ())
@@ -2590,6 +2610,7 @@ public function testCheckProductBuyStateEmptyOptionsException()
2590
2610
{
2591
2611
$ this ->mockBundleCollection ();
2592
2612
$ product = $ this ->getProductMock ();
2613
+ $ this ->expectProductEntityMetadata ();
2593
2614
$ product ->method ('getCustomOption ' )->willReturnMap ([
2594
2615
['bundle_selection_ids ' , new DataObject (['value ' => '[] ' ])],
2595
2616
['info_buyRequest ' , new DataObject (['value ' => json_encode (['bundle_option ' => '' ])])],
@@ -2615,13 +2636,14 @@ public function testCheckProductBuyStateMissedOptionException($element, $expecte
2615
2636
{
2616
2637
$ this ->mockBundleCollection ();
2617
2638
$ product = $ this ->getProductMock ();
2639
+ $ this ->expectProductEntityMetadata ();
2618
2640
$ product ->method ('getCustomOption ' )->willReturnMap ([
2619
2641
['bundle_selection_ids ' , new DataObject (['value ' => json_encode ([1 ])])],
2620
2642
['info_buyRequest ' , new DataObject (['value ' => json_encode (['bundle_option ' => [1 ]])])],
2621
2643
]);
2622
2644
$ product ->setCustomOption (json_encode ([]));
2623
2645
2624
- $ this ->bundleCollection ->method ('getItemById ' )->willReturn ($ element );
2646
+ $ this ->bundleCollectionFactory ->method ('getItemById ' )->willReturn ($ element );
2625
2647
$ this ->catalogProduct ->setSkipSaleableCheck ($ check );
2626
2648
2627
2649
try {
@@ -2644,6 +2666,7 @@ public function testCheckProductBuyStateRequiredOptionException()
2644
2666
{
2645
2667
$ this ->mockBundleCollection ();
2646
2668
$ product = $ this ->getProductMock ();
2669
+ $ this ->expectProductEntityMetadata ();
2647
2670
$ product ->method ('getCustomOption ' )->willReturnMap ([
2648
2671
['bundle_selection_ids ' , new DataObject (['value ' => json_encode ([])])],
2649
2672
['info_buyRequest ' , new DataObject (['value ' => json_encode (['bundle_option ' => [1 ]])])],
@@ -2656,7 +2679,7 @@ public function testCheckProductBuyStateRequiredOptionException()
2656
2679
->getMock ();
2657
2680
$ falseSelection ->method ('isSalable ' )->willReturn (false );
2658
2681
2659
- $ this ->bundleCollection ->method ('getItemById ' )->willReturn ($ falseSelection );
2682
+ $ this ->bundleCollectionFactory ->method ('getItemById ' )->willReturn ($ falseSelection );
2660
2683
$ this ->catalogProduct ->setSkipSaleableCheck (false );
2661
2684
2662
2685
try {
@@ -2709,14 +2732,18 @@ public function getProductMock()
2709
2732
*/
2710
2733
public function mockBundleCollection ()
2711
2734
{
2712
- $ this ->bundleCollection ->method ('create ' )->willReturn ($ this ->bundleCollection );
2713
- $ this ->bundleCollection ->method ('addAttributeToSelect ' )->willReturn ($ this ->bundleCollection );
2714
- $ this ->bundleCollection ->method ('setFlag ' )->willReturn ($ this ->bundleCollection );
2715
- $ this ->bundleCollection ->method ('setPositionOrder ' )->willReturn ($ this ->bundleCollection );
2716
- $ this ->bundleCollection ->method ('addStoreFilter ' )->willReturn ($ this ->bundleCollection );
2717
- $ this ->bundleCollection ->method ('setStoreId ' )->willReturn ($ this ->bundleCollection );
2718
- $ this ->bundleCollection ->method ('addFilterByRequiredOptions ' )->willReturn ($ this ->bundleCollection );
2719
- $ this ->bundleCollection ->method ('setOptionIdsFilter ' )->willReturn ($ this ->bundleCollection );
2735
+ $ selectionCollectionMock = $ this ->getSelectionCollectionMock ([]);
2736
+ $ this ->bundleCollectionFactory ->expects ($ this ->once ())
2737
+ ->method ('create ' )
2738
+ ->will ($ this ->returnValue ($ selectionCollectionMock ));
2739
+ $ this ->bundleCollectionFactory ->method ('create ' )->willReturn ($ selectionCollectionMock );
2740
+ $ selectionCollectionMock ->method ('addAttributeToSelect ' )->willReturn ($ selectionCollectionMock );
2741
+ $ selectionCollectionMock ->method ('setFlag ' )->willReturn ($ selectionCollectionMock );
2742
+ $ selectionCollectionMock ->method ('setPositionOrder ' )->willReturn ($ selectionCollectionMock );
2743
+ $ selectionCollectionMock ->method ('addStoreFilter ' )->willReturn ($ selectionCollectionMock );
2744
+ $ selectionCollectionMock ->method ('setStoreId ' )->willReturn ($ selectionCollectionMock );
2745
+ $ selectionCollectionMock ->method ('addFilterByRequiredOptions ' )->willReturn ($ selectionCollectionMock );
2746
+ $ selectionCollectionMock ->method ('setOptionIdsFilter ' )->willReturn ($ selectionCollectionMock );
2720
2747
}
2721
2748
2722
2749
/**
@@ -2743,4 +2770,16 @@ public function notAvailableOptionProvider()
2743
2770
],
2744
2771
];
2745
2772
}
2773
+
2774
+ /**
2775
+ * @return void
2776
+ */
2777
+ private function expectProductEntityMetadata ()
2778
+ {
2779
+ $ entityMetadataMock = $ this ->getMockBuilder (EntityMetadataInterface::class)
2780
+ ->getMockForAbstractClass ();
2781
+ $ this ->metadataPool ->expects ($ this ->any ())->method ('getMetadata ' )
2782
+ ->with (\Magento \Catalog \Api \Data \ProductInterface::class)
2783
+ ->willReturn ($ entityMetadataMock );
2784
+ }
2746
2785
}
0 commit comments