Completed
Push — master ( 5b5792...2b84bd )
by Schlaefer
03:33 queued 11s
created

UploaderConfigTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefaultSize() 0 14 1
A testCustomSize() 0 10 1
A testSizeNotFound() 0 9 1
A testGetCacheKey() 0 6 1
A testGetAllTypes() 0 9 2
A testMaxNumberOfUploadsPerUser() 0 8 1
A testHasType() 0 8 1
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 testDefaultSize()
21
    {
22
        $config = new UploaderConfig();
23
        $config->addType('video/webm');
24
        $this->assertEquals(2000000, $config->getSize('video/webm'));
25
26
        $config->setDefaultMaxFileSize(5);
27
        $config->addType('text/plain');
28
        $this->assertEquals(5, $config->getSize('text/plain'));
29
30
        $config->setDefaultMaxFileSize('3KB');
31
        $config->addType('text/plain');
32
        $this->assertEquals(3 * 1024, $config->getSize('text/plain'));
33
    }
34
35
    public function testCustomSize()
36
    {
37
        $config = new UploaderConfig();
38
39
        $config->addType('text/plain', 10);
40
        $this->assertEquals(10, $config->getSize('text/plain'));
41
42
        $config->addType('text/plain', '10KB');
43
        $this->assertEquals(10 * 1024, $config->getSize('text/plain'));
44
    }
45
46
    public function testSizeNotFound()
47
    {
48
        $config = new UploaderConfig();
49
50
        $this->expectException(\RuntimeException::class);
51
        $this->expectExceptionCode(1561357996);
52
53
        $config->getSize('foo/bar');
54
    }
55
56
    public function testGetCacheKey()
57
    {
58
        $config = new UploaderConfig();
59
60
        $this->assertEquals('uploadsThumbnails', $config->getCacheKey());
61
    }
62
63
    public function testGetAllTypes()
64
    {
65
        $config = new UploaderConfig();
66
        $types = ['text/plain', 'video/webm'];
67
        foreach ($types as $type) {
68
            $config->addType($type);
69
        }
70
        $this->assertEquals($types, $config->getAllTypes());
71
    }
72
73
    public function testMaxNumberOfUploadsPerUser()
74
    {
75
        $config = new UploaderConfig();
76
        $this->assertEquals(10, $config->getMaxNumberOfUploadsPerUser());
77
78
        $config->setMaxNumberOfUploadsPerUser(20);
79
        $this->assertEquals(20, $config->getMaxNumberOfUploadsPerUser());
80
    }
81
82
    public function testHasType()
83
    {
84
        $config = new UploaderConfig();
85
        $this->assertFalse($config->hasType('text/plain'));
86
87
        $config->addType('text/plain');
88
        $this->assertTrue($config->hasType('text/plain'));
89
    }
90
}
91