Completed
Pull Request — master (#501)
by Nic
35:26
created

EditableFileFieldTest::testUpdatedMaxFileSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package userforms
5
 */
6
class EditableFileFieldTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    /**
10
     * @var string
11
     */
12
    public static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
13
14
    /**
15
     * @var
16
     */
17
    private $php_max_file_size;
18
19
    /**
20
     * Hold the server default max file size upload limit for later
21
     */
22
    public function setUp()
23
    {
24
        parent::setUp();
25
26
        $editableFileField = singleton('EditableFileField');
27
        $this->php_max_file_size = $editableFileField::get_php_max_file_size();
28
29
    }
30
31
    /**
32
     * Test that the field validator has the server default as the max file size upload
33
     */
34
    public function testDefaultMaxFileSize()
35
    {
36
        $fileField = $this->objFromFixture('EditableFileField', 'file-field');
37
        $formField = $fileField->getFormField();
38
39
        $this->assertEquals($this->php_max_file_size, $formField->getValidator()->getAllowedMaxFileSize());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFileFieldTest>.

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
42
    /**
43
     * Test that validation prevents the provided upload size limit to be less than or equal to the max php size
44
     */
45
    public function testValidateFileSizeFieldValue()
46
    {
47
48
        $fileField = $this->objFromFixture('EditableFileField', 'file-field');
49
        $this->setExpectedException('ValidationException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<EditableFileFieldTest>.

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...
50
        $fileField->MaxFileSizeMB = $this->php_max_file_size * 2;
51
        $fileField->write();
52
    }
53
54
    /**
55
     * Test the field validator has the updated allowed max file size
56
     */
57
    public function testUpdatedMaxFileSize()
58
    {
59
        $fileField = $this->objFromFixture('EditableFileField', 'file-field');
60
        $fileField->MaxFileSizeMB = .25;
61
        $fileField->write();
62
63
        $formField = $fileField->getFormField();
64
        $this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 256);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFileFieldTest>.

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...
65
    }
66
67
}