@@ -61,21 +61,21 @@ class MediaTest extends \PHPUnit_Framework_TestCase
61
61
public function setUp ()
62
62
{
63
63
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
64
- $ this ->connection = $ this ->getMock (' Magento\Framework\DB\Adapter\Pdo\Mysql ' , [], [], '' , false );
65
- $ resource = $ this ->getMock (' Magento\Framework\App\ResourceConnection ' , [], [], '' , false );
64
+ $ this ->connection = $ this ->getMock (\ Magento \Framework \DB \Adapter \Pdo \Mysql::class , [], [], '' , false );
65
+ $ resource = $ this ->getMock (\ Magento \Framework \App \ResourceConnection::class , [], [], '' , false );
66
66
$ resource ->expects ($ this ->any ())
67
67
->method ('getConnection ' )
68
68
->willReturn ($ this ->connection );
69
69
$ resource ->expects ($ this ->any ())->method ('getTableName ' )->willReturn ('table ' );
70
70
$ this ->connection ->expects ($ this ->any ())->method ('setCacheAdapter ' );
71
71
$ this ->resource = $ objectManager ->getObject (
72
- ' Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media ' ,
72
+ \ Magento \Catalog \Model \ResourceModel \Product \Attribute \Backend \Media::class ,
73
73
['resource ' => $ resource ]
74
74
);
75
- $ this ->product = $ this ->getMock (' Magento\Catalog\Model\Product ' , [], [], '' , false );
76
- $ this ->model = $ this ->getMock (' Magento\Catalog\Model\Product\Attribute\Backend\Media ' , [], [], '' , false );
77
- $ this ->select = $ this ->getMock (' Magento\Framework\DB\Select ' , [], [], '' , false );
78
- $ this ->attribute = $ this ->getMock (' Magento\Eav\Model\Entity\Attribute\AbstractAttribute ' , [], [], '' , false );
75
+ $ this ->product = $ this ->getMock (\ Magento \Catalog \Model \Product::class , [], [], '' , false );
76
+ $ this ->model = $ this ->getMock (\ Magento \Catalog \Model \Product \Attribute \Backend \Media::class , [], [], '' , false );
77
+ $ this ->select = $ this ->getMock (\ Magento \Framework \DB \Select::class , [], [], '' , false );
78
+ $ this ->attribute = $ this ->getMock (\ Magento \Eav \Model \Entity \Attribute \AbstractAttribute::class , [], [], '' , false );
79
79
}
80
80
81
81
public function testLoadDataFromTableByValueId ()
@@ -412,4 +412,33 @@ public function testDeleteGalleryValueInStore()
412
412
413
413
$ this ->resource ->deleteGalleryValueInStore ($ valueId , $ entityId , $ storeId );
414
414
}
415
+
416
+
417
+ public function testCountImageUses ()
418
+ {
419
+ $ results = [
420
+ [
421
+ 'value_id ' => '1 ' ,
422
+ 'attribute_id ' => 90 ,
423
+ 'value ' => '/d/o/download_7.jpg ' ,
424
+ 'media_type ' => 'image ' ,
425
+ 'disabled ' => '0 ' ,
426
+ ],
427
+ ];
428
+
429
+ $ this ->connection ->expects ($ this ->once ())->method ('select ' )->will ($ this ->returnValue ($ this ->select ));
430
+ $ this ->select ->expects ($ this ->at (0 ))
431
+ ->method ('from ' )
432
+ ->with (['main ' => 'table ' ], 'count(*) ' )
433
+ ->willReturnSelf ();
434
+ $ this ->select ->expects ($ this ->at (1 ))
435
+ ->method ('where ' )
436
+ ->with ('value = ? ' , 1 )
437
+ ->willReturnSelf ();
438
+ $ this ->connection ->expects ($ this ->once ())
439
+ ->method ('fetchOne ' )
440
+ ->with ($ this ->select )
441
+ ->willReturn (count ($ results ));
442
+ $ this ->assertEquals ($ this ->resource ->countImageUses (1 ), count ($ results ));
443
+ }
415
444
}
0 commit comments