當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。