Commit 7115995 1 parent c926404 commit 7115995 Copy full SHA for 7115995
File tree 2 files changed +79
-0
lines changed
2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Tests \Unit ;
4
4
5
+ enum TestEnum : int
6
+ {
7
+ case NO = 0 ;
8
+ case YES = 1 ;
9
+ }
10
+
5
11
class MiscellaneousTest extends \PHPUnit \Framework \TestCase
6
12
{
13
+ public function testEnumCondition () : void
14
+ {
15
+ $ condition = new \PHPFUI \ORM \Condition ('field ' , TestEnum::YES );
16
+ $ input = $ condition ->getInput ();
17
+ $ this ->assertIsArray ($ input );
18
+ $ this ->assertCount (1 , $ input );
19
+ $ this ->assertContains (1 , $ input );
20
+ }
21
+
22
+ public function testInOperator () : void
23
+ {
24
+ $ in = new \PHPFUI \ORM \Operator \In ();
25
+ $ this ->assertTrue ($ in ->correctlyTyped ([1 , 2 ]));
26
+ $ this ->assertFalse ($ in ->correctlyTyped ([]));
27
+ $ this ->assertFalse ($ in ->correctlyTyped (1 ));
28
+
29
+ $ notIn = new \PHPFUI \ORM \Operator \NotIn ();
30
+ $ this ->assertTrue ($ notIn ->correctlyTyped ([1 , 2 ]));
31
+ $ this ->assertFalse ($ notIn ->correctlyTyped ([]));
32
+ $ this ->assertFalse ($ notIn ->correctlyTyped (1 ));
33
+ }
34
+
35
+ public function testLiteralCondition () : void
36
+ {
37
+ $ condition = new \PHPFUI \ORM \Condition ('field ' , new \PHPFUI \ORM \Literal ('invoiceItem.storeItemId ' ));
38
+ $ this ->assertEquals ('field = invoiceItem.storeItemId ' , (string )$ condition );
39
+ }
40
+
7
41
public function testRow () : void
8
42
{
9
43
$ row = \PHPFUI \ORM ::getRow ('select * from customer ' );
Original file line number Diff line number Diff line change @@ -1069,6 +1069,51 @@ public function updateFromTable(array $request) : bool
1069
1069
return $ transation ->commit ();
1070
1070
}
1071
1071
1072
+ /**
1073
+ * @param array<string,mixed> $request
1074
+ *
1075
+ * @return array<string,string> errors
1076
+ */
1077
+ public function validateFromTable (array $ request ) : array
1078
+ {
1079
+ $ fields = $ this ->instance ->getFields ();
1080
+
1081
+ $ primaryKeys = $ this ->getPrimaryKeys ();
1082
+
1083
+ $ errors = [];
1084
+
1085
+ if (\count ($ primaryKeys ))
1086
+ {
1087
+ $ mainKey = $ primaryKeys [0 ];
1088
+
1089
+ foreach ($ request [$ mainKey ] ?? [] as $ existingKey => $ index )
1090
+ {
1091
+ $ data = [];
1092
+
1093
+ $ record = new static::$ className ($ existingKey );
1094
+
1095
+ foreach ($ fields as $ field => $ typeInfo )
1096
+ {
1097
+ if (isset ($ request [$ field ]))
1098
+ {
1099
+ if (\is_array ($ request [$ field ]))
1100
+ {
1101
+ $ data [$ field ] = $ request [$ field ][$ index ];
1102
+ }
1103
+ else
1104
+ {
1105
+ $ data [$ field ] = $ request [$ field ];
1106
+ }
1107
+ }
1108
+ }
1109
+ $ record ->setFrom ($ data );
1110
+ $ errors = \array_merge ($ errors , $ record ->validate ());
1111
+ }
1112
+ }
1113
+
1114
+ return $ errors ;
1115
+ }
1116
+
1072
1117
private function doTranslation (string $ text ) : string
1073
1118
{
1074
1119
$ translationCallback = null ;
You can’t perform that action at this time.
0 commit comments