@@ -2047,7 +2047,7 @@ public function testSaveHasOneWithValidationError() {
2047
2047
$ this ->assertNull ($ entity ->article ->id );
2048
2048
$ this ->assertNull ($ entity ->article ->get ('author_id ' ));
2049
2049
$ this ->assertTrue ($ entity ->article ->dirty ('author_id ' ));
2050
- $ this ->assertNotEMpty ($ entity ->article ->errors ('title ' ));
2050
+ $ this ->assertNotEmpty ($ entity ->article ->errors ('title ' ));
2051
2051
}
2052
2052
2053
2053
/**
@@ -2162,4 +2162,66 @@ public function testSaveHasManyWithErrorsNonAtomic() {
2162
2162
$ this ->assertEquals (5 , $ entity ->articles [1 ]->author_id );
2163
2163
}
2164
2164
2165
+ /**
2166
+ * Tests saving hasOne association and returning a validation error will
2167
+ * not abort the saving process if atomic is set to false
2168
+ *
2169
+ * @group save
2170
+ * @return void
2171
+ */
2172
+ public function testSaveHasOneWithValidationErrorNonAtomic () {
2173
+ $ entity = new \Cake \ORM \Entity ([
2174
+ 'name ' => 'Jose '
2175
+ ]);
2176
+ $ entity ->article = new \Cake \ORM \Entity ([
2177
+ 'title ' => 'A Title ' ,
2178
+ 'body ' => 'A body '
2179
+ ]);
2180
+
2181
+ $ table = TableRegistry::get ('authors ' );
2182
+ $ table ->hasOne ('articles ' );
2183
+ $ table ->association ('articles ' )
2184
+ ->target ()
2185
+ ->validator ()
2186
+ ->add ('title ' , 'num ' , ['rule ' => 'numeric ' ]);
2187
+
2188
+ $ this ->assertSame ($ entity , $ table ->save ($ entity , ['atomic ' => false ]));
2189
+ $ this ->assertFalse ($ entity ->isNew ());
2190
+ $ this ->assertTrue ($ entity ->article ->isNew ());
2191
+ $ this ->assertNull ($ entity ->article ->id );
2192
+ $ this ->assertNull ($ entity ->article ->get ('author_id ' ));
2193
+ $ this ->assertTrue ($ entity ->article ->dirty ('author_id ' ));
2194
+ $ this ->assertNotEmpty ($ entity ->article ->errors ('title ' ));
2195
+ }
2196
+
2197
+ /**
2198
+ * Tests saving belongsTo association and get a validation error won't stop
2199
+ * saving if atomic is set to false
2200
+ *
2201
+ * @group save
2202
+ * @return void
2203
+ */
2204
+ public function testsSaveBelongsToWithValidationErrorNotAtomic () {
2205
+ $ entity = new \Cake \ORM \Entity ([
2206
+ 'title ' => 'A Title ' ,
2207
+ 'body ' => 'A body '
2208
+ ]);
2209
+ $ entity ->author = new \Cake \ORM \Entity ([
2210
+ 'name ' => 'Jose '
2211
+ ]);
2212
+
2213
+ $ table = TableRegistry::get ('articles ' );
2214
+ $ table ->belongsTo ('authors ' );
2215
+ $ table ->association ('authors ' )
2216
+ ->target ()
2217
+ ->validator ()
2218
+ ->add ('name ' , 'num ' , ['rule ' => 'numeric ' ]);
2219
+
2220
+ $ this ->assertSame ($ entity , $ table ->save ($ entity ));
2221
+ $ this ->assertFalse ($ entity ->isNew ());
2222
+ $ this ->assertTrue ($ entity ->author ->isNew ());
2223
+ $ this ->assertNull ($ entity ->get ('author_id ' ));
2224
+ $ this ->assertNotEmpty ($ entity ->author ->errors ('name ' ));
2225
+ }
2226
+
2165
2227
}
0 commit comments