home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (content_migrate.test)

This example Drupal source code file (content_migrate.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, default, field, fields, for, function, label, node, not, null, php, table, true, value

The content_migrate.test Drupal example source code

<?php
/**
 * @file Content Migrate Test Cases
 */

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

  public $content_type;

  /**
   * In the base setUp() method we need to create a content type, and 
   * Drupal 6 tables relating to CCK: content_node_field, 
   * content_node_field_instance, and content_type_TYPENAME. It is up
   * to a child class to make the proper inserts into these tables.
   */
  function setUp() {
    parent::setUp('field', 'field_ui', 'content_migrate');

    // We need a content type. We don't need nodes. We'll leave that
    // to actual tests.
    $this->content_type = $this->drupalCreateContentType(array());

    // We need to setup Drupal 6 CCK tables.
    $schema = $this->contentDrupal6Schema();
    _drupal_schema_initialize($schema, 'content_migrate', TRUE);
    foreach ($schema as $name => $table) {
      db_create_table($name, $table); // Whoopie~
      $this->assertTrue(db_table_exists($name), t('Table %table exists.', array('%table' => $name)));
    }

    // Create an admin user.
    $this->admin_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer nodes'));
  }

  protected function contentDrupal6Schema() {
    $schema =  array(
      'content_node_field' => array(
        'fields' => array(
          'field_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
          'type' => array('type' => 'varchar', 'length' => 127, 'not null' => TRUE, 'default' => ''),
          'global_settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
          'required' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
          'multiple' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
          'db_storage' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1),
          'module' => array('type' => 'varchar', 'length' => 127, 'not null' => TRUE, 'default' => ''),
          'db_columns' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
          'active' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
          'locked' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
        ),
        'primary key' => array('field_name'),
      ),
      'content_node_field_instance' => array(
        'fields' => array(
          'field_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
          'type_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
          'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
          'label' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
          'widget_type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
          'widget_settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
          'display_settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE),
          'description' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
          'widget_module' => array('type' => 'varchar', 'length' => 127, 'not null' => TRUE, 'default' => ''),
          'widget_active' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
        ),
        'primary key' => array('field_name', 'type_name'),
      ),
      'content_type_' . $this->content_type->type => 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'),
      ),
    );

    return $schema;
  }

  /**
   * Setup a field definition array based on parameters.
   * @param $type the field type.
   * @param $widget the widget type.
   * @param $multiple an integer referring to the field setting of that name.
   * @param $required should the field be required?
   * @param $default the default value to use.
   * @return $field field definition array
   */
  public function setupField($type, $widget, $multiple = 0, $required = 0, $default = '') {
    // This is going to look a little different from exported CCK
    // fields. I want to be pretty efficient in the insert phase.
    // Apologies for any confusion this might cause.
    $field = array(
      'label' => $this->randomName(8),
      'field_name' => 'field_' . strtolower($this->randomName(4)),
      'type' => $type,
      'widget_type' => $widget,
      'change' => 'Change basic information',
      'op' => 'Save field settings',
      'description' => $this->randomName(25),
      'module' => $type,
      'widget_module' => '', // fill in later
      'weight' => '0',
      'required' => $required,
      'multiple' => $multiple,
      'db_storage' => 1,
      'global_settings' => array(),
      'widget_settings' => array(
        'default_value' => array(), // fill in later
        'default_value_php' => '', // fill in later
        'default_value_widget' => NULL, // fill in later
      ),
      'db_columns' => array(
        'value' => array(
          // fill in the rest later
        ),
      ),
      'display_settings' => array(
        'label' => array('format' => 'inline', 'exclude' => 0),
        'teaser' => array('format' => 'default', 'exclude' => 0),
        'full' => array('format' => 'default', 'exclude' => 0),
      ),
    );

    for ($i = 0; $i <= $multiple; $i++) {
      $field['widget_settings']['default_value'][] = array(
        'value' => $default,
      );
    }

    return $field;
  }

  /**
   * Create a field, field_instance, and alter content_type table based on
   * the field definition input.
   * @param $field field definition array
   */
  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))); 
    }

  }

  /**
   * 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().
   *
   * @param $data data to insert.
   * @param $field a field definition array.
   * @param $node the node that the field data is attached to.
   * @param $table just in case, we'll include the table name
   * @param $delta defaults to NULL
   */
  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)));
  }

}

/**
 * @class Content Migrate Text Test Case.
 */
class ContentMigrateTextTestCase extends ContentMigrateTestCase {

  public $test_node = NULL;

  public static function getInfo() {
    return array(
      'name' => t('Content Migrate Text'),
      'description' => t('Functional tests for migrating text fields to Drupal 7.'),
      'group' => t('CCK'),
    );
  }

  function setUp() {
    parent::setUp();
  }

  function setupField($type, $widget, $multiple, $required, $default) {
    $field = parent::setupField($type, $widget, $multiple, $required, $default);

    $field['widget_module'] = 'text';
    $field['widget_settings']['rows'] = 5;
    $field['widget_settings']['size'] = '60';
    $field['global_settings']['text_processing'] = '0';
    $field['global_settings']['max_length'] = '';
    $field['global_settings']['allowed_values'] = '';
    $field['global_settings']['allowed_values_php'] = '';
    $field['db_columns']['value']['type'] = 'text';
    $field['db_columns']['value']['size'] = 'big';
    $field['db_columns']['value']['not null'] = false;
    $field['db_columns']['value']['sortable'] = true;
    $field['db_columns']['value']['views'] = true;
 
    if ($multiple <> 0) {
      $field['db_storage'] = 0;
    }

    return $field;
  }

  /**
   * Test text field migration to Drupal 7.
   */
  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();
  }

  /**
   * Test multiple revision text field migration to Drupal 7.
   */
  function testMultiRevisionTextFieldMigration() {

    // 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 with a field value.
    $settings = array('type' => $this->content_type->type);
    $test_node = $this->drupalCreateNode($settings);
    $value = array('value' => $this->randomName(10));
    $this->createFieldData($value, $test_field, $test_node, 'content_type_' . $settings['type']);

    // Revise the node and the field value.
    $test_node2 = $this->drupalCreateNode(get_object_vars($test_node));    
    $value2 = array('value' => $this->randomName(10));
    $this->createFieldData($value2, $test_field, $test_node2, '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_node2->nid);
    $this->assertText($test_field['label'], t('Found field, %field, on node %node.', array('%field' => $test_field['field_name'], '%node' => $test_node2->title)));
    $this->assertText($value2['value'], t('Found field value, %value, on node %node.', array('%value' => $value2['value'], '%node' => $test_node2->title)));

    // Get previous revision
    $this->drupalGet("node/$test_node->nid/revisions/$test_node->vid/view");
    $this->assertText($test_field['label'], t('Found field, %field, on node %node.', array('%field' => $test_field['field_name'], '%node' => $test_node->title)));
    $this->assertText($value['value'], t('Found field value, %value, on node %node.', array('%value' => $value['value'], '%node' => $test_node->title)));

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

    // Check the node edit form.
    $this->drupalGet('node/' . $test_node2->nid . '/edit');
    $this->assertFieldById('edit-' . $id . '-' . LANGUAGE_NONE . '-0-value', $value2['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();
  }

  /**
   * Test multiple valued text fields.
   */
  function testMultiValueTextFieldMigration() {
    // We need a field to migrate.
    $test_field = $this->setupField('text', 'text_textfield', 3, 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);
    $values = array();

    // Add arbitrary field data to the node.
    for ($i = 0; $i < 3; $i++) {
      $values[$i] = array('value' => $this->randomName(10));
      $this->createFieldData($values[$i], $test_field, $test_node, 'content_type_' . $settings['type'], $i);
    }

    // Okay let's do the work.
    $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.
    // @todo Check data integrity instead?
    $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 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'])));

    // Test the most important setting, number of values, for this test.
    $this->drupalGet('admin/structure/types/manage/' . $this->content_type->type . '/fields/' . $test_field['field_name']);
    $this->assertOptionSelected('edit-field-cardinality', 3, t('Number of values set to 3.'));

    $this->drupalLogout();
  }

  /**
   * Test multiple node import of a text field.
   */
  function testMultiNodeTextMigrate() {

    // 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);
    $nodes = array();
    for ($i = 0; $i < 3; $i++) {
      $nodes[$i] = $this->drupalCreateNode($settings);
      // Add arbitrary field data to the node.
      $value = array('value' => $this->randomName(10));
      $this->createFieldData($value, $test_field, $nodes[$i], 'content_type_' . $settings['type']);
    }

    // Okay let's do the work.
    $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'));

    for ($i = 0; $i < 3; $i++) {
      // Check to see if the node has the field label on it.
      // @todo Check data integrity instead?
      $this->drupalGet('node/' . $nodes[$i]->nid);
      $this->assertText($test_field['label'], t('Found field, %field, on node %node.', array('%field' => $test_field['field_name'], '%node' => $nodes[$i]->title)));
    }

    // 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'])));

    $this->drupalLogout();
  }
}

/**
 * @class List widget functional test case
 */
class ContentMigrateListTestCase extends ContentMigrateTestCase {

  public static function getInfo() {
    return array(
      'name' => t('Content Migrate List'),
      'description' => t('Functional tests for list widget.'),
      'group' => t('CCK'),
    );
  }

  function setUp() {
    parent::setUp();
  }

  /**
   * Slightly different from setupField in text case.
   */
  function setupField($type, $widget, $multiple, $required, $default, $values) {
    $field = parent::setupField($type, $widget, $multiple, $required, $default);

    $field['widget_module'] = 'optionwidgets';
    $field['widget_settings']['rows'] = 5;
    $field['widget_settings']['size'] = '60';
    $field['global_settings']['text_processing'] = '0';
    $field['global_settings']['max_length'] = '';
    $field['global_settings']['allowed_values'] = '';
    $i = 0;
    foreach ($values['value'] as $name => $val) {
      if ($i <> 0) {
        $field['global_settings']['allowed_values'] .= "\n";
      }
      $field['global_settings']['allowed_values'] .= $name . '|' . $val;
      $i++;
    }
    $field['global_settings']['allowed_values_php'] = '';
    $field['db_columns']['value']['type'] = 'text';
    $field['db_columns']['value']['size'] = 'big';
    $field['db_columns']['value']['not null'] = false;
    $field['db_columns']['value']['sortable'] = true;
    $field['db_columns']['value']['views'] = true;
 
    if ($multiple <> 0) {
      $field['db_storage'] = 0;
    }

    return $field;
  }

  function testSelectListMigration() {
    // We need a field to migrate.
    $values = array();
    for ($i = 0; $i < 5; $i++) {
      $val = $this->randomName(10);
      $values['value'][$val] = $val;
      if ($i == 0) {
        $default = array('value' => $val);
      }
      else if ($i == 2) {
        $data = array('value' => $val);
      }
    }
    $test_field = $this->setupField('text', 'optionwidgets_select', 0, 0, $default, $values);

    // 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);
    $node = $this->drupalCreateNode($settings);
    // Add arbitrary field data to the node.
    $this->createFieldData($data, $test_field, $node, 'content_type_' . $settings['type']);

    // Okay let's do the work.
    $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'));

    // Test data integrity
    $this->drupalGet('node/' . $node->nid);
    $this->assertText($test_field['label'], t('Found field, %field, on node %node.', array('%field' => $test_field['field_name'], '%node' => $node->title)));

    $this->drupalGet('node/' . $node->nid . '/edit');
    $this->assertOptionSelected('edit-' . $id . '-' . LANGUAGE_NONE, $data['value'], t('Value, %value, was selected in the select list in the node edit form.', array('%value' => $data['value'])));

    // 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'])));

    // Make sure allowed values matches.
    $n = 0;
    $allowed_values = '';
    foreach ($values['value'] as $val => $label) {
      if ($n <> 0) {
        $allowed_values .= "\n";
      }
      $allowed_values .= $val . '|' . $label;
      $n++;
    }
    $this->drupalGet('admin/structure/types/manage/' . $this->content_type->type . '/fields/' . $test_field['field_name']);
    $this->assertFieldById('edit-field-settings-allowed-values', $allowed_values, t('Found allowed values, %values, on the field edit form.', array('%values' => $allowed_values)));

    $this->drupalLogout();
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal content_migrate.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.