本文整理汇总了PHP中Cake\ORM\Entity::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::clean方法的具体用法?PHP Entity::clean怎么用?PHP Entity::clean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Entity
的用法示例。
在下文中一共展示了Entity::clean方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMergeWithCreate
/**
* Test merge with validation and create or update validation rules
*
* @return void
*/
public function testMergeWithCreate()
{
$data = ['title' => 'My title', 'author_id' => 'foo'];
$marshall = new Marshaller($this->articles);
$entity = new Entity(['title' => 'Foo', 'body' => 'My Content', 'author_id' => 1]);
$entity->accessible('*', true);
$entity->isNew(true);
$entity->clean();
$this->articles->validator()->requirePresence('thing', 'update')->add('author_id', 'numeric', ['rule' => 'numeric', 'on' => 'update']);
$expected = clone $entity;
$result = $marshall->merge($expected, $data, []);
$this->assertEmpty($result->errors('author_id'));
$this->assertEmpty($result->errors('thing'));
$entity->clean();
$entity->isNew(false);
$result = $marshall->merge($entity, $data, []);
$this->assertNotEmpty($result->errors('author_id'));
$this->assertNotEmpty($result->errors('thing'));
}
示例2: testModifiedPresent
/**
* testModifiedPresent
*
* @return void
* @triggers Model.beforeSave
*/
public function testModifiedPresent()
{
$table = $this->getMock('Cake\\ORM\\Table');
$this->Behavior = new TimestampBehavior($table);
$ts = new \DateTime('2000-01-01');
$this->Behavior->timestamp($ts);
$event = new Event('Model.beforeSave');
$existingValue = new \DateTime('2011-11-11');
$entity = new Entity(['name' => 'Foo', 'modified' => $existingValue]);
$entity->clean();
$entity->isNew(false);
$return = $this->Behavior->handleEvent($event, $entity);
$this->assertTrue($return, 'Handle Event is expected to always return true');
$this->assertInstanceOf('Cake\\I18n\\Time', $entity->modified);
$this->assertSame($ts->format('c'), $entity->modified->format('c'), 'Modified timestamp is expected to be updated');
}
示例3: afterSave
/**
* Restore original (unencrypted) values after saving to DB
* @param Event $event Event object
* @param Entity $entity Entity object
* @param ArrayObject $options Save options array
* @return void
*/
public function afterSave(Event $event, Entity $entity, ArrayObject $options)
{
if ($entity->has('_cyphered') && is_array($entity->_cyphered)) {
foreach ($entity->_cyphered as $field => $value) {
$entity->set($field, $value);
$entity->clean();
}
unset($entity->_cyphered);
}
}
示例4: testCleanRemovesErrors
/**
* Tests that marking an entity as clean will remove errors too
*
* @return void
*/
public function testCleanRemovesErrors()
{
$entity = new Entity(['a' => 'b']);
$entity->errors('a', 'is not good');
$entity->clean();
$this->assertEmpty($entity->errors());
}
示例5: testSaveOnlyDirtyProperties
/**
* Tests that only the properties marked as dirty are actually saved
* to the database
*
* @group save
* @return void
*/
public function testSaveOnlyDirtyProperties()
{
$entity = new \Cake\ORM\Entity(['username' => 'superuser', 'password' => 'root', 'created' => new Time('2013-10-10 00:00'), 'updated' => new Time('2013-10-10 00:00')]);
$entity->clean();
$entity->dirty('username', true);
$entity->dirty('created', true);
$entity->dirty('updated', true);
$table = TableRegistry::get('users');
$this->assertSame($entity, $table->save($entity));
$this->assertEquals($entity->id, self::$nextUserId);
$row = $table->find('all')->where(['id' => self::$nextUserId])->first();
$entity->set('password', null);
$this->assertEquals($entity->toArray(), $row->toArray());
}
示例6: testMergeWithFieldList
/**
* Tests that it is possible to pass a fieldList option to the merge method
*
* @return void
*/
public function testMergeWithFieldList()
{
$data = ['title' => 'My title', 'author_id' => 1];
$marshall = new Marshaller($this->articles);
$entity = new Entity(['title' => 'Foo', 'body' => 'My Content', 'author_id' => 2]);
$entity->accessible('*', false);
$entity->isNew(false);
$entity->clean();
$result = $marshall->merge($entity, $data, ['fieldList' => ['title', 'body']]);
$expected = ['title' => 'My title', 'body' => 'My Content', 'author_id' => 2];
$this->assertSame($entity, $result);
$this->assertEquals($expected, $result->toArray());
$this->assertFalse($entity->accessible('*'));
}
示例7: testIteratorAfterSerializationHydrated
/**
* Test iteration after serialization
*
* @return void
*/
public function testIteratorAfterSerializationHydrated()
{
$query = $this->table->find('all');
$results = unserialize(serialize($query->all()));
// Use a loop to test Iterator implementation
foreach ($results as $i => $row) {
$expected = new \Cake\ORM\Entity($this->fixtureData[$i]);
$expected->isNew(false);
$expected->source($this->table->alias());
$expected->clean();
$this->assertEquals($expected, $row, "Row {$i} does not match");
}
}
示例8: testMergeDirty
/**
* Tests that fields with the same value are not marked as dirty
*
* @return void
*/
public function testMergeDirty()
{
$marshall = new Marshaller($this->articles);
$entity = new Entity(['title' => 'Foo', 'author_id' => 1]);
$data = ['title' => 'Foo', 'author_id' => 1, 'crazy' => true];
$entity->accessible('*', true);
$entity->clean();
$result = $marshall->merge($entity, $data, []);
$expected = ['title' => 'Foo', 'author_id' => 1, 'crazy' => true];
$this->assertEquals($expected, $result->toArray());
$this->assertFalse($entity->dirty('title'));
$this->assertFalse($entity->dirty('author_id'));
$this->assertTrue($entity->dirty('crazy'));
}
示例9: testModifierIdPresent
/**
* Test what happens when everything works and a modifier_id value for the
* Entity is already set.
*
* @return void
* @triggers Model.beforeSave
*/
public function testModifierIdPresent()
{
$existingValue = "54108b70-a178-4590-9df4-1a900a00020f";
$event = new Event('Model.beforeSave');
$entity = new Entity(['name' => 'Foo', 'modifier_id' => $existingValue]);
$entity->clean();
$entity->isNew(false);
$return = $this->Behavior->handleEvent($event, $entity);
$this->assertTrue($return, 'Handle Event is expected to always return true');
$this->assertInternalType('string', $entity->modifier_id);
$this->assertSame($this->mockedUserUUID, $entity->modifier_id, 'Modifier_id Field Equals The Mocked Value as it Should be edited');
}