Skip to content

Commit 9bf4cc5

Browse files
committed
Zipdownload: check zip contents in E2E tests
This checks an Mbox download has a properly escaped From line, and also checks at least some content of each zipped file (which as a side effect verifies the zips' CRCs).
1 parent bef22cc commit 9bf4cc5

2 files changed

Lines changed: 38 additions & 17 deletions

File tree

plugins/zipdownload/tests/Browser/MailTest.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/Browser/data/mail/list_00.eml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Content-Type: text/plain; charset=UTF-8;
2121
format=flowed
2222
2323
Plain text message body.
24+
From line which needs to be escaped in mbox format.
2425
2526
--
2627
Developer of Free Software

0 commit comments

Comments
 (0)