You are here

function ContentMigrateTextTestCase::testTextFieldMigration in Content Construction Kit (CCK) 7.3

Test text field migration to Drupal 7.

File

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

Class

ContentMigrateTextTestCase
@class Content Migrate Text Test Case.

Code

function testTextFieldMigration() {

  // We need a field to migrate.
  $test_field = $this
    ->setupField('text', 'text_textfield', 0, 0, '');

  // Save the field and field_instance to the database. And alter table.
  $this
    ->createField($test_field);

  // Create a node to work with.
  $settings = array(
    'type' => $this->content_type->type,
  );
  $test_node = $this
    ->drupalCreateNode($settings);

  // Add arbitrary field data to the node.
  $value = array(
    'value' => $this
      ->randomName(10),
  );
  $this
    ->createFieldData($value, $test_field, $test_node, 'content_type_' . $settings['type']);

  // Okay, let's login.
  $this
    ->drupalLogin($this->admin_user);
  $id = str_replace('_', '-', $test_field['field_name']);
  $this
    ->drupalGet('admin/structure/content_migrate');
  $this
    ->assertNoFieldChecked('edit-available-data-' . $id, t('Found form field for CCK field %field.', array(
    '%field' => $test_field['field_name'],
  )));
  $edit = array(
    'available[data][' . $test_field['field_name'] . ']' => $test_field['field_name'],
  );
  $this
    ->drupalPost('admin/structure/content_migrate', $edit, t('Migrate selected fields'));

  // Check to see if the node has the field label on it.
  $this
    ->drupalGet('node/' . $test_node->nid);
  $this
    ->assertText($test_field['label'], t('Found field, %field, on node %node.', array(
    '%field' => $test_field['field_name'],
    '%node' => $test_node->title,
  )));

  // Check data integrity.
  $node = node_load($test_node->nid);
  $field_name = $test_field['field_name'];
  $this
    ->assertEqual($node->{$field_name}[LANGUAGE_NONE][0]['value'], $value['value'], t('Field value, %value, is equal to original value, %old.', array(
    '%value' => $node->{$test_field['field_name']}[LANGUAGE_NONE][0]['value'],
    '%old' => $value['value'],
  )));

  // Check the node edit form.
  $this
    ->drupalGet('node/' . $test_node->nid . '/edit');
  $this
    ->assertFieldById('edit-' . $id . '-' . LANGUAGE_NONE . '-0-value', $value['value'], t('Found form field on the node edit page.'));

  // Check to make sure field instance is displayed on the manage fields page.
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->content_type->type . '/fields');
  $this
    ->assertText($test_field['label'], t('Found label, %label, for field, %field, on content type field administration page.', array(
    '%field' => $test_field['field_name'],
    '%label' => $test_field['label'],
  )));

  // @todo Do we want to confirm every setting?
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->content_type->type . '/fields/' . $test_field['field_name']);
  $this
    ->drupalLogout();
}