summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.test85
-rw-r--r--modules/field/modules/list/tests/list.test8
2 files changed, 39 insertions, 54 deletions
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.test b/modules/field/modules/field_sql_storage/field_sql_storage.test
index 32125ac10..3a3522f2b 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.test
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.test
@@ -23,7 +23,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('field_sql_storage', 'field', 'field_test', 'text');
- $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
+ $this->field_name = strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => 'test_field', 'cardinality' => 4);
$this->field = field_create_field($this->field);
$this->instance = array(
@@ -324,51 +324,45 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
* Test adding and removing indexes while data is present.
*/
function testFieldUpdateIndexesWithData() {
- // We do not have a db-agnostic inspection system in core yet, so
- // for now we can only test this on mysql.
- if (Database::getConnection()->databaseType() == 'mysql') {
- // Create a decimal field.
- $field_name = 'testfield';
- $field = array('field_name' => $field_name, 'type' => 'text');
- $field = field_create_field($field);
- $instance = array('field_name' => $field_name, 'object_type' => 'test_entity', 'bundle' => 'test_bundle');
- $instance = field_create_instance($instance);
- $tables = array(_field_sql_storage_tablename($field), _field_sql_storage_revision_tablename($field));
-
- // Verify the indexes we will create do not exist yet.
- foreach ($tables as $table) {
- $indexes = $this->getIndexes($table);
- $this->assertTrue(empty($indexes['value']), t("No index named value exists in $table"));
- $this->assertTrue(empty($indexes['value_format']), t("No index named value_format exists in $table"));
- }
- // Add data so the table cannot be dropped.
- $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
- $entity->{$field_name}[LANGUAGE_NONE][0]['value'] = 'field data';
- field_attach_insert('test_entity', $entity);
+ // Create a decimal field.
+ $field_name = 'testfield';
+ $field = array('field_name' => $field_name, 'type' => 'text');
+ $field = field_create_field($field);
+ $instance = array('field_name' => $field_name, 'object_type' => 'test_entity', 'bundle' => 'test_bundle');
+ $instance = field_create_instance($instance);
+ $tables = array(_field_sql_storage_tablename($field), _field_sql_storage_revision_tablename($field));
- // Add an index
- $field = array('field_name' => $field_name, 'indexes' => array('value' => array('value')));
- field_update_field($field);
- foreach ($tables as $table) {
- $indexes = $this->getIndexes($table);
- $this->assertTrue($indexes["{$field_name}_value"] == array(1 => "{$field_name}_value"), t("Index on value created in $table"));
- }
+ // Verify the indexes we will create do not exist yet.
+ foreach ($tables as $table) {
+ $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value'), t("No index named value exists in $table"));
+ $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value_format'), t("No index named value_format exists in $table"));
+ }
- // Add a different index, removing the existing custom one.
- $field = array('field_name' => $field_name, 'indexes' => array('value_format' => array('value', 'format')));
- field_update_field($field);
- foreach ($tables as $table) {
- $indexes = $this->getIndexes($table);
- $this->assertTrue($indexes["{$field_name}_value_format"] == array(1 => "{$field_name}_value", 2 => "{$field_name}_format"), t("Index on value_format created in $table"));
- $this->assertTrue(empty($indexes["{$field_name}_value"]), t("Index on value removed in $table"));
- }
+ // Add data so the table cannot be dropped.
+ $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
+ $entity->{$field_name}[LANGUAGE_NONE][0]['value'] = 'field data';
+ field_attach_insert('test_entity', $entity);
+
+ // Add an index
+ $field = array('field_name' => $field_name, 'indexes' => array('value' => array('value')));
+ field_update_field($field);
+ foreach ($tables as $table) {
+ $this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value created in $table"));
+ }
- // Verify that the tables were not dropped.
- $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
- field_attach_load('test_entity', array(0 => $entity));
- $this->assertEqual($entity->{$field_name}[LANGUAGE_NONE][0]['value'], 'field data', t("Index changes performed without dropping the tables"));
+ // Add a different index, removing the existing custom one.
+ $field = array('field_name' => $field_name, 'indexes' => array('value_format' => array('value', 'format')));
+ field_update_field($field);
+ foreach ($tables as $table) {
+ $this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in $table"));
+ $this->assertFalse(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value removed in $table"));
}
+
+ // Verify that the tables were not dropped.
+ $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
+ field_attach_load('test_entity', array(0 => $entity));
+ $this->assertEqual($entity->{$field_name}[LANGUAGE_NONE][0]['value'], 'field data', t("Index changes performed without dropping the tables"));
}
/**
@@ -398,13 +392,4 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$this->assertEqual($details[FIELD_LOAD_REVISION][$revision][$column_name], $storage_column_name, t('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => $revision)));
}
}
-
- function getIndexes($table) {
- $indexes = array();
- $result = db_query("SHOW INDEXES FROM {" . $table . "}");
- foreach ($result as $row) {
- $indexes[$row->key_name][$row->seq_in_index] = $row->column_name;
- }
- return $indexes;
- }
}
diff --git a/modules/field/modules/list/tests/list.test b/modules/field/modules/list/tests/list.test
index 7fa0685be..73c94a4a0 100644
--- a/modules/field/modules/list/tests/list.test
+++ b/modules/field/modules/list/tests/list.test
@@ -21,7 +21,7 @@ class ListFieldTestCase extends FieldTestCase {
function setUp() {
parent::setUp('field_test');
- $this->field_name = 'field_test';
+ $this->field_name = 'test_list';
$this->field = array(
'field_name' => $this->field_name,
'type' => 'list',
@@ -117,15 +117,15 @@ class ListFieldUITestCase extends FieldTestCase {
$this->drupalLogin($admin_user);
// Create content type, with underscores.
- $type_name = strtolower($this->randomName(8)) . '_' .'test';
+ $type_name = 'test_' . strtolower($this->randomName());
$type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
$this->type = $type->type;
// Store a valid URL name, with hyphens instead of underscores.
$this->hyphen_type = str_replace('_', '-', $this->type);
// Create random field name.
- $this->field_label = $this->randomName(8);
- $this->field_name = 'field_' . strtolower($this->randomName(8));
+ $this->field_label = $this->randomString();
+ $this->field_name = strtolower($this->randomName());
}
/**