@@ -53,7 +53,7 @@ protected function setUp()
53
53
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
54
54
55
55
$ this ->connection = $ this ->getMock (
56
- ' Magento\Framework\DB\Adapter\Pdo\Mysql ' ,
56
+ \ Magento \Framework \DB \Adapter \Pdo \Mysql::class ,
57
57
[],
58
58
[],
59
59
'' ,
@@ -63,7 +63,7 @@ protected function setUp()
63
63
->method ('setCacheAdapter ' );
64
64
65
65
$ metadata = $ this ->getMock (
66
- ' Magento\Framework\EntityManager\EntityMetadata ' ,
66
+ \ Magento \Framework \EntityManager \EntityMetadata::class ,
67
67
[],
68
68
[],
69
69
'' ,
@@ -77,29 +77,35 @@ protected function setUp()
77
77
->willReturn ($ this ->connection );
78
78
79
79
$ metadataPool = $ this ->getMock (
80
- ' Magento\Framework\EntityManager\MetadataPool ' ,
80
+ \ Magento \Framework \EntityManager \MetadataPool::class ,
81
81
[],
82
82
[],
83
83
'' ,
84
84
false
85
85
);
86
86
$ metadataPool ->expects ($ this ->once ())
87
87
->method ('getMetadata ' )
88
- ->with (' Magento\Catalog\Api\Data\ProductInterface ' )
88
+ ->with (\ Magento \Catalog \Api \Data \ProductInterface::class )
89
89
->willReturn ($ metadata );
90
90
91
- $ resource = $ this ->getMock (' Magento\Framework\App\ResourceConnection ' , [], [], '' , false );
91
+ $ resource = $ this ->getMock (\ Magento \Framework \App \ResourceConnection::class , [], [], '' , false );
92
92
$ resource ->expects ($ this ->any ())->method ('getTableName ' )->willReturn ('table ' );
93
93
$ this ->resource = $ objectManager ->getObject (
94
- ' Magento\Catalog\Model\ResourceModel\Product\Gallery ' ,
94
+ \ Magento \Catalog \Model \ResourceModel \Product \Gallery::class ,
95
95
[
96
96
'metadataPool ' => $ metadataPool ,
97
97
'resource ' => $ resource
98
98
]
99
99
);
100
- $ this ->product = $ this ->getMock ('Magento\Catalog\Model\Product ' , [], [], '' , false );
101
- $ this ->select = $ this ->getMock ('Magento\Framework\DB\Select ' , [], [], '' , false );
102
- $ this ->attribute = $ this ->getMock ('Magento\Eav\Model\Entity\Attribute\AbstractAttribute ' , [], [], '' , false );
100
+ $ this ->product = $ this ->getMock (\Magento \Catalog \Model \Product::class, [], [], '' , false );
101
+ $ this ->select = $ this ->getMock (\Magento \Framework \DB \Select::class, [], [], '' , false );
102
+ $ this ->attribute = $ this ->getMock (
103
+ \Magento \Eav \Model \Entity \Attribute \AbstractAttribute::class,
104
+ [],
105
+ [],
106
+ '' ,
107
+ false
108
+ );
103
109
}
104
110
105
111
public function testLoadDataFromTableByValueId ()
@@ -437,4 +443,32 @@ public function testDeleteGalleryValueInStore()
437
443
438
444
$ this ->resource ->deleteGalleryValueInStore ($ valueId , $ entityId , $ storeId );
439
445
}
446
+
447
+ public function testCountImageUses ()
448
+ {
449
+ $ results = [
450
+ [
451
+ 'value_id ' => '1 ' ,
452
+ 'attribute_id ' => 90 ,
453
+ 'value ' => '/d/o/download_7.jpg ' ,
454
+ 'media_type ' => 'image ' ,
455
+ 'disabled ' => '0 ' ,
456
+ ],
457
+ ];
458
+
459
+ $ this ->connection ->expects ($ this ->once ())->method ('select ' )->will ($ this ->returnValue ($ this ->select ));
460
+ $ this ->select ->expects ($ this ->at (0 ))
461
+ ->method ('from ' )
462
+ ->with (['main ' => 'table ' ], 'count(*) ' )
463
+ ->willReturnSelf ();
464
+ $ this ->select ->expects ($ this ->at (1 ))
465
+ ->method ('where ' )
466
+ ->with ('value = ? ' , 1 )
467
+ ->willReturnSelf ();
468
+ $ this ->connection ->expects ($ this ->once ())
469
+ ->method ('fetchOne ' )
470
+ ->with ($ this ->select )
471
+ ->willReturn (count ($ results ));
472
+ $ this ->assertEquals ($ this ->resource ->countImageUses (1 ), count ($ results ));
473
+ }
440
474
}
0 commit comments