You are here

protected function EntityMetadataIntegrationTestCase::createValue in Entity API 7

Creates a value for the given property.

1 call to EntityMetadataIntegrationTestCase::createValue()
EntityMetadataIntegrationTestCase::testCRUDfunctions in ./entity.test
Runs some generic tests on each entity.

File

./entity.test, line 2095
Entity CRUD API tests.

Class

EntityMetadataIntegrationTestCase
Tests provided entity property info of the core modules.

Code

protected function createValue($wrapper) {
  if (!isset($this->node)) {
    $this->node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->user = $this
      ->drupalCreateUser();
    $this->taxonomy_vocabulary = $this
      ->createVocabulary();
  }
  if ($options = $wrapper
    ->optionsList()) {
    $options = entity_property_options_flatten($options);
    return $wrapper instanceof EntityListWrapper ? array(
      key($options),
    ) : key($options);
  }

  // For mail addresses properly pass an mail address.
  $info = $wrapper
    ->info();
  if ($info['name'] == 'mail') {
    return 'webmaster@example.com';
  }
  switch ($wrapper
    ->type()) {
    case 'decimal':
    case 'integer':
    case 'duration':
      return 1;
    case 'date':
      return REQUEST_TIME;
    case 'boolean':
      return TRUE;
    case 'token':
      return drupal_strtolower($this
        ->randomName(8));
    case 'text':
      return $this
        ->randomName(32);
    case 'text_formatted':
      return array(
        'value' => $this
          ->randomName(16),
      );
    case 'list<taxonomy_term>':
      return array();
    default:
      return $this->{$wrapper
        ->type()};
  }
}