public function testUpdateWithOneToOne() { $this->loadFixtures(['Users', 'Profiles']); $user = User::find(1); $this->assertEquals(new User(['id' => 1, 'country_id' => 1, 'username' => 'miles', 'password' => '1Z5895jf72yL77h', 'email' => '*****@*****.**', 'firstName' => 'Miles', 'lastName' => 'Johnson', 'age' => 25, 'created' => '1988-02-26 21:22:34', 'modified' => null]), $user); $profile = $user->Profile; $this->assertEquals(new Profile(['id' => 4, 'user_id' => 1, 'lastLogin' => '2012-02-15 21:22:34', 'currentLogin' => '2013-06-06 19:11:03']), $profile); // Update records $time = time(); $user->country_id = 3; $user->username = '******'; $profile->currentLogin = $time; $user->link($profile); $this->assertEquals(1, $user->save(['validate' => false])); $this->assertEquals(new User(['id' => 1, 'country_id' => 3, 'username' => 'milesj', 'password' => '1Z5895jf72yL77h', 'email' => '*****@*****.**', 'firstName' => 'Miles', 'lastName' => 'Johnson', 'age' => 25, 'created' => '1988-02-26 21:22:34', 'modified' => null, 'Profile' => new Profile(['id' => 4, 'user_id' => 1, 'lastLogin' => '2012-02-15 21:22:34', 'currentLogin' => date('Y-m-d H:i:s', $time)])]), User::select()->with('Profile')->where('id', 1)->first()); }
/** * Test single record deletion. */ public function testDelete() { $this->loadFixtures('Users'); $last = User::select()->orderBy('_id', 'asc')->first(); $user = User::find($last->_id); $this->assertTrue($user->exists()); $this->assertSame(1, $user->delete(false)); $this->assertFalse($user->exists()); }