@@ -136,18 +136,22 @@ public function testExecute()
136
136
$ serializedOptions = '{"key":"value"} ' ;
137
137
$ this ->requestMock ->expects ($ this ->any ())
138
138
->method ('getParam ' )
139
- ->willReturnMap ([
139
+ ->willReturnMap (
140
+ [
140
141
['frontend_label ' , null , 'test_frontend_label ' ],
141
142
['attribute_code ' , null , 'test_attribute_code ' ],
142
143
['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
143
144
['serialized_options ' , '[] ' , $ serializedOptions ],
144
- ]);
145
+ ]
146
+ );
145
147
$ this ->objectManagerMock ->expects ($ this ->exactly (2 ))
146
148
->method ('create ' )
147
- ->willReturnMap ([
149
+ ->willReturnMap (
150
+ [
148
151
[\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class, [], $ this ->attributeMock ],
149
152
[\Magento \Eav \Model \Entity \Attribute \Set::class, [], $ this ->attributeSetMock ]
150
- ]);
153
+ ]
154
+ );
151
155
$ this ->attributeMock ->expects ($ this ->once ())
152
156
->method ('loadByCode ' )
153
157
->willReturnSelf ();
@@ -182,23 +186,25 @@ public function testExecute()
182
186
183
187
/**
184
188
* @dataProvider provideUniqueData
185
- * @param array $options
186
- * @param boolean $isError
187
- * @throws \Magento\Framework\Exception\NotFoundException
189
+ * @param array $options
190
+ * @param boolean $isError
191
+ * @throws \Magento\Framework\Exception\NotFoundException
188
192
*/
189
193
public function testUniqueValidation (array $ options , $ isError )
190
194
{
191
195
$ serializedOptions = '{"key":"value"} ' ;
192
196
$ countFunctionCalls = ($ isError ) ? 6 : 5 ;
193
197
$ this ->requestMock ->expects ($ this ->exactly ($ countFunctionCalls ))
194
198
->method ('getParam ' )
195
- ->willReturnMap ([
199
+ ->willReturnMap (
200
+ [
196
201
['frontend_label ' , null , null ],
197
202
['attribute_code ' , null , "test_attribute_code " ],
198
203
['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
199
204
['message_key ' , null , Validate::DEFAULT_MESSAGE_KEY ],
200
205
['serialized_options ' , '[] ' , $ serializedOptions ],
201
- ]);
206
+ ]
207
+ );
202
208
203
209
$ this ->formDataSerializerMock
204
210
->expects ($ this ->once ())
@@ -323,22 +329,24 @@ public function provideUniqueData()
323
329
* Check that empty admin scope labels will trigger error.
324
330
*
325
331
* @dataProvider provideEmptyOption
326
- * @param array $options
327
- * @throws \Magento\Framework\Exception\NotFoundException
332
+ * @param array $options
333
+ * @throws \Magento\Framework\Exception\NotFoundException
328
334
*/
329
335
public function testEmptyOption (array $ options , $ result )
330
336
{
331
337
$ serializedOptions = '{"key":"value"} ' ;
332
338
$ this ->requestMock ->expects ($ this ->any ())
333
339
->method ('getParam ' )
334
- ->willReturnMap ([
340
+ ->willReturnMap (
341
+ [
335
342
['frontend_label ' , null , null ],
336
343
['frontend_input ' , 'select ' , 'multipleselect ' ],
337
344
['attribute_code ' , null , "test_attribute_code " ],
338
345
['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
339
346
['message_key ' , Validate::DEFAULT_MESSAGE_KEY , 'message ' ],
340
347
['serialized_options ' , '[] ' , $ serializedOptions ],
341
- ]);
348
+ ]
349
+ );
342
350
343
351
$ this ->formDataSerializerMock
344
352
->expects ($ this ->once ())
@@ -439,6 +447,129 @@ public function provideEmptyOption()
439
447
];
440
448
}
441
449
450
+ /**
451
+ * Check that admin scope labels which only contain spaces will trigger error.
452
+ *
453
+ * @dataProvider provideWhitespaceOption
454
+ * @param array $options
455
+ * @param $result
456
+ * @throws \Magento\Framework\Exception\NotFoundException
457
+ */
458
+ public function testWhitespaceOption (array $ options , $ result )
459
+ {
460
+ $ serializedOptions = '{"key":"value"} ' ;
461
+ $ this ->requestMock ->expects ($ this ->any ())
462
+ ->method ('getParam ' )
463
+ ->willReturnMap (
464
+ [
465
+ ['frontend_label ' , null , null ],
466
+ ['frontend_input ' , 'select ' , 'multipleselect ' ],
467
+ ['attribute_code ' , null , "test_attribute_code " ],
468
+ ['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
469
+ ['message_key ' , Validate::DEFAULT_MESSAGE_KEY , 'message ' ],
470
+ ['serialized_options ' , '[] ' , $ serializedOptions ],
471
+ ]
472
+ );
473
+
474
+ $ this ->formDataSerializerMock
475
+ ->expects ($ this ->once ())
476
+ ->method ('unserialize ' )
477
+ ->with ($ serializedOptions )
478
+ ->willReturn ($ options );
479
+
480
+ $ this ->objectManagerMock ->expects ($ this ->once ())
481
+ ->method ('create ' )
482
+ ->willReturn ($ this ->attributeMock );
483
+
484
+ $ this ->attributeMock ->expects ($ this ->once ())
485
+ ->method ('loadByCode ' )
486
+ ->willReturnSelf ();
487
+
488
+ $ this ->attributeCodeValidatorMock ->expects ($ this ->once ())
489
+ ->method ('isValid ' )
490
+ ->with ('test_attribute_code ' )
491
+ ->willReturn (true );
492
+
493
+ $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
494
+ ->method ('create ' )
495
+ ->willReturn ($ this ->resultJson );
496
+
497
+ $ this ->resultJson ->expects ($ this ->once ())
498
+ ->method ('setJsonData ' )
499
+ ->willReturnArgument (0 );
500
+
501
+ $ response = $ this ->getModel ()->execute ();
502
+ $ responseObject = json_decode ($ response );
503
+ $ this ->assertEquals ($ responseObject , $ result );
504
+ }
505
+
506
+ /**
507
+ * Dataprovider for testWhitespaceOption.
508
+ *
509
+ * @return array
510
+ */
511
+ public function provideWhitespaceOption ()
512
+ {
513
+ return [
514
+ 'whitespace admin scope options ' => [
515
+ [
516
+ 'option ' => [
517
+ 'value ' => [
518
+ "option_0 " => [' ' ],
519
+ ],
520
+ ],
521
+ ],
522
+ (object ) [
523
+ 'error ' => true ,
524
+ 'message ' => 'The value of Admin scope can \'t be empty. ' ,
525
+ ]
526
+ ],
527
+ 'not empty admin scope options ' => [
528
+ [
529
+ 'option ' => [
530
+ 'value ' => [
531
+ "option_0 " => ['asdads ' ],
532
+ ],
533
+ ],
534
+ ],
535
+ (object ) [
536
+ 'error ' => false ,
537
+ ]
538
+ ],
539
+ 'whitespace admin scope options and deleted ' => [
540
+ [
541
+ 'option ' => [
542
+ 'value ' => [
543
+ "option_0 " => [' ' ],
544
+ ],
545
+ 'delete ' => [
546
+ 'option_0 ' => '1 ' ,
547
+ ],
548
+ ],
549
+ ],
550
+ (object ) [
551
+ 'error ' => false ,
552
+ ],
553
+ ],
554
+ 'whitespace admin scope options and not deleted ' => [
555
+ [
556
+ 'option ' => [
557
+ 'value ' => [
558
+ "option_0 " => [' ' ],
559
+ ],
560
+ 'delete ' => [
561
+ 'option_0 ' => '0 ' ,
562
+ ],
563
+ ],
564
+ ],
565
+ (object ) [
566
+ 'error ' => true ,
567
+ 'message ' => 'The value of Admin scope can \'t be empty. ' ,
568
+ ],
569
+ ],
570
+ ];
571
+ }
572
+
442
573
/**
443
574
* @throws \Magento\Framework\Exception\NotFoundException
444
575
*/
@@ -449,13 +580,15 @@ public function testExecuteWithOptionsDataError()
449
580
. "If the error persists, please try again later. " ;
450
581
$ this ->requestMock ->expects ($ this ->any ())
451
582
->method ('getParam ' )
452
- ->willReturnMap ([
583
+ ->willReturnMap (
584
+ [
453
585
['frontend_label ' , null , 'test_frontend_label ' ],
454
586
['attribute_code ' , null , 'test_attribute_code ' ],
455
587
['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
456
588
['message_key ' , Validate::DEFAULT_MESSAGE_KEY , 'message ' ],
457
589
['serialized_options ' , '[] ' , $ serializedOptions ],
458
- ]);
590
+ ]
591
+ );
459
592
460
593
$ this ->formDataSerializerMock
461
594
->expects ($ this ->once ())
@@ -465,10 +598,12 @@ public function testExecuteWithOptionsDataError()
465
598
466
599
$ this ->objectManagerMock
467
600
->method ('create ' )
468
- ->willReturnMap ([
601
+ ->willReturnMap (
602
+ [
469
603
[\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class, [], $ this ->attributeMock ],
470
604
[\Magento \Eav \Model \Entity \Attribute \Set::class, [], $ this ->attributeSetMock ]
471
- ]);
605
+ ]
606
+ );
472
607
473
608
$ this ->attributeCodeValidatorMock
474
609
->method ('isValid ' )
@@ -485,10 +620,14 @@ public function testExecuteWithOptionsDataError()
485
620
->willReturn ($ this ->resultJson );
486
621
$ this ->resultJson ->expects ($ this ->once ())
487
622
->method ('setJsonData ' )
488
- ->with (json_encode ([
489
- 'error ' => true ,
490
- 'message ' => $ message
491
- ]))
623
+ ->with (
624
+ json_encode (
625
+ [
626
+ 'error ' => true ,
627
+ 'message ' => $ message
628
+ ]
629
+ )
630
+ )
492
631
->willReturnSelf ();
493
632
494
633
$ this ->getModel ()->execute ();
@@ -498,23 +637,25 @@ public function testExecuteWithOptionsDataError()
498
637
* Test execute with an invalid attribute code
499
638
*
500
639
* @dataProvider provideInvalidAttributeCodes
501
- * @param string $attributeCode
502
- * @param $result
503
- * @throws \Magento\Framework\Exception\NotFoundException
640
+ * @param string $attributeCode
641
+ * @param $result
642
+ * @throws \Magento\Framework\Exception\NotFoundException
504
643
*/
505
644
public function testExecuteWithInvalidAttributeCode ($ attributeCode , $ result )
506
645
{
507
646
$ serializedOptions = '{"key":"value"} ' ;
508
647
$ this ->requestMock ->expects ($ this ->any ())
509
648
->method ('getParam ' )
510
- ->willReturnMap ([
649
+ ->willReturnMap (
650
+ [
511
651
['frontend_label ' , null , null ],
512
652
['frontend_input ' , 'select ' , 'multipleselect ' ],
513
653
['attribute_code ' , null , $ attributeCode ],
514
654
['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
515
655
['message_key ' , Validate::DEFAULT_MESSAGE_KEY , 'message ' ],
516
656
['serialized_options ' , '[] ' , $ serializedOptions ],
517
- ]);
657
+ ]
658
+ );
518
659
519
660
$ this ->formDataSerializerMock
520
661
->expects ($ this ->once ())
0 commit comments