|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
| 4 | + * |
| 5 | + * Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics) |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as published |
| 9 | + * by the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace App\Tests\Settings\SystemSettings; |
| 22 | + |
| 23 | +use App\Settings\SystemSettings\AttachmentsSettings; |
| 24 | +use App\Tests\SettingsTestHelper; |
| 25 | +use PHPUnit\Framework\TestCase; |
| 26 | + |
| 27 | +class AttachmentsSettingsTest extends TestCase |
| 28 | +{ |
| 29 | + |
| 30 | + public function testGetMaxFileSizeInMegabytes(): void |
| 31 | + { |
| 32 | + $settings = SettingsTestHelper::createSettingsDummy(AttachmentsSettings::class); |
| 33 | + |
| 34 | + $settings->maxFileSize = '100M'; |
| 35 | + $this->assertEquals(100, $settings->getMaxFileSizeInMegabytes()); |
| 36 | + |
| 37 | + $settings->maxFileSize = '1G'; |
| 38 | + $this->assertEquals(1024, $settings->getMaxFileSizeInMegabytes()); |
| 39 | + |
| 40 | + //We round up to the next megabyte if the file size is smaller than 1 MB |
| 41 | + $settings->maxFileSize = '500K'; |
| 42 | + $this->assertEquals(1, $settings->getMaxFileSizeInMegabytes()); |
| 43 | + |
| 44 | + $settings->maxFileSize = '13.5M'; |
| 45 | + $this->assertEquals(13, $settings->getMaxFileSizeInMegabytes()); |
| 46 | + } |
| 47 | +} |
0 commit comments