Completed
Pull Request — master (#9)
by Nic
03:48
created

ImageUploadFieldTest::testINIUploadLimitCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\ImageUpload\Tests;
4
5
use Dynamic\ImageUpload\ImageUploadField;
6
use Dynamic\ImageUpload\Tests\Field\CustomImageUploadField;
7
use SilverStripe\AssetAdmin\Forms\UploadField;
0 ignored issues
show
Bug introduced by
The type SilverStripe\AssetAdmin\Forms\UploadField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Core\Convert;
10
use SilverStripe\Dev\SapphireTest;
11
12
/**
13
 * Class ImageUploadFieldTest
14
 */
15
class ImageUploadFieldTest extends SapphireTest
16
{
17
18
    /**
19
     *
20
     */
21
    public function test__construct()
22
    {
23
        $field = ImageUploadField::create('Image');
24
        $this->assertInstanceOf(UploadField::class, $field);
25
    }
26
27
    /**
28
     *
29
     */
30
    public function testMaxUpload()
31
    {
32
        $this->assertEquals(ImageUploadField::config()->get('ImageUploadField', 'max_upload'), 1024000);
33
        Config::modify()->set(ImageUploadField::class, 'max_upload', 512000);
34
        $this->assertEquals(ImageUploadField::config()->get('ImageUploadField', 'max_upload'), 512000);
35
    }
36
37
    /**
38
     *
39
     */
40
    public function testINIUploadLimitCheck()
41
    {
42
        $iniMax = Convert::memstring2bytes(ini_get('post_max_size'));
43
        $over = $iniMax * 2;
44
        $under = $iniMax / 2;
45
46
        Config::modify()->set(ImageUploadField::class, 'max_upload', $over);
47
        $imageField = ImageUploadField::create('testField');
48
        $this->assertEquals($imageField->getValidator()->getAllowedMaxFileSize(), $iniMax);
49
50
        Config::modify()->set(ImageUploadField::class, 'max_upload', $under);
51
        $imageField2 = ImageUploadField::create('testField2');
52
        $this->assertEquals($imageField2->getValidator()->getAllowedMaxFileSize(), $under);
53
    }
54
55
    /**
56
     *
57
     */
58
    public function testExtendedField()
59
    {
60
61
        $imageField = CustomImageUploadField::create('testImageField');
62
        $this->assertEquals($imageField->getValidator()->getAllowedMaxFileSize(), 512000);
63
64
        Config::inst()->update('CustomImageUploadField', 'max_upload', 256000);
0 ignored issues
show
Bug introduced by
The method update() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. It seems like you code against a sub-type of SilverStripe\Config\Coll...nfigCollectionInterface such as SilverStripe\Config\Coll...\MemoryConfigCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        Config::inst()->/** @scrutinizer ignore-call */ update('CustomImageUploadField', 'max_upload', 256000);
Loading history...
65
        $imageField2 = new CustomImageUploadField('testImageField2');
66
        $this->assertEquals($imageField2->getValidator()->getAllowedMaxFileSize(), 256000);
67
    }
68
69
}
70
71