Completed
Pull Request — master (#5)
by Nic
03:30
created

ImageUploadFieldTest::test__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class ImageUploadFieldTest
5
 */
6
class ImageUploadFieldTest extends SapphireTest
7
{
8
9
    /**
10
     *
11
     */
12
    public function test__construct()
0 ignored issues
show
Coding Style introduced by
Method name "ImageUploadFieldTest::test__construct" is not in camel caps format
Loading history...
13
    {
14
        $field = new ImageUploadField('Image');
15
        $this->assertInstanceOf('UploadField', $field);
1 ignored issue
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
    }
17
18
    /**
19
     *
20
     */
21
    public function testMaxUpload()
22
    {
23
        $this->assertEquals(Config::inst()->get('ImageUploadField', 'max_upload'), 1024000);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
        Config::inst()->update('ImageUploadField', 'max_upload', 512000);
25
        $this->assertEquals(Config::inst()->get('ImageUploadField', 'max_upload'), 512000);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
    }
27
28
    /**
29
     *
30
     */
31
    public function testINIUploadLimitCheck()
32
    {
33
        $iniMax = File::ini2bytes(ini_get('post_max_size'));
34
        $over = $iniMax * 2;
35
        $under = $iniMax / 2;
36
37
        Config::inst()->update('ImageUploadField', 'max_upload', $over);
38
        $imageField = ImageUploadField::create('testField');
39
        $this->assertEquals($imageField->getValidator()->getAllowedMaxFileSize(), $iniMax);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        Config::inst()->update('ImageUploadField', 'max_upload', $under);
42
        $imageField2 = ImageUploadField::create('testField2');
43
        $this->assertEquals($imageField2->getValidator()->getAllowedMaxFileSize(), $under);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
    }
45
46
    /**
47
     *
48
     */
49
    public function testExtendedField()
50
    {
51
52
        $imageField = new CustomImageUploadField('testImageField');
53
        $this->assertEquals($imageField->getValidator()->getAllowedMaxFileSize(), 512000);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
55
        Config::inst()->update('CustomImageUploadField', 'max_upload', 256000);
56
        $imageField2 = new CustomImageUploadField('testImageField2');
57
        $this->assertEquals($imageField2->getValidator()->getAllowedMaxFileSize(), 256000);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ImageUploadFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
59
    }
60
61
}
62
63
/**
64
 * Class CustomImageUploadField
65
 */
66
class CustomImageUploadField extends ImageUploadField implements TestOnly
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
67
{
68
69
    /**
70
     * @var int
71
     */
72
    private static $max_upload = 512000;
0 ignored issues
show
Unused Code introduced by
The property $max_upload is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
73
74
}
75