@@ -62,10 +62,13 @@ public function testMailUI()
6262 ->click ('a.download.mbox ' );
6363
6464 $ filename = 'INBOX.zip ' ;
65- $ files = $ this ->getFilesFromZip ($ browser , $ filename );
66- $ browser ->removeDownloadedFile ($ filename );
67-
68- $ this ->assertSame (['INBOX.mbox ' ], $ files );
65+ try {
66+ $ this ->checkFilesInZip ($ browser , $ filename , [
67+ 'INBOX.mbox ' => ['From test-from ' , "\nFrom thomas " , "\n>From line which needs to be escaped " ],
68+ ]);
69+ } finally {
70+ $ browser ->removeDownloadedFile ($ filename );
71+ }
6972 });
7073
7174 // Test More > Download > Maildir format (two messages selected)
@@ -79,9 +82,14 @@ public function testMailUI()
7982 $ browser ->click ('a.download.maildir ' );
8083
8184 $ filename = 'INBOX.zip ' ;
82- $ files = $ this ->getFilesFromZip ($ browser , $ filename );
83- $ browser ->removeDownloadedFile ($ filename );
84- $ this ->assertCount (2 , $ files );
85+ try {
86+ $ this ->checkFilesInZip ($ browser , $ filename , [
87+ 'Test.eml ' => ['Attached image: ' ],
88+ 'Lines.eml ' => ["\nFrom line which needs to be escaped in mbox format. " ],
89+ ]);
90+ } finally {
91+ $ browser ->removeDownloadedFile ($ filename );
92+ }
8593 });
8694
8795 // Test attachments download
@@ -95,17 +103,21 @@ public function testMailUI()
95103 });
96104
97105 $ filename = 'Lines.zip ' ;
98- $ files = $ this ->getFilesFromZip ($ browser , $ filename );
99- $ browser ->removeDownloadedFile ($ filename );
100- $ expected = ['lines.txt ' , 'lines_lf.txt ' ];
101- $ this ->assertSame ($ expected , $ files );
106+ try {
107+ $ this ->checkFilesInZip ($ browser , $ filename , [
108+ 'lines.txt ' => ["foo \r\nbar \r\ngna " ],
109+ 'lines_lf.txt ' => ["foo \nbar \ngna " ],
110+ ]);
111+ } finally {
112+ $ browser ->removeDownloadedFile ($ filename );
113+ }
102114 });
103115 }
104116
105117 /**
106- * Helper to extract files list from downloaded zip file
118+ * Helper to extract and check files from downloaded zip file
107119 */
108- private function getFilesFromZip ($ browser , $ filename )
120+ private function checkFilesInZip ($ browser , $ filename, $ contents )
109121 {
110122 $ filename = $ browser ->getDownloadedFilePath ($ filename );
111123
@@ -134,16 +146,24 @@ private function getFilesFromZip($browser, $filename)
134146 } while ($ filesize1 !== $ filesize2 );
135147
136148 $ zip = new \ZipArchive ();
137- $ files = [];
149+ $ partial_names = [];
150+ $ m = [];
138151
139152 if ($ zip ->open ($ filename )) {
140153 for ($ i = 0 ; $ i < $ zip ->numFiles ; $ i ++) {
141- $ files [] = $ zip ->getNameIndex ($ i );
154+ $ this ->assertSame (1 , preg_match ('/([a-z]\w*).*(\.[^.]+)$/i ' , $ zip ->getNameIndex ($ i ), $ m ));
155+ $ first_word_and_ext = $ m [1 ] . $ m [2 ];
156+ $ partial_names [] = $ first_word_and_ext ;
157+ if (array_key_exists ($ first_word_and_ext , $ contents )) {
158+ $ unzipped = $ zip ->getFromIndex ($ i );
159+ foreach ($ contents [$ first_word_and_ext ] as $ str ) {
160+ $ this ->assertStringContainsString ($ str , $ unzipped );
161+ }
162+ }
142163 }
143164 }
165+ $ this ->assertSame (array_keys ($ contents ), $ partial_names );
144166
145167 $ zip ->close ();
146-
147- return $ files ;
148168 }
149169}
0 commit comments