Classi per la configurazione upload
Cristiano Magro
2018-01-16 40d16cb1f73f75cb82cb80cb1cf3318861695cf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
 
 
 
/**
 * Implementazione dei test per la classe SetupUpload
 *
 * @author Cristiano Magro
 */
class SetupUploadTest extends PHPUnit_Framework_TestCase {
 
    /**
     *  @var $object SetupUpload
     */
    protected $object;
 
    /**
     * Set up fixture, inizializzazione dei test.
     * Eseguito prima di ogni test
     */
    protected function setUp() {
        $this->object = SetupUpload::create();
    }
 
    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown() {
 
    }
 
    public static function setUpBeforeClass() {
 
    }
 
    /**
     * Conversione di una stringa nel corrispondente valore di byte
     *
     * @since 0.3.0
     */
    public function test_str2Bytes() {
 
        $this->assertEquals('1', SetupUpload::str2Bytes('1'));
        $this->assertEquals('1', SetupUpload::str2Bytes('1b'));
        $this->assertEquals('1', SetupUpload::str2Bytes('1 b'));
 
        $this->assertEquals('1024', SetupUpload::str2Bytes('1 kb'));
        $this->assertEquals('1024', SetupUpload::str2Bytes('1 Kb'));
        $this->assertEquals('1024', SetupUpload::str2Bytes('1 KB'));
 
        $this->assertEquals('1024', SetupUpload::str2Bytes('1 kb'));
        $this->assertEquals('2048', SetupUpload::str2Bytes('2 Kb'));
        $this->assertEquals('1024', SetupUpload::str2Bytes('1 KB'));
        $this->assertEquals('2048', SetupUpload::str2Bytes('2           Kb'));
 
        $this->assertEquals('1048576', SetupUpload::str2Bytes('1 mB'));
 
        $this->assertEquals('0', SetupUpload::str2Bytes('0 B'));
        $this->assertEquals('0', SetupUpload::str2Bytes('0 kB'));
        $this->assertEquals('0', SetupUpload::str2Bytes('0 mB'));
        $this->assertEquals('0', SetupUpload::str2Bytes('0 GB'));
        $this->assertEquals('0', SetupUpload::str2Bytes('0 TB'));
    }
 
    /**
     * Conversione di una stringa nel corrispondente valore di byte, stringhe
     * non convertibili devono andare in errore
     *
     * @since             0.3.1
     * @expectedException Upload_Exc_Error
     * @dataProvider      getBytesStringNotValid
     */
    public function test_str2BytesNonValido($byteString) {
        SetupUpload::str2Bytes($byteString);
    }
 
    public function getBytesStringNotValid() {
        return array(
            array(''),
            array('b'),
            array('1 k'),
            array('1 a'),
        );
    }
 
    /**
     * La coda non inizializzata prevede un numero minimo di files
     *
     * @since 0.3.1
     */
    public function testDefaultValue() {
        $this->assertEquals(1, $this->object->getNumMaxFiles());
    }
 
    /**
     * Gestione di valori non adeguati
     *
     * @since             0.3.1
     * @expectedException Upload_Exc_Error
     * @dataProvider      getNumMaxFilesException
     */
    public function testNotValidNumMaxFilesGetException($num) {
        $this->object->setNumMaxFiles($num);
    }
 
    public function getNumMaxFilesException() {
        return array(
            array(''),
            array(0),
            array(-10),
            array('a'),
        );
    }
 
    /**
     * Caselle della coda valide
     *
     * @since        0.3.1
     * @dataProvider getSomeMaxFiles
     */
    public function testSomeValidMaxFiles($num) {
        $this->object->setNumMaxFiles($num);
        $this->assertEquals($num, $this->object->getNumMaxFiles());
    }
 
    public function getSomeMaxFiles() {
        return array(
            array(2),
            array(020),
            array(100),
            array(10000),
        );
    }
 
    /**
     * Impostazioni delle dimensioni massime del totale caricabile
     *
     * @since 0.3.1
     */
    public function testSetSizeMaxFilesByte() {
        $this->object->setSizeMaxFilesByte(100);
        $this->assertEquals(100, $this->object->getSizeMaxFilesByte());
 
        $this->object->setSizeMaxFilesByte('200');
        $this->assertEquals(200, $this->object->getSizeMaxFilesByte());
 
        $this->object->setSizeMaxFilesByte('3 kb');
        $this->assertEquals(1024 * 3, $this->object->getSizeMaxFilesByte());
    }
 
    /**
     * Impostazioni delle dimensioni massime di un file
     *
     * @since 0.3.1
     */
    public function testSetSizeLimitFile() {
        $this->object->setSizeLimitFile(100);
        $this->assertEquals(100, $this->object->getSizeLimitFile());
 
        $this->object->setSizeLimitFile('200');
        $this->assertEquals(200, $this->object->getSizeLimitFile());
 
        $this->object->setSizeLimitFile('3kb');
        $this->assertEquals(1024 * 3, $this->object->getSizeLimitFile());
    }
 
}