Skip to content

Commit 497dcd6

Browse files
michallohniskydg
authored andcommitted
UploadControl: added isOK()
1 parent 9cbbc41 commit 497dcd6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Forms/Controls/UploadControl.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,18 @@ public function isFilled()
8989
return $this->value instanceof FileUpload ? $this->value->isOk() : (bool) $this->value; // ignore NULL object
9090
}
9191

92+
93+
/**
94+
* Have been all files succesfully uploaded?
95+
* @return bool
96+
*/
97+
public function isOk()
98+
{
99+
return $this->value instanceof FileUpload
100+
? $this->value->isOk()
101+
: $this->value && array_reduce($this->value, function ($carry, $fileUpload) {
102+
return $carry && $fileUpload->isOk();
103+
}, TRUE);
104+
}
105+
92106
}

tests/Forms/Controls.UploadControl.loadData.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ test(function () {
6868
'error' => 0,
6969
]), $input->getValue());
7070
Assert::true($input->isFilled());
71+
Assert::true($input->isOk());
7172
});
7273

7374

@@ -84,6 +85,7 @@ test(function () { // container
8485
'error' => 0,
8586
]), $input->getValue());
8687
Assert::true($input->isFilled());
88+
Assert::true($input->isOk());
8789
});
8890

8991

@@ -106,6 +108,7 @@ test(function () { // multiple (in container)
106108
'error' => 0,
107109
])], $input->getValue());
108110
Assert::true($input->isFilled());
111+
Assert::true($input->isOk());
109112
});
110113

111114

@@ -117,6 +120,7 @@ test(function () { // missing data
117120
Assert::false($form->isValid());
118121
Assert::equal([], $input->getValue());
119122
Assert::false($input->isFilled());
123+
Assert::false($input->isOk());
120124
});
121125

122126

@@ -128,6 +132,7 @@ test(function () { // empty data
128132
Assert::false($form->isValid());
129133
Assert::equal(new FileUpload([]), $input->getValue());
130134
Assert::false($input->isFilled());
135+
Assert::false($input->isOk());
131136
});
132137

133138

@@ -138,27 +143,31 @@ test(function () { // malformed data
138143
Assert::true($form->isValid());
139144
Assert::equal(new FileUpload([]), $input->getValue());
140145
Assert::false($input->isFilled());
146+
Assert::false($input->isOk());
141147

142148
$form = new Form;
143149
$input = $form->addUpload('invalid2');
144150

145151
Assert::true($form->isValid());
146152
Assert::equal(new FileUpload([]), $input->getValue());
147153
Assert::false($input->isFilled());
154+
Assert::false($input->isOk());
148155

149156
$form = new Form;
150157
$input = $form->addMultiUpload('avatar');
151158

152159
Assert::true($form->isValid());
153160
Assert::equal([], $input->getValue());
154161
Assert::false($input->isFilled());
162+
Assert::false($input->isOk());
155163

156164
$form = new Form;
157165
$input = $form->addContainer('multiple')->addUpload('avatar');
158166

159167
Assert::true($form->isValid());
160168
Assert::equal(new FileUpload([]), $input->getValue());
161169
Assert::false($input->isFilled());
170+
Assert::false($input->isOk());
162171
});
163172

164173

0 commit comments

Comments
 (0)