save() public method

Save metadata object
public save ( ) : integer | boolean
return integer | boolean the metadata object id or true if updated
示例#1
0
 public function testCanSaveMetadata()
 {
     $owner = $this->mocks()->getUser();
     _elgg_services()->session->setLoggedInUser($owner);
     $object = $this->mocks()->getObject(['owner_guid' => $owner->guid]);
     $metadata = new ElggMetadata();
     $metadata->entity_guid = $object->guid;
     $metadata->name = 'foo';
     $metadata->value = 'bar';
     $metadata->time_created = _elgg_services()->metadataTable->getCurrentTime()->getTimestamp();
     $id = _elgg_services()->metadataTable->iterator + 1;
     // Insert
     $dbprefix = elgg_get_config('dbprefix');
     $sql = "INSERT INTO {$dbprefix}metadata\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES (:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
     _elgg_services()->db->addQuerySpec(['sql' => $sql, 'params' => [':entity_guid' => $metadata->entity_guid, ':name' => 'foo', ':value' => 'bar', ':value_type' => 'text', ':owner_guid' => $metadata->owner_guid, ':time_created' => $metadata->time_created, ':access_id' => $metadata->access_id], 'insert_id' => $id]);
     $this->assertEquals($id, $metadata->save());
     _elgg_services()->session->removeLoggedInUser();
 }