public function testChangedValues()
 {
     $model = new User();
     $this->assertTrue($model->getIsNewRecord());
     $model->username = '******';
     $model->password = '******';
     $this->assertEquals($model->getDirtyAttributes(), ['username' => 'Anton', 'password' => 'VeryGoodP@ssword']);
     $model->save();
     $this->assertEquals($model->getDirtyAttributes(), []);
     $this->assertFalse($model->getIsNewRecord());
     $model->username = '******';
     $model->username = '******';
     $this->assertEquals($model->getDirtyAttributes(), ['username' => 'Vasya']);
     $model->save();
     $finded = User::objects()->filter(['pk' => $model->pk])->get();
     $this->assertEquals('Vasya', $finded->username);
     $this->assertEquals($finded->getDirtyAttributes(), []);
     $finded->username = '******';
     $this->assertEquals($finded->getDirtyAttributes(), ['username' => 'Max']);
 }
Esempio n. 2
0
 public function testDirtyAttributes()
 {
     $user = new User();
     $this->assertTrue($user->getIsNewRecord());
     $user->username = '******';
     $user->password = '******';
     $this->assertEquals(['username' => '123', 'password' => '123'], $user->getDirtyAttributes());
     $saved = $user->save();
     $this->assertTrue($saved);
     $this->assertFalse($user->getIsNewRecord());
 }