当前位置: 首页>>代码示例>>PHP>>正文


PHP Entity::clean方法代码示例

本文整理汇总了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'));
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:24,代码来源:MarshallerTest.php

示例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');
 }
开发者ID:Slayug,项目名称:castor,代码行数:22,代码来源:TimestampBehaviorTest.php

示例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);
     }
 }
开发者ID:lorenzo,项目名称:cakephp-cipher-behavior,代码行数:17,代码来源:CipherBehavior.php

示例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());
 }
开发者ID:jeremyheaton,项目名称:ultiswap,代码行数:12,代码来源:EntityTest.php

示例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());
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:21,代码来源:TableTest.php

示例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('*'));
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:19,代码来源:MarshallerTest.php

示例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");
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:18,代码来源:ResultSetTest.php

示例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'));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:19,代码来源:MarshallerTest.php

示例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');
 }
开发者ID:loadsys,项目名称:cakephp-creatormodifier,代码行数:19,代码来源:CreatorModifierBehaviorTest.php


注:本文中的Cake\ORM\Entity::clean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。