55 */
66namespace Magento \CatalogWidget \Test \Unit \Model \Rule \Condition ;
77
8+ use Magento \Catalog \Model \ProductCategoryList ;
9+ use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
10+ use Magento \Catalog \Model \ResourceModel \Product ;
11+ use Magento \Catalog \Model \ResourceModel \Product \Collection ;
12+ use Magento \CatalogWidget \Model \Rule \Condition \Product as ProductWidget ;
13+ use Magento \Eav \Model \Config ;
14+ use Magento \Eav \Model \Entity \AbstractEntity ;
15+ use Magento \Framework \DB \Adapter \AdapterInterface ;
16+ use Magento \Framework \DB \Select ;
817use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
18+ use Magento \SalesRule \Model \Rule ;
19+ use Magento \Store \Api \Data \StoreInterface ;
20+ use Magento \Store \Model \StoreManagerInterface ;
21+ use PHPUnit \Framework \MockObject \MockObject ;
22+ use PHPUnit \Framework \TestCase ;
923
1024/**
1125 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1226 */
13- class ProductTest extends \ PHPUnit \ Framework \ TestCase
27+ class ProductTest extends TestCase
1428{
1529 /**
16- * @var \Magento\CatalogWidget\Model\Rule\Condition\Product
30+ * @var ProductWidget
1731 */
1832 private $ model ;
1933
2034 /**
21- * @var \Magento\Catalog\Model\ResourceModel\Product|\PHPUnit_Framework_MockObject_MockObject
35+ * @var MockObject
2236 */
23- private $ productResource ;
37+ private $ attributeMock ;
2438
2539 /**
26- * @var \PHPUnit_Framework_MockObject_MockObject
40+ * @var Product|MockObject
2741 */
28- private $ attributeMock ;
42+ private $ productResource ;
2943
3044 /**
3145 * @inheritdoc
32- *
33- * @return void
3446 */
3547 protected function setUp ()
3648 {
3749 $ objectManagerHelper = new ObjectManager ($ this );
3850
39- $ eavConfig = $ this ->createMock (\ Magento \ Eav \ Model \ Config::class);
40- $ this ->attributeMock = $ this ->createMock (\ Magento \ Catalog \ Model \ ResourceModel \ Eav \ Attribute::class);
51+ $ eavConfig = $ this ->createMock (Config::class);
52+ $ this ->attributeMock = $ this ->createMock (Attribute::class);
4153 $ eavConfig ->expects ($ this ->any ())->method ('getAttribute ' )->willReturn ($ this ->attributeMock );
42- $ ruleMock = $ this ->createMock (\ Magento \ SalesRule \ Model \ Rule::class);
43- $ storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
44- $ storeMock = $ this ->createMock (\ Magento \ Store \ Api \ Data \ StoreInterface::class);
54+ $ ruleMock = $ this ->createMock (Rule::class);
55+ $ storeManager = $ this ->createMock (StoreManagerInterface::class);
56+ $ storeMock = $ this ->createMock (StoreInterface::class);
4557 $ storeManager ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
46- $ this ->productResource = $ this ->createMock (\ Magento \ Catalog \ Model \ ResourceModel \ Product::class);
58+ $ this ->productResource = $ this ->createMock (Product::class);
4759 $ this ->productResource ->expects ($ this ->once ())->method ('loadAllAttributes ' )->willReturnSelf ();
4860 $ this ->productResource ->expects ($ this ->once ())->method ('getAttributesByCode ' )->willReturn ([]);
49- $ productCategoryList = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ProductCategoryList::class)
61+ $ productCategoryList = $ this ->getMockBuilder (ProductCategoryList::class)
5062 ->disableOriginalConstructor ()
5163 ->getMock ();
5264
5365 $ this ->model = $ objectManagerHelper ->getObject (
54- \ Magento \ CatalogWidget \ Model \ Rule \ Condition \Product ::class,
66+ ProductWidget ::class,
5567 [
5668 'config ' => $ eavConfig ,
5769 'storeManager ' => $ storeManager ,
@@ -72,8 +84,8 @@ protected function setUp()
7284 */
7385 public function testAddToCollection ()
7486 {
75- $ collectionMock = $ this ->createMock (\ Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection::class);
76- $ selectMock = $ this ->createMock (\ Magento \ Framework \ DB \ Select::class);
87+ $ collectionMock = $ this ->createMock (Collection::class);
88+ $ selectMock = $ this ->createMock (Select::class);
7789 $ collectionMock ->expects ($ this ->once ())->method ('getSelect ' )->willReturn ($ selectMock );
7890 $ selectMock ->expects ($ this ->any ())->method ('join ' )->willReturnSelf ();
7991 $ this ->attributeMock ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('code ' );
@@ -83,10 +95,10 @@ public function testAddToCollection()
8395 $ this ->attributeMock ->expects ($ this ->once ())->method ('isScopeGlobal ' )->willReturn (true );
8496 $ this ->attributeMock ->expects ($ this ->once ())->method ('getBackendType ' )->willReturn ('multiselect ' );
8597
86- $ entityMock = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ AbstractEntity::class);
98+ $ entityMock = $ this ->createMock (AbstractEntity::class);
8799 $ entityMock ->expects ($ this ->once ())->method ('getLinkField ' )->willReturn ('entitiy_id ' );
88100 $ this ->attributeMock ->expects ($ this ->once ())->method ('getEntity ' )->willReturn ($ entityMock );
89- $ connection = $ this ->createMock (\ Magento \ Framework \ DB \ Adapter \ AdapterInterface::class);
101+ $ connection = $ this ->createMock (AdapterInterface::class);
90102
91103 $ this ->productResource ->expects ($ this ->atLeastOnce ())->method ('getConnection ' )->willReturn ($ connection );
92104
@@ -102,5 +114,7 @@ public function testGetMappedSqlFieldSku()
102114 {
103115 $ this ->model ->setAttribute ('sku ' );
104116 $ this ->assertEquals ('e.sku ' , $ this ->model ->getMappedSqlField ());
117+ $ this ->model ->setAttribute ('attribute_set_id ' );
118+ $ this ->assertEquals ('e.attribute_set_id ' , $ this ->model ->getMappedSqlField ());
105119 }
106120}
0 commit comments