1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Test the save to VFS functions |
||
5 | * |
||
6 | * @link http://www.egroupware.org |
||
7 | * @author Nathan Gray |
||
8 | * @package mail |
||
9 | * @copyright (c) 2018 by Nathan Gray |
||
10 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
11 | */ |
||
12 | |||
13 | |||
14 | namespace EGroupware\Mail; |
||
15 | |||
16 | class SaveToVfsTest extends \PHPUnit\Framework\TestCase |
||
17 | { |
||
18 | /** |
||
19 | * Create a custom status we can use to test |
||
20 | */ |
||
21 | public static function setUpBeforeClass() : void |
||
22 | { |
||
23 | parent::setUpBeforeClass(); |
||
24 | |||
25 | } |
||
26 | public static function tearDownAfterClass() : void |
||
27 | { |
||
28 | |||
29 | // Have to remove custom status first, before the DB is gone |
||
30 | parent::tearDownAfterClass(); |
||
31 | } |
||
32 | |||
33 | protected function setUp() : void |
||
34 | { |
||
35 | } |
||
36 | |||
37 | protected function tearDown() : void |
||
38 | { |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Test that we make nice filenames for the VFS |
||
43 | * |
||
44 | * Under Windows the characters < > ? " : | \ / * are not allowed. |
||
45 | * % causes problems with VFS UI |
||
46 | * |
||
47 | * @param String $filename |
||
48 | * @dataProvider filenameProvider |
||
49 | */ |
||
50 | public function testVfsFilename($filename, $replacements) |
||
51 | { |
||
52 | $cleaned = VfsTestMail::clean_subject_for_filename($filename); |
||
53 | |||
54 | $this->assertNotContains('<', $cleaned); |
||
55 | $this->assertNotContains('>', $cleaned); |
||
56 | $this->assertNotContains('"', $cleaned); |
||
57 | $this->assertNotContains('#', $cleaned); |
||
58 | $this->assertNotContains(':', $cleaned); |
||
59 | $this->assertNotContains('|', $cleaned); |
||
60 | $this->assertNotContains('\\', $cleaned); |
||
61 | $this->assertNotContains('*', $cleaned); |
||
62 | $this->assertNotContains('/', $cleaned); |
||
63 | $this->assertNotContains('?', $cleaned); |
||
64 | $this->assertNotContains('\x0b', $cleaned); |
||
65 | $this->assertNotContains('😂', $cleaned); |
||
66 | |||
67 | // Check if the filename is not empty |
||
68 | $this->assertGreaterThan(0, strlen($cleaned), 'File name is empty'); |
||
69 | |||
70 | if(!$replacements) |
||
71 | { |
||
72 | $this->assertEquals($filename, $cleaned); |
||
73 | } |
||
74 | else |
||
75 | { |
||
76 | $this->assertNotEquals($filename, $cleaned); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | public function filenameProvider() |
||
81 | { |
||
82 | return array( |
||
83 | array('Normal! All allowed (!@$^&) {\'} []', false), |
||
84 | array('Contains a >', true), |
||
85 | array('Contains a <', true), |
||
86 | array('Contains a "', true), |
||
87 | array('Contains a #', true), |
||
88 | array('Contains a :', true), |
||
89 | array('Contains a |', true), |
||
90 | array('Contains a \\', true), |
||
91 | array('Contains a *', true), |
||
92 | array('Contains a /', true), |
||
93 | array('Contains a ?', true), |
||
94 | array('Contains a %', true), |
||
95 | array('Contains a \x0b', true), |
||
96 | array('Contains a 😂', true), |
||
97 | array('This one contains them all < > " : | \ * / ? % 😂 are not allowed', true) |
||
98 | ); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | |||
103 | class VfsTestMail extends \mail_bo |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
104 | { |
||
105 | // Expose for testing |
||
106 | public static function clean_subject_for_filename($filename) |
||
107 | { |
||
108 | return parent::clean_subject_for_filename($filename); |
||
109 | } |
||
110 | } |