9
9
namespace Magento \Catalog \Test \Unit \Model ;
10
10
11
11
use Magento \Catalog \Model \Indexer ;
12
+ use Magento \Catalog \Model \Category as Model ;
12
13
13
14
/**
14
15
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -89,9 +90,16 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
89
90
*/
90
91
protected $ attributeValueFactory ;
91
92
93
+ /**
94
+ * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
95
+ */
96
+ protected $ objectManager ;
97
+
92
98
protected function setUp ()
93
99
{
94
- $ this ->context = $ this ->getMock (
100
+ $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
101
+
102
+ $ this ->context = $ this ->getMock (
95
103
\Magento \Framework \Model \Context::class,
96
104
['getEventDispatcher ' , 'getCacheManager ' ],
97
105
[],
@@ -108,37 +116,37 @@ protected function setUp()
108
116
109
117
$ this ->registry = $ this ->getMock (\Magento \Framework \Registry::class);
110
118
$ this ->storeManager = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class);
111
- $ this ->categoryTreeResource = $ this ->getMock (
112
- \Magento \Catalog \Model \ResourceModel \Category \Tree::class,
113
- [],
114
- [],
115
- '' ,
116
- false
119
+ $ this ->categoryTreeResource = $ this ->getMock (
120
+ \Magento \Catalog \Model \ResourceModel \Category \Tree::class,
121
+ [],
122
+ [],
123
+ '' ,
124
+ false
117
125
);
118
- $ this ->categoryTreeFactory = $ this ->getMock (
126
+ $ this ->categoryTreeFactory = $ this ->getMock (
119
127
\Magento \Catalog \Model \ResourceModel \Category \TreeFactory::class,
120
128
['create ' ],
121
129
[],
122
130
'' ,
123
131
false );
124
132
$ this ->categoryRepository = $ this ->getMock (\Magento \Catalog \Api \CategoryRepositoryInterface::class);
125
- $ this ->storeCollectionFactory = $ this ->getMock (
133
+ $ this ->storeCollectionFactory = $ this ->getMock (
126
134
\Magento \Store \Model \ResourceModel \Store \CollectionFactory::class,
127
135
['create ' ],
128
136
[],
129
137
'' ,
130
138
false
131
139
);
132
140
$ this ->url = $ this ->getMock (\Magento \Framework \UrlInterface::class);
133
- $ this ->productCollectionFactory = $ this ->getMock (
141
+ $ this ->productCollectionFactory = $ this ->getMock (
134
142
\Magento \Catalog \Model \ResourceModel \Product \CollectionFactory::class,
135
143
['create ' ],
136
144
[],
137
145
'' ,
138
146
false
139
147
);
140
148
$ this ->catalogConfig = $ this ->getMock (\Magento \Catalog \Model \Config::class, [], [], '' , false );
141
- $ this ->filterManager = $ this ->getMock (
149
+ $ this ->filterManager = $ this ->getMock (
142
150
\Magento \Framework \Filter \FilterManager::class,
143
151
['translitUrl ' ],
144
152
[],
@@ -148,27 +156,27 @@ protected function setUp()
148
156
$ this ->flatState = $ this ->getMock (\Magento \Catalog \Model \Indexer \Category \Flat \State::class, [], [], '' , false );
149
157
$ this ->flatIndexer = $ this ->getMock (\Magento \Framework \Indexer \IndexerInterface::class);
150
158
$ this ->productIndexer = $ this ->getMock (\Magento \Framework \Indexer \IndexerInterface::class);
151
- $ this ->categoryUrlPathGenerator = $ this ->getMock (
159
+ $ this ->categoryUrlPathGenerator = $ this ->getMock (
152
160
\Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator::class,
153
161
[],
154
162
[],
155
163
'' ,
156
164
false
157
165
);
158
166
$ this ->urlFinder = $ this ->getMock (\Magento \UrlRewrite \Model \UrlFinderInterface::class);
159
- $ this ->resource = $ this ->getMock (
167
+ $ this ->resource = $ this ->getMock (
160
168
\Magento \Catalog \Model \ResourceModel \Category::class,
161
169
[],
162
170
[],
163
171
'' ,
164
172
false
165
173
);
166
- $ this ->indexerRegistry = $ this ->getMock (
167
- \Magento \Framework \Indexer \IndexerRegistry::class,
168
- ['get ' ],
169
- [],
170
- '' ,
171
- false
174
+ $ this ->indexerRegistry = $ this ->getMock (
175
+ \Magento \Framework \Indexer \IndexerRegistry::class,
176
+ ['get ' ],
177
+ [],
178
+ '' ,
179
+ false
172
180
);
173
181
174
182
$ this ->metadataServiceMock = $ this ->getMock (\Magento \Catalog \Api \CategoryAttributeRepositoryInterface::class);
@@ -198,7 +206,7 @@ public function testFormatUrlKey()
198
206
public function testMoveWhenCannotFindParentCategory ()
199
207
{
200
208
$ this ->markTestIncomplete ('MAGETWO-31165 ' );
201
- $ parentCategory = $ this ->getMock (
209
+ $ parentCategory = $ this ->getMock (
202
210
\Magento \Catalog \Model \Category::class,
203
211
['getId ' , 'setStoreId ' , 'load ' ],
204
212
[],
@@ -223,7 +231,7 @@ public function testMoveWhenCannotFindParentCategory()
223
231
*/
224
232
public function testMoveWhenCannotFindNewCategory ()
225
233
{
226
- $ parentCategory = $ this ->getMock (
234
+ $ parentCategory = $ this ->getMock (
227
235
\Magento \Catalog \Model \Category::class,
228
236
['getId ' , 'setStoreId ' , 'load ' ],
229
237
[],
@@ -250,7 +258,7 @@ public function testMoveWhenCannotFindNewCategory()
250
258
public function testMoveWhenParentCategoryIsSameAsChildCategory ()
251
259
{
252
260
$ this ->markTestIncomplete ('MAGETWO-31165 ' );
253
- $ parentCategory = $ this ->getMock (
261
+ $ parentCategory = $ this ->getMock (
254
262
\Magento \Catalog \Model \Category::class,
255
263
['getId ' , 'setStoreId ' , 'load ' ],
256
264
[],
@@ -277,7 +285,7 @@ public function testMovePrimaryWorkflow()
277
285
->method ('get ' )
278
286
->with ('catalog_category_product ' )
279
287
->will ($ this ->returnValue ($ indexer ));
280
- $ parentCategory = $ this ->getMock (
288
+ $ parentCategory = $ this ->getMock (
281
289
\Magento \Catalog \Model \Category::class,
282
290
['getId ' , 'setStoreId ' , 'load ' ],
283
291
[],
@@ -313,7 +321,7 @@ public function testGetUseFlatResourceTrue()
313
321
314
322
protected function getCategoryModel ()
315
323
{
316
- return ( new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ( $ this )) ->getObject (
324
+ return $ this -> objectManager ->getObject (
317
325
\Magento \Catalog \Model \Category::class,
318
326
[
319
327
'context ' => $ this ->context ,
@@ -487,4 +495,68 @@ public function testGetCustomAttributes()
487
495
$ this ->category ->getCustomAttribute ($ descriptionAttributeCode )->getValue ()
488
496
);
489
497
}
498
+
499
+ public function imageAttributeNameAndUrlProvider ()
500
+ {
501
+ return [
502
+ ['testimage ' , 'http://www.test123.com/catalog/category/testimage ' ],
503
+ [false , false ]
504
+ ];
505
+ }
506
+
507
+ /**
508
+ * @param $value
509
+ * @param $url
510
+ *
511
+ * @dataProvider imageAttributeNameAndUrlProvider
512
+ */
513
+ public function testGetImageUrlShouldGenerateMediaUrlForSpecifiedAttributeValue ($ value , $ url )
514
+ {
515
+ $ storeManager = $ this ->getMock (\Magento \Store \Model \StoreManager::class, ['getStore ' ], [], '' , false );
516
+ $ store = $ this ->getMock (\Magento \Store \Model \Store::class, ['getBaseUrl ' ], [], '' , false );
517
+
518
+ $ storeManager ->expects ($ this ->any ())
519
+ ->method ('getStore ' )
520
+ ->will ($ this ->returnValue ($ store ));
521
+
522
+ $ store ->expects ($ this ->any ())
523
+ ->method ('getBaseUrl ' )
524
+ ->with (\Magento \Framework \UrlInterface::URL_TYPE_MEDIA )
525
+ ->will ($ this ->returnValue ('http://www.test123.com/ ' ));
526
+
527
+ $ model = $ this ->objectManager ->getObject (Model::class, [
528
+ 'storeManager ' => $ storeManager
529
+ ]);
530
+
531
+ $ model ->setData ('attribute1 ' , $ value );
532
+
533
+ $ result = $ model ->getImageUrl ('attribute1 ' );
534
+
535
+ $ this ->assertEquals ($ url , $ result );
536
+ }
537
+
538
+ public function testGetImageUrlShouldGenerateMediaUrlForImageAttributeValue ()
539
+ {
540
+ $ storeManager = $ this ->getMock (\Magento \Store \Model \StoreManager::class, ['getStore ' ], [], '' , false );
541
+ $ store = $ this ->getMock (\Magento \Store \Model \Store::class, ['getBaseUrl ' ], [], '' , false );
542
+
543
+ $ storeManager ->expects ($ this ->any ())
544
+ ->method ('getStore ' )
545
+ ->will ($ this ->returnValue ($ store ));
546
+
547
+ $ store ->expects ($ this ->any ())
548
+ ->method ('getBaseUrl ' )
549
+ ->with (\Magento \Framework \UrlInterface::URL_TYPE_MEDIA )
550
+ ->will ($ this ->returnValue ('http://www.test123.com/ ' ));
551
+
552
+ $ model = $ this ->objectManager ->getObject (Model::class, [
553
+ 'storeManager ' => $ storeManager
554
+ ]);
555
+
556
+ $ model ->setData ('image ' , 'myimage ' );
557
+
558
+ $ result = $ model ->getImageUrl ();
559
+
560
+ $ this ->assertEquals ('http://www.test123.com/catalog/category/myimage ' , $ result );
561
+ }
490
562
}
0 commit comments