File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
55and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
66
7+ ## [ 2.1.5] - 2019-10-04
8+ ### Fixed
9+ - Moved validation of invalid file to validate function to avoid wrong behavior.
10+
711## [ 2.1.4] - 2019-05-10
812### Added
913 - Added missing varible (attributes) to ` BoundWidget ` class
Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ public function __construct(array $args = array())
3131
3232 public function validate ($ value )
3333 {
34- if (0 == $ value ->size && !$ this ->required ) {
34+ if ((! isset ( $ value -> size ) && $ this -> isDisabled ()) || 0 == $ value ->size && !$ this ->required ) {
3535 return ;
36+ } elseif (!isset ($ value ->size ) && !$ this ->isDisabled ()) {
37+ throw new ValidationError (msg ("INVALID_FILE " ), 'invalid ' );
3638 }
3739
3840 if (0 == $ value ->size && $ this ->required ) {
@@ -55,10 +57,9 @@ public function validate($value)
5557
5658 public function toNative ($ value )
5759 {
58- if (! is_array ($ value )) {
59- throw new ValidationError ( msg ( " INVALID_FILE " ), ' invalid ' ) ;
60+ if (is_null ($ value )) {
61+ return $ value ;
6062 }
61-
6263 return (object ) $ value ;
6364 }
6465}
Original file line number Diff line number Diff line change 66use PHPForm \Exceptions \ValidationError ;
77use PHPForm \Fields \FileField ;
88use PHPForm \Widgets \FileInput ;
9+ use stdClass ;
910
1011class FileFieldTest extends TestCase
1112{
@@ -72,13 +73,10 @@ public function testToNative()
7273 $ this ->assertEquals ($ data ['size ' ], $ result ->size );
7374 }
7475
75- /**
76- * @expectedException PHPForm\Exceptions\ValidationError
77- * @expectedExceptionMessage Invalid file submitted.
78- */
7976 public function testToNativeInvalidValue ()
8077 {
81- $ this ->field ->toNative ("string " );
78+ $ result = $ this ->field ->toNative (null );
79+ $ this ->assertNull ($ result );
8280 }
8381
8482 /**
You can’t perform that action at this time.
0 commit comments