@@ -17,6 +17,7 @@ class Email_Test extends WPTestCase {
1717 */
1818 public function it_should_throw_exception_for_invalid_email () {
1919 $ this ->expectException ( InvalidArgumentException::class );
20+ $ this ->expectExceptionMessage ( 'Invalid email address(es): not-an-email ' );
2021 new Email ( 'not-an-email ' , 'Subject ' , 'Body ' );
2122 }
2223
@@ -68,4 +69,82 @@ public function it_should_throw_shepherd_exception_if_wp_mail_fails() {
6869 $ this ->expectException ( ShepherdTaskException::class );
6970 $ email ->process ();
7071 }
72+
73+ /**
74+ * @test
75+ */
76+ public function it_should_accept_multiple_recipients_separated_by_comma () {
77+ $ email = new Email ( 'test1@test.com, test2@test.com, test3@test.com ' , 'Subject ' , 'Body ' );
78+
79+ $ spy = [];
80+ $ this ->set_fn_return ( 'wp_mail ' , function ( $ to , $ subject , $ body , $ headers = [], $ attachments = [] ) use ( &$ spy ) {
81+ $ spy = [ $ to , $ subject , $ body , $ headers , $ attachments ];
82+ return true ;
83+ }, true );
84+
85+ $ email ->process ();
86+
87+ $ this ->assertEquals ( [ 'test1@test.com, test2@test.com, test3@test.com ' , 'Subject ' , 'Body ' , [], [] ], $ spy );
88+ }
89+
90+ /**
91+ * @test
92+ */
93+ public function it_should_accept_multiple_recipients_with_spaces () {
94+ $ email = new Email ( 'test1@test.com, test2@test.com ,test3@test.com ' , 'Subject ' , 'Body ' );
95+
96+ $ spy = [];
97+ $ this ->set_fn_return ( 'wp_mail ' , function ( $ to , $ subject , $ body , $ headers = [], $ attachments = [] ) use ( &$ spy ) {
98+ $ spy = [ $ to , $ subject , $ body , $ headers , $ attachments ];
99+ return true ;
100+ }, true );
101+
102+ $ email ->process ();
103+
104+ $ this ->assertEquals ( [ 'test1@test.com, test2@test.com ,test3@test.com ' , 'Subject ' , 'Body ' , [], [] ], $ spy );
105+ }
106+
107+ /**
108+ * @test
109+ */
110+ public function it_should_throw_exception_for_invalid_email_in_multiple_recipients () {
111+ $ this ->expectException ( InvalidArgumentException::class );
112+ $ this ->expectExceptionMessage ( 'Invalid email address(es): not-an-email, another-invalid ' );
113+ new Email ( 'test@test.com, not-an-email, valid@email.com, another-invalid ' , 'Subject ' , 'Body ' );
114+ }
115+
116+ /**
117+ * @test
118+ */
119+ public function it_should_throw_exception_for_empty_string_recipients () {
120+ $ this ->expectException ( InvalidArgumentException::class );
121+ $ this ->expectExceptionMessage ( 'Email recipients must be a non-empty string ' );
122+ new Email ( '' , 'Subject ' , 'Body ' );
123+ }
124+
125+ /**
126+ * @test
127+ */
128+ public function it_should_throw_exception_for_whitespace_only_recipients () {
129+ $ this ->expectException ( InvalidArgumentException::class );
130+ $ this ->expectExceptionMessage ( 'Email recipients must be a non-empty string ' );
131+ new Email ( ' ' , 'Subject ' , 'Body ' );
132+ }
133+
134+ /**
135+ * @test
136+ */
137+ public function it_should_accept_single_recipient () {
138+ $ email = new Email ( 'test@test.com ' , 'Subject ' , 'Body ' );
139+
140+ $ spy = [];
141+ $ this ->set_fn_return ( 'wp_mail ' , function ( $ to , $ subject , $ body , $ headers = [], $ attachments = [] ) use ( &$ spy ) {
142+ $ spy = [ $ to , $ subject , $ body , $ headers , $ attachments ];
143+ return true ;
144+ }, true );
145+
146+ $ email ->process ();
147+
148+ $ this ->assertEquals ( [ 'test@test.com ' , 'Subject ' , 'Body ' , [], [] ], $ spy );
149+ }
71150}
0 commit comments