|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Live Mailbox - PHPUnit tests. |
| 4 | + * |
| 5 | + * Runs tests on a live mailbox |
| 6 | + * |
| 7 | + * @author Sebi94nbg |
| 8 | + */ |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace PhpImap; |
| 12 | + |
| 13 | +use const ENCQUOTEDPRINTABLE; |
| 14 | +use Generator; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +class LiveMailboxStringDecodingConvertingTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Provides data for testing string decoding. |
| 21 | + */ |
| 22 | + public function stringDecodeProvider(): Generator |
| 23 | + { |
| 24 | + yield 'Issue #250 iso-8859-1' => [ |
| 25 | + ENCQUOTEDPRINTABLE, |
| 26 | + 'iso-8859-1', |
| 27 | + 'mountainguan', |
| 28 | + 'mountainguan', |
| 29 | + 'e94a37111edb29a8d3f6078dc4810953964f19562613cf2bd15e21b69d30822a', |
| 30 | + ]; |
| 31 | + |
| 32 | + yield 'Issue #250 utf-7' => [ |
| 33 | + ENCQUOTEDPRINTABLE, |
| 34 | + 'utf-7', |
| 35 | + '+bUuL1Q-', |
| 36 | + '测试', |
| 37 | + '6aa8f49cc992dfd75a114269ed26de0ad6d4e7d7a70d9c8afb3d7a57a88a73ed', |
| 38 | + ]; |
| 39 | + |
| 40 | + yield 'Issue #250 utf-7 with chinese' => [ |
| 41 | + ENCQUOTEDPRINTABLE, |
| 42 | + 'utf-7', |
| 43 | + 'mountainguan+bUuL1Q-', |
| 44 | + 'mountainguan测试', |
| 45 | + '62a5022b682b7e02bda8d18424fa06501cdd71cce2832e95129673f63da2e177', |
| 46 | + ]; |
| 47 | + |
| 48 | + yield 'Issue #250 utf-8 with chinese' => [ |
| 49 | + ENCQUOTEDPRINTABLE, |
| 50 | + 'utf-8', |
| 51 | + 'mountainguan=E6=B5=8B=E8=AF=95', |
| 52 | + 'mountainguan测试', |
| 53 | + '62a5022b682b7e02bda8d18424fa06501cdd71cce2832e95129673f63da2e177', |
| 54 | + ]; |
| 55 | + |
| 56 | + yield 'Issue #657' => [ |
| 57 | + ENCQUOTEDPRINTABLE, |
| 58 | + 'iso-8859-2', |
| 59 | + '=EC=B9=E8=F8=BE=FD=E1=ED=E9', |
| 60 | + 'ěščřžýáíé', |
| 61 | + 'a05e42c7e14de716cd501e135f3f5e49545f71069de316a1e9f7bb153f9a7356', |
| 62 | + ]; |
| 63 | + |
| 64 | + yield 'Emoji utf-8' => [ |
| 65 | + ENCQUOTEDPRINTABLE, |
| 66 | + 'utf-8', |
| 67 | + 'Some subject here =F0=9F=98=98', |
| 68 | + 'Some subject here 😘', |
| 69 | + 'da66c62e7e82316b8b543f52f1ecc4415c4dc93bc87e2239ee5f98bdf00a8c50', |
| 70 | + ]; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Test that string decoding and converting works as expected. |
| 75 | + * |
| 76 | + * @dataProvider stringDecodeProvider |
| 77 | + */ |
| 78 | + public function testStringDecode(int $encoding, string $charset, string $iso_8859_2, string $utf8, string $sha256): void |
| 79 | + { |
| 80 | + $mailbox = new Mailbox('', '', ''); |
| 81 | + |
| 82 | + $dataInfo = new DataPartInfo($mailbox, 1337, '', $encoding, 0); |
| 83 | + $dataInfo->charset = $charset; |
| 84 | + |
| 85 | + $decoded = $dataInfo->decodeAfterFetch($iso_8859_2); |
| 86 | + |
| 87 | + $this->assertSame($utf8, $decoded); |
| 88 | + |
| 89 | + $this->assertSame($sha256, \hash('sha256', $decoded)); |
| 90 | + } |
| 91 | +} |
0 commit comments