Passed
Push — develop ( 17729f...4ba9b1 )
by Schlaefer
04:26
created

UploaderConfigTest::testMaxResize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace ImageUploader\Test\TestCase\Lib;
14
15
use Cake\TestSuite\TestCase;
16
use ImageUploader\Lib\UploaderConfig;
17
18
class UploaderConfigTest extends TestCase
19
{
20
    public function testMaxResize()
21
    {
22
        $config = new UploaderConfig();
23
24
        $this->assertEquals(450000, $config->getMaxResize());
25
26
        $newDefaultSize = random_int(1, 1000);
27
        $config->setDefaultMaxResize($newDefaultSize);
28
        $this->assertEquals($newDefaultSize, $config->getMaxResize());
29
    }
30
31
    public function testDefaultSize()
32
    {
33
        $config = new UploaderConfig();
34
        $config->addType('video/webm');
35
        $this->assertEquals(2000000, $config->getSize('video/webm'));
36
37
        $config->setDefaultMaxFileSize(5);
38
        $config->addType('text/plain');
39
        $this->assertEquals(5, $config->getSize('text/plain'));
40
41
        $config->setDefaultMaxFileSize('3KB');
42
        $config->addType('text/plain');
43
        $this->assertEquals(3 * 1024, $config->getSize('text/plain'));
44
    }
45
46
    public function testCustomSize()
47
    {
48
        $config = new UploaderConfig();
49
50
        $config->addType('text/plain', 10);
51
        $this->assertEquals(10, $config->getSize('text/plain'));
52
53
        $config->addType('text/plain', '10KB');
54
        $this->assertEquals(10 * 1024, $config->getSize('text/plain'));
55
    }
56
57
    public function testSizeNotFound()
58
    {
59
        $config = new UploaderConfig();
60
61
        $this->expectException(\RuntimeException::class);
62
        $this->expectExceptionCode(1561357996);
63
64
        $config->getSize('foo/bar');
65
    }
66
67
    public function testGetCacheKey()
68
    {
69
        $config = new UploaderConfig();
70
71
        $this->assertEquals('uploadsThumbnails', $config->getCacheKey());
72
    }
73
74
    public function testGetAllTypes()
75
    {
76
        $config = new UploaderConfig();
77
        $types = ['text/plain', 'video/webm'];
78
        foreach ($types as $type) {
79
            $config->addType($type);
80
        }
81
        $this->assertEquals($types, $config->getAllTypes());
82
    }
83
84
    public function testMaxNumberOfUploadsPerUser()
85
    {
86
        $config = new UploaderConfig();
87
        $this->assertEquals(10, $config->getMaxNumberOfUploadsPerUser());
88
89
        $config->setMaxNumberOfUploadsPerUser(20);
90
        $this->assertEquals(20, $config->getMaxNumberOfUploadsPerUser());
91
    }
92
93
    public function testHasType()
94
    {
95
        $config = new UploaderConfig();
96
        $this->assertFalse($config->hasType('text/plain'));
97
98
        $config->addType('text/plain');
99
        $this->assertTrue($config->hasType('text/plain'));
100
    }
101
}
102