Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
42.39% |
39 / 92 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_plupload_test | |
42.39% |
39 / 92 |
|
50.00% |
2 / 4 |
7.06 | |
0.00% |
0 / 1 |
| generate_resize_string_data | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| test_generate_resize_string | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
| data_get_chunk_size | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_chunk_size | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_plupload_test extends phpbb_test_case |
| 15 | { |
| 16 | public static function generate_resize_string_data() |
| 17 | { |
| 18 | return array( |
| 19 | array( |
| 20 | 0, |
| 21 | 0, |
| 22 | 85, |
| 23 | 0, |
| 24 | '', |
| 25 | ), |
| 26 | array( |
| 27 | 130, |
| 28 | 150, |
| 29 | 85, |
| 30 | 1, |
| 31 | 'resize: {width: 130, height: 150, quality: 85, preserve_headers: false},' |
| 32 | ), |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @dataProvider generate_resize_string_data |
| 38 | */ |
| 39 | public function test_generate_resize_string($config_width, $config_height, $config_quality, $config_metadata, $expected) |
| 40 | { |
| 41 | global $phpbb_root_path, $phpEx; |
| 42 | |
| 43 | $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); |
| 44 | |
| 45 | $config = new \phpbb\config\config(array( |
| 46 | 'img_max_width' => $config_width, |
| 47 | 'img_max_height' => $config_height, |
| 48 | 'img_quality' => $config_quality, |
| 49 | 'img_strip_metadata' => $config_metadata, |
| 50 | 'upload_path' => 'files', |
| 51 | )); |
| 52 | $plupload = new \phpbb\plupload\plupload( |
| 53 | '', |
| 54 | $config, |
| 55 | new phpbb_mock_request, |
| 56 | new \phpbb\user($lang, '\phpbb\datetime'), |
| 57 | new \bantu\IniGetWrapper\IniGetWrapper, |
| 58 | new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)) |
| 59 | ); |
| 60 | |
| 61 | $this->assertEquals($expected, $plupload->generate_resize_string()); |
| 62 | } |
| 63 | |
| 64 | public static function data_get_chunk_size() |
| 65 | { |
| 66 | return [ |
| 67 | [[ |
| 68 | 'memory_limit' => -1, |
| 69 | 'upload_max_filesize' => 0, |
| 70 | 'post_max_size' => 0, |
| 71 | ], 0], |
| 72 | [[ |
| 73 | 'memory_limit' => -1, |
| 74 | 'upload_max_filesize' => 500, |
| 75 | 'post_max_size' => 400, |
| 76 | ], 200], |
| 77 | [[ |
| 78 | 'memory_limit' => 100, |
| 79 | 'upload_max_filesize' => 0, |
| 80 | 'post_max_size' => 300, |
| 81 | ], 50], |
| 82 | [[ |
| 83 | 'memory_limit' => 300, |
| 84 | 'upload_max_filesize' => 200, |
| 85 | 'post_max_size' => 0, |
| 86 | ], 100], |
| 87 | [[ |
| 88 | 'memory_limit' => 3000, |
| 89 | 'upload_max_filesize' => 800, |
| 90 | 'post_max_size' => 900, |
| 91 | ], 400], |
| 92 | [[ |
| 93 | 'memory_limit' => 2000, |
| 94 | 'upload_max_filesize' => 1000, |
| 95 | 'post_max_size' => 600, |
| 96 | ], 300], |
| 97 | [[ |
| 98 | 'memory_limit' => 1000, |
| 99 | 'upload_max_filesize' => 2000, |
| 100 | 'post_max_size' => 3000, |
| 101 | ], 500], |
| 102 | ]; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @dataProvider data_get_chunk_size |
| 107 | */ |
| 108 | public function test_get_chunk_size($limits_ary, $expected) |
| 109 | { |
| 110 | global $phpbb_root_path, $phpEx; |
| 111 | |
| 112 | $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); |
| 113 | $config = new \phpbb\config\config([]); |
| 114 | |
| 115 | $ini_wrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper') |
| 116 | ->onlyMethods(['getBytes']) |
| 117 | ->getMock(); |
| 118 | $ini_wrapper->method('getBytes') |
| 119 | ->will($this->returnValueMap([ |
| 120 | ['memory_limit', $limits_ary['memory_limit']], |
| 121 | ['upload_max_filesize', $limits_ary['upload_max_filesize']], |
| 122 | ['post_max_size', $limits_ary['post_max_size']] |
| 123 | ])); |
| 124 | |
| 125 | $plupload = new \phpbb\plupload\plupload( |
| 126 | '', |
| 127 | $config, |
| 128 | new phpbb_mock_request, |
| 129 | new \phpbb\user($lang, '\phpbb\datetime'), |
| 130 | $ini_wrapper, |
| 131 | new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)) |
| 132 | ); |
| 133 | |
| 134 | $this->assertEquals($expected, $plupload->get_chunk_size()); |
| 135 | } |
| 136 | } |