Passed
Pull Request — master (#754)
by Robbie
02:38
created

EditableFileFieldTest::testAllowEmptyTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\ORM\ValidationException;
7
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
8
9
/**
10
 * @package userforms
11
 */
12
class EditableFileFieldTest extends SapphireTest
13
{
14
    protected static $fixture_file = '../EditableFormFieldTest.yml';
15
16
    /**
17
     * @var
18
     */
19
    private $php_max_file_size;
20
21
    /**
22
     * Hold the server default max file size upload limit for later
23
     */
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
28
        $editableFileField = singleton(EditableFileField::class);
29
        $this->php_max_file_size = $editableFileField::get_php_max_file_size();
30
    }
31
32
    /**
33
     * Test that the field validator has the server default as the max file size upload
34
     */
35
    public function testDefaultMaxFileSize()
36
    {
37
        $fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
38
        $formField = $fileField->getFormField();
39
40
        $this->assertEquals($this->php_max_file_size, $formField->getValidator()->getAllowedMaxFileSize());
41
    }
42
43
    /**
44
     * Test that validation prevents the provided upload size limit to be less than or equal to the max php size
45
     */
46
    public function testValidateFileSizeFieldValue()
47
    {
48
49
        $fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
50
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

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

50
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
51
        $fileField->MaxFileSizeMB = $this->php_max_file_size * 2;
52
        $fileField->write();
53
    }
54
55
    /**
56
     * Test the field validator has the updated allowed max file size
57
     */
58
    public function testUpdatedMaxFileSize()
59
    {
60
        $fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
61
        $fileField->MaxFileSizeMB = .25;
62
        $fileField->write();
63
64
        $formField = $fileField->getFormField();
65
        $this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 262144);
66
    }
67
68
    public function testAllowEmptyTitle()
69
    {
70
        /** @var EditableFileField $field */
71
        $field = EditableFileField::create();
72
        $field->Name = 'EditableFormField_123456';
73
        $this->assertEmpty($field->getFormField()->Title());
74
    }
75
}
76