You are here

public function ContentMigrateTestCase::createFieldData in Content Construction Kit (CCK) 7.3

Insert field data into database for a field. This will work for basic fields like text, but anything more complex will require it to be overridden. Multiple values should work with the delta parameter and if $field is setup correctly for it from createField().

Parameters

$data data to insert.:

$field a field definition array.:

$node the node that the field data is attached to.:

$table just in case, we'll include the table name:

$delta defaults to NULL:

5 calls to ContentMigrateTestCase::createFieldData()
ContentMigrateListTestCase::testSelectListMigration in modules/content_migrate/tests/content_migrate.test
ContentMigrateTextTestCase::testMultiNodeTextMigrate in modules/content_migrate/tests/content_migrate.test
Test multiple node import of a text field.
ContentMigrateTextTestCase::testMultiRevisionTextFieldMigration in modules/content_migrate/tests/content_migrate.test
Test multiple revision text field migration to Drupal 7.
ContentMigrateTextTestCase::testMultiValueTextFieldMigration in modules/content_migrate/tests/content_migrate.test
Test multiple valued text fields.
ContentMigrateTextTestCase::testTextFieldMigration in modules/content_migrate/tests/content_migrate.test
Test text field migration to Drupal 7.

File

modules/content_migrate/tests/content_migrate.test, line 226
Content Migrate Test Cases

Class

ContentMigrateTestCase
@class Content Migrate Test Case. You should use this as the parent class for your content migrate tests.

Code

public function createFieldData($data, $field, $node, $table, $delta = NULL, $shared = FALSE) {
  $fields = array(
    'vid' => $node->vid,
    'nid' => $node->nid,
  );
  foreach ($data as $key => $value) {
    $fields[$field['field_name'] . '_' . $key] = $value;
  }
  if ($field['multiple'] != 0 || $shared) {
    $table = 'content_' . $field['field_name'];
  }
  if ($field['multiple'] != 0) {
    $fields['delta'] = $delta;
  }
  $options = array(
    'return' => Database::RETURN_INSERT_ID,
  );
  $query = db_insert($table, $options)
    ->fields($fields);
  $ret = $query
    ->execute();
  $this
    ->assertNotIdentical($ret, FALSE, t('Successfully inserted %data into field %field for node %node', array(
    '%data' => serialize($data),
    '%field' => $field['field_name'],
    '%node' => $node->title,
  )));
}