File tree Expand file tree Collapse file tree 2 files changed +51
-5
lines changed
Model/Config/Source/Email
Test/Unit/Model/Config/Source/Email Expand file tree Collapse file tree 2 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,12 @@ public function toOptionArray()
6060 $ this ->_coreRegistry ->register ('config_system_email_template ' , $ collection );
6161 }
6262 $ options = $ collection ->toOptionArray ();
63- $ templateId = str_replace ('/ ' , '_ ' , $ this ->getPath ());
64- $ templateLabel = $ this ->_emailConfig ->getTemplateLabel ($ templateId );
65- $ templateLabel = __ ('%1 (Default) ' , $ templateLabel );
66- array_unshift ($ options , ['value ' => $ templateId , 'label ' => $ templateLabel ]);
63+ if (!empty ($ this ->getPath ())) {
64+ $ templateId = str_replace ('/ ' , '_ ' , $ this ->getPath ());
65+ $ templateLabel = $ this ->_emailConfig ->getTemplateLabel ($ templateId );
66+ $ templateLabel = __ ('%1 (Default) ' , $ templateLabel );
67+ array_unshift ($ options , ['value ' => $ templateId , 'label ' => $ templateLabel ]);
68+ }
6769 return $ options ;
6870 }
6971}
Original file line number Diff line number Diff line change @@ -102,4 +102,48 @@ public function testToOptionArray()
102102 $ this ->_model ->setPath ('template/new ' );
103103 $ this ->assertEquals ($ expectedResult , $ this ->_model ->toOptionArray ());
104104 }
105- }
105+
106+ public function testToOptionArrayWithoutPath ()
107+ {
108+ $ collection = $ this ->createMock (Collection::class);
109+ $ collection ->expects (
110+ $ this ->once ()
111+ )->method (
112+ 'toOptionArray '
113+ )->willReturn (
114+ [
115+ ['value ' => 'template_one ' , 'label ' => 'Template One ' ],
116+ ['value ' => 'template_two ' , 'label ' => 'Template Two ' ],
117+ ]
118+ );
119+
120+ $ this ->_coreRegistry ->expects (
121+ $ this ->once ()
122+ )->method (
123+ 'registry '
124+ )->with (
125+ 'config_system_email_template '
126+ )->willReturn (
127+ $ collection
128+ );
129+
130+ $ this ->_emailConfig ->expects (
131+ $ this ->never ()
132+ )->method (
133+ 'getTemplateLabel '
134+ )->with ('' )
135+ ->willThrowException (new \UnexpectedValueException ("Email template '' is not defined. " ));
136+
137+ $ expectedResult = [
138+ [
139+ 'value ' => 'template_one ' ,
140+ 'label ' => 'Template One ' ,
141+ ],
142+ [
143+ 'value ' => 'template_two ' ,
144+ 'label ' => 'Template Two ' ,
145+ ],
146+ ];
147+
148+ $ this ->assertEquals ($ expectedResult , $ this ->_model ->toOptionArray ());
149+ }}
You can’t perform that action at this time.
0 commit comments