5
5
*/
6
6
namespace Magento \CatalogWidget \Test \Unit \Model \Rule \Condition ;
7
7
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 ;
8
17
use 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 ;
9
23
10
24
/**
11
25
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
26
*/
13
- class ProductTest extends \ PHPUnit \ Framework \ TestCase
27
+ class ProductTest extends TestCase
14
28
{
15
29
/**
16
- * @var \Magento\CatalogWidget\Model\Rule\Condition\Product
30
+ * @var ProductWidget
17
31
*/
18
32
private $ model ;
19
33
20
34
/**
21
- * @var \Magento\Catalog\Model\ResourceModel\Product|\PHPUnit_Framework_MockObject_MockObject
35
+ * @var MockObject
22
36
*/
23
- private $ productResource ;
37
+ private $ attributeMock ;
24
38
25
39
/**
26
- * @var \PHPUnit_Framework_MockObject_MockObject
40
+ * @var Product|MockObject
27
41
*/
28
- private $ attributeMock ;
42
+ private $ productResource ;
29
43
30
44
/**
31
45
* @inheritdoc
32
- *
33
- * @return void
34
46
*/
35
47
protected function setUp ()
36
48
{
37
49
$ objectManagerHelper = new ObjectManager ($ this );
38
50
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);
41
53
$ 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);
45
57
$ 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);
47
59
$ this ->productResource ->expects ($ this ->once ())->method ('loadAllAttributes ' )->willReturnSelf ();
48
60
$ this ->productResource ->expects ($ this ->once ())->method ('getAttributesByCode ' )->willReturn ([]);
49
- $ productCategoryList = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ProductCategoryList::class)
61
+ $ productCategoryList = $ this ->getMockBuilder (ProductCategoryList::class)
50
62
->disableOriginalConstructor ()
51
63
->getMock ();
52
64
53
65
$ this ->model = $ objectManagerHelper ->getObject (
54
- \ Magento \ CatalogWidget \ Model \ Rule \ Condition \Product ::class,
66
+ ProductWidget ::class,
55
67
[
56
68
'config ' => $ eavConfig ,
57
69
'storeManager ' => $ storeManager ,
@@ -72,8 +84,8 @@ protected function setUp()
72
84
*/
73
85
public function testAddToCollection ()
74
86
{
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);
77
89
$ collectionMock ->expects ($ this ->once ())->method ('getSelect ' )->willReturn ($ selectMock );
78
90
$ selectMock ->expects ($ this ->any ())->method ('join ' )->willReturnSelf ();
79
91
$ this ->attributeMock ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('code ' );
@@ -83,10 +95,10 @@ public function testAddToCollection()
83
95
$ this ->attributeMock ->expects ($ this ->once ())->method ('isScopeGlobal ' )->willReturn (true );
84
96
$ this ->attributeMock ->expects ($ this ->once ())->method ('getBackendType ' )->willReturn ('multiselect ' );
85
97
86
- $ entityMock = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ AbstractEntity::class);
98
+ $ entityMock = $ this ->createMock (AbstractEntity::class);
87
99
$ entityMock ->expects ($ this ->once ())->method ('getLinkField ' )->willReturn ('entitiy_id ' );
88
100
$ 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);
90
102
91
103
$ this ->productResource ->expects ($ this ->atLeastOnce ())->method ('getConnection ' )->willReturn ($ connection );
92
104
@@ -102,5 +114,7 @@ public function testGetMappedSqlFieldSku()
102
114
{
103
115
$ this ->model ->setAttribute ('sku ' );
104
116
$ this ->assertEquals ('e.sku ' , $ this ->model ->getMappedSqlField ());
117
+ $ this ->model ->setAttribute ('attribute_set_id ' );
118
+ $ this ->assertEquals ('e.attribute_set_id ' , $ this ->model ->getMappedSqlField ());
105
119
}
106
120
}
0 commit comments