@@ -67,7 +67,7 @@ public function testValidate() {
67
67
$ this ->Users ->patchEntity ($ user , $ data );
68
68
$ is = $ this ->Users ->save ($ user );
69
69
$ this ->assertFalse ($ is );
70
- $ this ->assertEquals (['pwd_repeat ' ], array_keys ($ user ->errors ()));
70
+ $ this ->assertEquals (['pwd_repeat ' ], array_keys (( array ) $ user ->errors ()));
71
71
72
72
$ user = $ this ->Users ->newEntity ();
73
73
$ data = [
@@ -121,7 +121,7 @@ public function testValidateRequired() {
121
121
$ this ->Users ->patchEntity ($ user , $ data );
122
122
$ is = $ this ->Users ->save ($ user );
123
123
$ this ->assertFalse ($ is );
124
- $ this ->assertEquals (['pwd ' , 'pwd_repeat ' ], array_keys ($ user ->errors ()));
124
+ $ this ->assertEquals (['pwd ' , 'pwd_repeat ' ], array_keys (( array ) $ user ->errors ()));
125
125
}
126
126
127
127
/**
@@ -171,9 +171,8 @@ public function testValidateEmptyWithCurrentPassword() {
171
171
];
172
172
$ this ->Users ->patchEntity ($ user , $ data );
173
173
$ is = $ this ->Users ->save ($ user );
174
- //debug($user->errors());
175
174
$ this ->assertFalse ($ is );
176
- $ this ->assertEquals (['pwd ' , 'pwd_repeat ' , 'pwd_current ' ], array_keys ($ user ->errors ()));
175
+ $ this ->assertEquals (['pwd ' , 'pwd_repeat ' , 'pwd_current ' ], array_keys (( array ) $ user ->errors ()));
177
176
178
177
$ this ->tearDown ();
179
178
$ this ->setUp ();
@@ -435,7 +434,67 @@ public function testValidateCurrent() {
435
434
436
435
// Validation errors triggered - as expected
437
436
$ this ->assertFalse ($ is );
438
- $ this ->assertSame (['pwd ' , 'pwd_repeat ' , 'pwd_current ' ], array_keys ($ user ->errors ()));
437
+ $ this ->assertSame (['pwd ' , 'pwd_repeat ' , 'pwd_current ' ], array_keys ((array )$ user ->errors ()));
438
+ }
439
+
440
+ /**
441
+ * Needs faking of pwd check...
442
+ *
443
+ * @return void
444
+ */
445
+ public function testValidateCurrentOptional () {
446
+ $ this ->assertFalse ($ this ->Users ->behaviors ()->has ('Passwordable ' ));
447
+ $ user = $ this ->Users ->newEntity ();
448
+ $ data = [
449
+ 'name ' => 'xyz ' ,
450
+ 'password ' => $ this ->hasher ->hash ('somepwd ' )];
451
+ $ this ->Users ->patchEntity ($ user , $ data );
452
+ $ result = $ this ->Users ->save ($ user );
453
+ $ this ->assertTrue (!empty ($ result ));
454
+ $ userCopy = clone ($ user );
455
+ $ uid = $ user ->id ;
456
+
457
+ $ this ->Users ->removeBehavior ('Passwordable ' );
458
+ $ this ->Users ->addBehavior ('Tools.Passwordable ' , ['current ' => true , 'require ' => false ]);
459
+ $ user = clone ($ userCopy );
460
+ $ data = [
461
+ 'name ' => 'Yeah ' ,
462
+ 'current ' => '' ,
463
+ 'pwd ' => '' ,
464
+ 'pwd_repeat ' => '' ,
465
+ ];
466
+ $ this ->Users ->patchEntity ($ user , $ data );
467
+ $ this ->assertTrue ($ this ->Users ->behaviors ()->has ('Passwordable ' ));
468
+ $ is = $ this ->Users ->save ($ user );
469
+ $ this ->assertTrue ((bool )$ is );
470
+
471
+ $ user = clone ($ userCopy );
472
+ $ data = [
473
+ 'name ' => 'Yeah ' ,
474
+ 'pwd_current ' => '' ,
475
+ 'pwd ' => '123456 ' ,
476
+ 'pwd_repeat ' => '123456 '
477
+ ];
478
+ $ this ->Users ->patchEntity ($ user , $ data );
479
+ $ is = $ this ->Users ->save ($ user );
480
+ $ this ->assertFalse ($ is );
481
+
482
+ $ user = clone ($ userCopy );
483
+ $ data = [
484
+ 'name ' => 'Yeah ' ,
485
+ 'pwd_current ' => 'somepwd ' ,
486
+ 'pwd ' => '123456 ' ,
487
+ 'pwd_repeat ' => '123456 '
488
+ ];
489
+ $ user ->accessible ('* ' , false ); // Mark all properties as protected
490
+ $ user ->accessible (['id ' ], true ); // Allow id to be accessible by default
491
+ $ user = $ this ->Users ->patchEntity ($ user , $ data , ['fields ' => ['id ' ]]);
492
+
493
+ $ this ->assertNotSame ($ is ['password ' ], $ user ['password ' ]);
494
+ $ this ->assertTrue ($ user ->dirty ('pwd ' ));
495
+
496
+ $ is = $ this ->Users ->save ($ user );
497
+ $ this ->assertTrue ((bool )$ is );
439
498
}
440
499
441
500
/**
0 commit comments