@@ -439,6 +439,127 @@ public function provideEmptyOption()
439
439
];
440
440
}
441
441
442
+ /**
443
+ * Check that admin scope labels which only contain spaces will trigger error.
444
+ *
445
+ * @dataProvider provideWhitespaceOption
446
+ * @param array $options
447
+ * @param $result
448
+ * @throws \Magento\Framework\Exception\NotFoundException
449
+ */
450
+ public function testWhitespaceOption (array $ options , $ result )
451
+ {
452
+ $ serializedOptions = '{"key":"value"} ' ;
453
+ $ this ->requestMock ->expects ($ this ->any ())
454
+ ->method ('getParam ' )
455
+ ->willReturnMap ([
456
+ ['frontend_label ' , null , null ],
457
+ ['frontend_input ' , 'select ' , 'multipleselect ' ],
458
+ ['attribute_code ' , null , "test_attribute_code " ],
459
+ ['new_attribute_set_name ' , null , 'test_attribute_set_name ' ],
460
+ ['message_key ' , Validate::DEFAULT_MESSAGE_KEY , 'message ' ],
461
+ ['serialized_options ' , '[] ' , $ serializedOptions ],
462
+ ]);
463
+
464
+ $ this ->formDataSerializerMock
465
+ ->expects ($ this ->once ())
466
+ ->method ('unserialize ' )
467
+ ->with ($ serializedOptions )
468
+ ->willReturn ($ options );
469
+
470
+ $ this ->objectManagerMock ->expects ($ this ->once ())
471
+ ->method ('create ' )
472
+ ->willReturn ($ this ->attributeMock );
473
+
474
+ $ this ->attributeMock ->expects ($ this ->once ())
475
+ ->method ('loadByCode ' )
476
+ ->willReturnSelf ();
477
+
478
+ $ this ->attributeCodeValidatorMock ->expects ($ this ->once ())
479
+ ->method ('isValid ' )
480
+ ->with ('test_attribute_code ' )
481
+ ->willReturn (true );
482
+
483
+ $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
484
+ ->method ('create ' )
485
+ ->willReturn ($ this ->resultJson );
486
+
487
+ $ this ->resultJson ->expects ($ this ->once ())
488
+ ->method ('setJsonData ' )
489
+ ->willReturnArgument (0 );
490
+
491
+ $ response = $ this ->getModel ()->execute ();
492
+ $ responseObject = json_decode ($ response );
493
+ $ this ->assertEquals ($ responseObject , $ result );
494
+ }
495
+
496
+ /**
497
+ * Dataprovider for testWhitespaceOption.
498
+ *
499
+ * @return array
500
+ */
501
+ public function provideWhitespaceOption ()
502
+ {
503
+ return [
504
+ 'whitespace admin scope options ' => [
505
+ [
506
+ 'option ' => [
507
+ 'value ' => [
508
+ "option_0 " => [' ' ],
509
+ ],
510
+ ],
511
+ ],
512
+ (object ) [
513
+ 'error ' => true ,
514
+ 'message ' => 'The value of Admin scope can \'t be empty. ' ,
515
+ ]
516
+ ],
517
+ 'not empty admin scope options ' => [
518
+ [
519
+ 'option ' => [
520
+ 'value ' => [
521
+ "option_0 " => ['asdads ' ],
522
+ ],
523
+ ],
524
+ ],
525
+ (object ) [
526
+ 'error ' => false ,
527
+ ]
528
+ ],
529
+ 'whitespace admin scope options and deleted ' => [
530
+ [
531
+ 'option ' => [
532
+ 'value ' => [
533
+ "option_0 " => [' ' ],
534
+ ],
535
+ 'delete ' => [
536
+ 'option_0 ' => '1 ' ,
537
+ ],
538
+ ],
539
+ ],
540
+ (object ) [
541
+ 'error ' => false ,
542
+ ],
543
+ ],
544
+ 'whitespace admin scope options and not deleted ' => [
545
+ [
546
+ 'option ' => [
547
+ 'value ' => [
548
+ "option_0 " => [' ' ],
549
+ ],
550
+ 'delete ' => [
551
+ 'option_0 ' => '0 ' ,
552
+ ],
553
+ ],
554
+ ],
555
+ (object ) [
556
+ 'error ' => true ,
557
+ 'message ' => 'The value of Admin scope can \'t be empty. ' ,
558
+ ],
559
+ ],
560
+ ];
561
+ }
562
+
442
563
/**
443
564
* @throws \Magento\Framework\Exception\NotFoundException
444
565
*/
0 commit comments