@@ -51,7 +51,7 @@ public function testImportSubscribersWithNonCsvFileReturnsBadRequestStatus(): vo
5151    {
5252        $ filePath$ this tempDir  . '/test.txt ' ;
5353        file_put_contents ($ filePath'This is not a CSV file ' );
54-          
54+ 
5555        $ filenew  UploadedFile (
5656            $ filePath
5757            'test.txt ' ,
@@ -77,7 +77,7 @@ public function testImportSubscribersWithValidCsvFile(): void
7777        $ filePath$ this tempDir  . '/subscribers.csv ' ;
7878        $ csvContent = 
"email,name \n[email protected] ,Test User[email protected] ,Test User 2 ;
 7979        file_put_contents ($ filePath$ csvContent
80-          
80+ 
8181        $ filenew  UploadedFile (
8282            $ filePath
8383            'subscribers.csv ' ,
@@ -95,7 +95,7 @@ public function testImportSubscribersWithValidCsvFile(): void
9595
9696        $ responseself ::getClient ()->getResponse ();
9797        self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
98-          
98+ 
9999        $ responseContent$ this getDecodedJsonResponseContent ();
100100        self ::assertArrayHasKey ('imported ' , $ responseContent
101101        self ::assertArrayHasKey ('skipped ' , $ responseContent
@@ -107,7 +107,7 @@ public function testImportSubscribersWithOptions(): void
107107        $ filePath$ this tempDir  . '/subscribers.csv ' ;
108108        $ csvContent = 
"email,name \n[email protected] ,Test User ;
 109109        file_put_contents ($ filePath$ csvContent
110-          
110+ 
111111        $ filenew  UploadedFile (
112112            $ filePath
113113            'subscribers.csv ' ,
@@ -128,7 +128,7 @@ public function testImportSubscribersWithOptions(): void
128128
129129        $ responseself ::getClient ()->getResponse ();
130130        self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
131-          
131+ 
132132        $ responseContent$ this getDecodedJsonResponseContent ();
133133        self ::assertArrayHasKey ('imported ' , $ responseContent
134134        self ::assertArrayHasKey ('skipped ' , $ responseContent
@@ -141,4 +141,124 @@ public function testGetMethodIsNotAllowed(): void
141141
142142        $ this assertHttpMethodNotAllowed ();
143143    }
144+ 
145+     public  function  testImportSubscribersWithListId (): void 
146+     {
147+         $ filePath$ this tempDir  . '/subscribers.csv ' ;
148+         $ csvContent = 
"email,name \n[email protected] ,Test User ;
 149+         file_put_contents ($ filePath$ csvContent
150+ 
151+         $ filenew  UploadedFile (
152+             $ filePath
153+             'subscribers.csv ' ,
154+             'text/csv ' ,
155+             null ,
156+             true 
157+         );
158+ 
159+         $ this authenticatedJsonRequest (
160+             'POST ' ,
161+             '/api/v2/subscribers/import ' ,
162+             [
163+                 'list_id '  => '1 ' 
164+             ],
165+             ['file '  => $ file
166+         );
167+ 
168+         $ responseself ::getClient ()->getResponse ();
169+         self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
170+ 
171+         $ responseContent$ this getDecodedJsonResponseContent ();
172+         self ::assertArrayHasKey ('imported ' , $ responseContent
173+         self ::assertArrayHasKey ('skipped ' , $ responseContent
174+         self ::assertArrayHasKey ('errors ' , $ responseContent
175+     }
176+ 
177+     public  function  testImportSubscribersWithUpdateExisting (): void 
178+     {
179+         $ filePath$ this tempDir  . '/subscribers.csv ' ;
180+         $ csvContent = 
"email,name \n[email protected] ,Test User ;
 181+         file_put_contents ($ filePath$ csvContent
182+ 
183+         $ filenew  UploadedFile (
184+             $ filePath
185+             'subscribers.csv ' ,
186+             'text/csv ' ,
187+             null ,
188+             true 
189+         );
190+ 
191+         $ this authenticatedJsonRequest (
192+             'POST ' ,
193+             '/api/v2/subscribers/import ' ,
194+             [
195+                 'update_existing '  => 'true ' 
196+             ],
197+             ['file '  => $ file
198+         );
199+ 
200+         $ responseself ::getClient ()->getResponse ();
201+         self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
202+ 
203+         $ responseContent$ this getDecodedJsonResponseContent ();
204+         self ::assertArrayHasKey ('imported ' , $ responseContent
205+         self ::assertArrayHasKey ('skipped ' , $ responseContent
206+         self ::assertArrayHasKey ('errors ' , $ responseContent
207+     }
208+ 
209+     public  function  testImportSubscribersWithSkipInvalidEmails (): void 
210+     {
211+         $ filePath$ this tempDir  . '/subscribers.csv ' ;
212+         $ csvContent"email,name \ninvalid-email,Test User " ;
213+         file_put_contents ($ filePath$ csvContent
214+ 
215+         $ filenew  UploadedFile (
216+             $ filePath
217+             'subscribers.csv ' ,
218+             'text/csv ' ,
219+             null ,
220+             true 
221+         );
222+ 
223+         $ this authenticatedJsonRequest (
224+             'POST ' ,
225+             '/api/v2/subscribers/import ' ,
226+             [
227+                 'skip_invalid_emails '  => 'true ' 
228+             ],
229+             ['file '  => $ file
230+         );
231+ 
232+         $ responseself ::getClient ()->getResponse ();
233+         self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
234+ 
235+         $ responseContent$ this getDecodedJsonResponseContent ();
236+         self ::assertArrayHasKey ('imported ' , $ responseContent
237+         self ::assertArrayHasKey ('skipped ' , $ responseContent
238+         self ::assertArrayHasKey ('errors ' , $ responseContent
239+         self ::assertEquals (0 , $ responseContent'imported ' ]);
240+         self ::assertEquals (1 , $ responseContent'skipped ' ]);
241+         self ::assertEquals ([], $ responseContent'errors ' ]);
242+ 
243+         $ this authenticatedJsonRequest (
244+             'POST ' ,
245+             '/api/v2/subscribers/import ' ,
246+             [
247+                 'skip_invalid_emails '  => 'false ' ,
248+                 'update_existing '  => 'true ' 
249+             ],
250+             ['file '  => $ file
251+         );
252+ 
253+         $ responseself ::getClient ()->getResponse ();
254+         self ::assertSame (Response::HTTP_OK , $ responsegetStatusCode ());
255+ 
256+         $ responseContent$ this getDecodedJsonResponseContent ();
257+         self ::assertArrayHasKey ('imported ' , $ responseContent
258+         self ::assertArrayHasKey ('skipped ' , $ responseContent
259+         self ::assertArrayHasKey ('errors ' , $ responseContent
260+         self ::assertEquals (1 , $ responseContent'imported ' ]);
261+         self ::assertEquals (0 , $ responseContent'skipped ' ]);
262+         self ::assertEquals ([], $ responseContent'errors ' ]);
263+     }
144264}
0 commit comments