@@ -1238,4 +1238,51 @@ public function testAtomicSaveRollbackOnFailure() {
1238
1238
$ table ->save ($ data );
1239
1239
}
1240
1240
1241
+ /**
1242
+ * Tests that only the properties marked as dirty are actually saved
1243
+ * to the database
1244
+ *
1245
+ * @return void
1246
+ */
1247
+ public function testSaveOnlyDirtyProperties () {
1248
+ $ entity = new \Cake \ORM \Entity ([
1249
+ 'username ' => 'superuser ' ,
1250
+ 'password ' => 'root ' ,
1251
+ 'created ' => new \DateTime ('2013-10-10 00:00 ' ),
1252
+ 'updated ' => new \DateTime ('2013-10-10 00:00 ' )
1253
+ ]);
1254
+ $ entity ->clean ();
1255
+ $ entity ->dirty ('username ' , true );
1256
+ $ entity ->dirty ('created ' , true );
1257
+ $ entity ->dirty ('updated ' , true );
1258
+
1259
+ $ table = TableRegistry::get ('users ' );
1260
+ $ this ->assertSame ($ entity , $ table ->save ($ entity ));
1261
+ $ this ->assertEquals ($ entity ->id , 5 );
1262
+
1263
+ $ row = $ table ->find ('all ' )->where (['id ' => 5 ])->first ();
1264
+ $ entity ->set ('password ' , null );
1265
+ $ this ->assertEquals ($ entity ->toArray (), $ row ->toArray ());
1266
+ }
1267
+
1268
+ /**
1269
+ * Tests that a recently saved entity is marked as clean
1270
+ *
1271
+ * @return void
1272
+ */
1273
+ public function testsASavedEntityIsClean () {
1274
+ $ entity = new \Cake \ORM \Entity ([
1275
+ 'username ' => 'superuser ' ,
1276
+ 'password ' => 'root ' ,
1277
+ 'created ' => new \DateTime ('2013-10-10 00:00 ' ),
1278
+ 'updated ' => new \DateTime ('2013-10-10 00:00 ' )
1279
+ ]);
1280
+ $ table = TableRegistry::get ('users ' );
1281
+ $ this ->assertSame ($ entity , $ table ->save ($ entity ));
1282
+ $ this ->assertFalse ($ entity ->dirty ('usermane ' ));
1283
+ $ this ->assertFalse ($ entity ->dirty ('password ' ));
1284
+ $ this ->assertFalse ($ entity ->dirty ('created ' ));
1285
+ $ this ->assertFalse ($ entity ->dirty ('updated ' ));
1286
+ }
1287
+
1241
1288
}
0 commit comments