You are here

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

Create a field, field_instance, and alter content_type table based on the field definition input.

Parameters

$field field definition array:

5 calls to ContentMigrateTestCase::createField()
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 142
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 createField($field, $shared = FALSE) {

  // Insert field
  $new_field = array(
    'field_name' => $field['field_name'],
    'type' => $field['type'],
    'global_settings' => serialize($field['global_settings']),
    'multiple' => $field['multiple'],
    'required' => $field['required'],
    'db_storage' => $field['db_storage'],
    'module' => $field['module'],
    'db_columns' => serialize($field['db_columns']),
    'active' => 1,
    'locked' => 0,
  );
  $options = array(
    'return' => Database::RETURN_INSERT_ID,
  );
  $query = db_insert('content_node_field', $options)
    ->fields($new_field);
  $ret = $query
    ->execute();
  $this
    ->assertNotIdentical($ret, FALSE, t('Successfully inserted field, %field, into content_node_field.', array(
    '%field' => $new_field['field_name'],
  )));

  // @todo Insert field_instance
  $new_instance = array(
    'field_name' => $field['field_name'],
    'type_name' => $this->content_type->type,
    'weight' => $field['weight'],
    'label' => $field['label'],
    'widget_type' => $field['widget_type'],
    'widget_settings' => serialize($field['widget_settings']),
    'display_settings' => serialize($field['display_settings']),
    'description' => $field['description'],
    'widget_module' => $field['widget_module'],
    'widget_active' => 1,
  );
  $query = db_insert('content_node_field_instance', $options)
    ->fields($new_instance);
  $ret = $query
    ->execute();
  $this
    ->assertNotIdentical($ret, FALSE, t('Successfully inserted field instance, %field %type, into content_node_field_instance.', array(
    '%field' => $new_field['field_name'],
    '%type' => $this->content_type->type,
  )));
  $table = 'content_type_' . $this->content_type->type;
  if ($field['multiple'] != 0 || $shared) {
    $table = 'content_' . $field['field_name'];
    $schema = array(
      'fields' => array(
        'vid' => array(
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
        'nid' => array(
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'vid',
        'delta',
      ),
      'indexes' => array(
        'nid' => array(
          'nid',
        ),
      ),
    );
    if ($field['multiple'] != 0) {
      $schema['fields']['delta'] = array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      );
    }
    db_create_table($table, $schema);
    $this
      ->assertTrue(db_table_exists($table), t('Successfully added field table %table.', array(
      '%table' => $table,
    )));
  }
  foreach ($field['db_columns'] as $key => $value) {
    $db_columns = $field['db_columns'][$key];
    foreach (array(
      'views',
      'sortable',
    ) as $item) {
      if (isset($db_columns[$item])) {
        unset($item);
      }
    }
    db_add_field($table, $field['field_name'] . '_' . $key, $db_columns);
    $this
      ->assertTrue(db_field_exists($table, $field['field_name'] . '_' . $key), t('Successfully added field %field to table %table.', array(
      '%field' => $field['field_name'],
      '%table' => $table,
    )));
  }
}