5
5
*/
6
6
namespace Magento \Catalog \Test \Unit \Controller \Adminhtml \Category ;
7
7
8
- use Magento \Catalog \Controller \Adminhtml \Category \Save as Model ;
9
-
10
8
/**
11
9
* Class SaveTest
12
10
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -463,18 +461,35 @@ public function dataProviderExecute()
463
461
*/
464
462
public function imagePreprocessingDataProvider ()
465
463
{
464
+ $ dataWithImage = [
465
+ 'image ' => 'path.jpg ' ,
466
+ 'name ' => 'category ' ,
467
+ 'description ' => '' ,
468
+ 'parent ' => 0
469
+ ];
470
+ $ expectedSameAsDataWithImage = $ dataWithImage ;
471
+
472
+ $ dataWithoutImage = [
473
+ 'name ' => 'category ' ,
474
+ 'description ' => '' ,
475
+ 'parent ' => 0
476
+ ];
477
+ $ expectedIfDataWithoutImage = $ dataWithoutImage ;
478
+ $ expectedIfDataWithoutImage ['image ' ] = '' ;
479
+
466
480
return [
467
- [[ ' attribute1 ' => null , ' attribute2 ' => 123 ] ],
468
- [[ ' attribute2 ' => 123 ]]
481
+ ' categoryPostData contains image ' => [ $ dataWithImage , $ expectedSameAsDataWithImage ],
482
+ ' categoryPostData doesn \' t contain image ' => [ $ dataWithoutImage , $ expectedIfDataWithoutImage ],
469
483
];
470
484
}
471
485
472
486
/**
473
487
* @dataProvider imagePreprocessingDataProvider
474
488
*
475
489
* @param array $data
490
+ * @param array $expected
476
491
*/
477
- public function testImagePreprocessingWithoutValue ($ data )
492
+ public function testImagePreprocessing ($ data, $ expected )
478
493
{
479
494
$ eavConfig = $ this ->createPartialMock (\Magento \Eav \Model \Config::class, ['getEntityType ' ]);
480
495
@@ -484,68 +499,30 @@ public function testImagePreprocessingWithoutValue($data)
484
499
485
500
$ collection = new \Magento \Framework \DataObject (['attribute_collection ' => [
486
501
new \Magento \Framework \DataObject ([
487
- 'attribute_code ' => 'attribute1 ' ,
502
+ 'attribute_code ' => 'image ' ,
488
503
'backend ' => $ imageBackendModel
489
504
]),
490
505
new \Magento \Framework \DataObject ([
491
- 'attribute_code ' => 'attribute2 ' ,
506
+ 'attribute_code ' => 'name ' ,
492
507
'backend ' => new \Magento \Framework \DataObject ()
493
- ])
494
- ]]);
495
-
496
- $ eavConfig ->expects ($ this ->once ())
497
- ->method ('getEntityType ' )
498
- ->with (\Magento \Catalog \Api \Data \CategoryAttributeInterface::ENTITY_TYPE_CODE )
499
- ->will ($ this ->returnValue ($ collection ));
500
-
501
- $ model = $ this ->objectManager ->getObject (\Magento \Catalog \Controller \Adminhtml \Category \Save::class, [
502
- 'eavConfig ' => $ eavConfig
503
- ]);
504
-
505
- $ result = $ model ->imagePreprocessing ($ data );
506
-
507
- $ this ->assertEquals ([
508
- 'attribute1 ' => false ,
509
- 'attribute2 ' => 123
510
- ], $ result );
511
- }
512
-
513
- public function testImagePreprocessingWithValue ()
514
- {
515
- $ eavConfig = $ this ->createPartialMock (\Magento \Eav \Model \Config::class, ['getEntityType ' ]);
516
-
517
- $ imageBackendModel = $ this ->objectManager ->getObject (
518
- \Magento \Catalog \Model \Category \Attribute \Backend \Image::class
519
- );
520
-
521
- $ collection = new \Magento \Framework \DataObject (['attribute_collection ' => [
522
- new \Magento \Framework \DataObject ([
523
- 'attribute_code ' => 'attribute1 ' ,
524
- 'backend ' => $ imageBackendModel
525
508
]),
526
509
new \Magento \Framework \DataObject ([
527
- 'attribute_code ' => 'attribute2 ' ,
510
+ 'attribute_code ' => 'level ' ,
528
511
'backend ' => new \Magento \Framework \DataObject ()
529
- ])
512
+ ]),
530
513
]]);
531
514
532
515
$ eavConfig ->expects ($ this ->once ())
533
516
->method ('getEntityType ' )
534
517
->with (\Magento \Catalog \Api \Data \CategoryAttributeInterface::ENTITY_TYPE_CODE )
535
518
->will ($ this ->returnValue ($ collection ));
536
519
537
- $ model = $ this ->objectManager ->getObject (Model ::class, [
520
+ $ model = $ this ->objectManager ->getObject (\ Magento \ Catalog \ Controller \ Adminhtml \ Category \Save ::class, [
538
521
'eavConfig ' => $ eavConfig
539
522
]);
540
523
541
- $ result = $ model ->imagePreprocessing ([
542
- 'attribute1 ' => 'somevalue ' ,
543
- 'attribute2 ' => null
544
- ]);
524
+ $ result = $ model ->imagePreprocessing ($ data );
545
525
546
- $ this ->assertEquals ([
547
- 'attribute1 ' => 'somevalue ' ,
548
- 'attribute2 ' => null
549
- ], $ result );
526
+ $ this ->assertEquals ($ expected , $ result );
550
527
}
551
528
}
0 commit comments