/** * @return void */ public function testFindWithIdAsField() { $this->Addresses->behaviors()->Hashid->config('field', 'id'); $address = $this->Addresses->find()->where(['city' => 'NoHashId'])->first(); $hashid = $this->Addresses->encodeId($address->getOriginal('id')); $this->assertSame($hashid, $address->id); $address = $this->Addresses->patchEntity($address, ['postal_code' => '678']); $result = $this->Addresses->save($address); $this->assertTrue((bool) $result); $address = $this->Addresses->find()->where(['city' => 'NoHashId'])->first(); $this->assertSame($hashid, $address->id); }
/** * GeocoderBehaviorTest::testExpect() * * @return void */ public function testExpect() { $this->Addresses->removeBehavior('Geocoder'); $this->Addresses->addBehavior('Geo.Geocoder', ['real' => false, 'expect' => ['postal_code']]); $data = ['city' => 'Bibersfeld, Deutschland']; $entity = $this->_getEntity($data); $res = $this->Addresses->save($entity); $this->assertTrue(empty($res['lat']) && empty($res['lng'])); $data = ['city' => '74523, Deutschland']; $entity = $this->_getEntity($data); $res = $this->Addresses->save($entity); $this->assertEquals('74523 Schwäbisch Hall, Deutschland', $res['formatted_address']); $this->assertTrue(!empty($res['lat']) && !empty($res['lng'])); }
/** * GeocoderBehaviorTest::testExpect() * * @return void */ public function testExpect() { $this->Addresses->removeBehavior('Geocoder'); $this->Addresses->addBehavior('Geocoder', ['real' => false, 'expect' => [Geocoder::TYPE_POSTAL]]); $data = ['city' => 'Berlin, Deutschland']; $entity = $this->_getEntity($data); $res = $this->Addresses->save($entity); $this->assertTrue(empty($res['lat']) && empty($res['lng'])); $data = ['city' => '74523, Deutschland']; $entity = $this->_getEntity($data); $res = $this->Addresses->save($entity); $this->assertContains('74523 Schwäbisch Hall', $res['formatted_address']); //$this->assertEquals('74523 Schwäbisch Hall, Deutschland', $res['formatted_address']); $this->assertTrue(!empty($res['lat']) && !empty($res['lng'])); }
/** * @return void */ public function testSave() { $captcha = $this->Captchas->newEntity(['result' => 3, 'ip' => '127.0.0.1', 'session_id' => 1, 'created' => new DateTime('- 1 hour'), 'modified' => new DateTime('- 1 hour')]); $result = $this->Captchas->save($captcha); $this->assertTrue((bool) $result); $id = $captcha->id; $data = ['comment' => 'Foo']; $comment = $this->Comments->newEntity($data); $res = $this->Comments->save($comment); $this->assertFalse((bool) $res); $data['captcha_id'] = $id; $data['captcha_result'] = 2; $data['email_homepage'] = ''; $comment = $this->Comments->newEntity($data); $res = $this->Comments->save($comment); $this->assertFalse((bool) $res); $data['captcha_result'] = 3; $data['email_homepage'] = ''; $comment = $this->Comments->newEntity($data); $res = $this->Comments->save($comment); $this->assertTrue((bool) $res); $captcha = $this->Captchas->get($id); $this->assertNotEmpty($captcha->used); }