Model = ClassRegistry::init('WhoDidItPlayer'); $this->Model->Behaviors->load('Tools.WhoDidIt'); } public function testModel() { $this->assertInstanceOf('AppModel', $this->Model); } public function testSaveWithDefaultSettings() { $data = array( 'name' => 'Foo' ); $this->Model->create(); $res = $this->Model->save($data); $this->assertTrue((bool)$res); $this->assertTrue(count($res['WhoDidItPlayer']) === 4); // create a new one being logged in CakeSession::write('Auth.User.id', '1'); $data = array( 'name' => 'Foo2' ); $this->Model->create(); $res = $this->Model->save($data); $this->assertTrue((bool)$res); $this->assertTrue(count($res['WhoDidItPlayer']) === 6); $this->assertEquals('1', $res['WhoDidItPlayer']['created_by']); $this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']); // now update $data = array( 'name' => 'Foo2x' ); $res = $this->Model->save($data); $this->assertTrue((bool)$res); $this->assertTrue(count($res['WhoDidItPlayer']) === 3); $this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']); } }