Commit 39dc1313 authored by Dries's avatar Dries
Browse files

- Patch #718254 by andypost: field names were too long -- make PostgreSQL happy.

parent 890ee7f4
...@@ -23,7 +23,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { ...@@ -23,7 +23,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
function setUp() { function setUp() {
parent::setUp('field_sql_storage', 'field', 'field_test', 'text'); 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 = array('field_name' => $this->field_name, 'type' => 'test_field', 'cardinality' => 4);
$this->field = field_create_field($this->field); $this->field = field_create_field($this->field);
$this->instance = array( $this->instance = array(
...@@ -324,51 +324,45 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { ...@@ -324,51 +324,45 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
* Test adding and removing indexes while data is present. * Test adding and removing indexes while data is present.
*/ */
function testFieldUpdateIndexesWithData() { 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. // Create a decimal field.
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']); $field_name = 'testfield';
$entity->{$field_name}[LANGUAGE_NONE][0]['value'] = 'field data'; $field = array('field_name' => $field_name, 'type' => 'text');
field_attach_insert('test_entity', $entity); $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 // Verify the indexes we will create do not exist yet.
$field = array('field_name' => $field_name, 'indexes' => array('value' => array('value'))); foreach ($tables as $table) {
field_update_field($field); $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value'), t("No index named value exists in $table"));
foreach ($tables as $table) { $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value_format'), t("No index named value_format exists in $table"));
$indexes = $this->getIndexes($table); }
$this->assertTrue($indexes["{$field_name}_value"] == array(1 => "{$field_name}_value"), t("Index on value created in $table"));
}
// Add a different index, removing the existing custom one. // Add data so the table cannot be dropped.
$field = array('field_name' => $field_name, 'indexes' => array('value_format' => array('value', 'format'))); $entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
field_update_field($field); $entity->{$field_name}[LANGUAGE_NONE][0]['value'] = 'field data';
foreach ($tables as $table) { field_attach_insert('test_entity', $entity);
$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")); // Add an index
$this->assertTrue(empty($indexes["{$field_name}_value"]), t("Index on value removed in $table")); $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. // Add a different index, removing the existing custom one.
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']); $field = array('field_name' => $field_name, 'indexes' => array('value_format' => array('value', 'format')));
field_attach_load('test_entity', array(0 => $entity)); field_update_field($field);
$this->assertEqual($entity->{$field_name}[LANGUAGE_NONE][0]['value'], 'field data', t("Index changes performed without dropping the tables")); 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 { ...@@ -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))); $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;
}
} }
...@@ -21,7 +21,7 @@ class ListFieldTestCase extends FieldTestCase { ...@@ -21,7 +21,7 @@ class ListFieldTestCase extends FieldTestCase {
function setUp() { function setUp() {
parent::setUp('field_test'); parent::setUp('field_test');
$this->field_name = 'field_test'; $this->field_name = 'test_list';
$this->field = array( $this->field = array(
'field_name' => $this->field_name, 'field_name' => $this->field_name,
'type' => 'list', 'type' => 'list',
...@@ -117,15 +117,15 @@ class ListFieldUITestCase extends FieldTestCase { ...@@ -117,15 +117,15 @@ class ListFieldUITestCase extends FieldTestCase {
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
// Create content type, with underscores. // 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)); $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
$this->type = $type->type; $this->type = $type->type;
// Store a valid URL name, with hyphens instead of underscores. // Store a valid URL name, with hyphens instead of underscores.
$this->hyphen_type = str_replace('_', '-', $this->type); $this->hyphen_type = str_replace('_', '-', $this->type);
// Create random field name. // Create random field name.
$this->field_label = $this->randomName(8); $this->field_label = $this->randomString();
$this->field_name = 'field_' . strtolower($this->randomName(8)); $this->field_name = strtolower($this->randomName());
} }
/** /**
......
...@@ -207,7 +207,7 @@ class FileFieldRevisionTestCase extends FileFieldTestCase { ...@@ -207,7 +207,7 @@ class FileFieldRevisionTestCase extends FileFieldTestCase {
*/ */
function testRevisions() { function testRevisions() {
$type_name = 'article'; $type_name = 'article';
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createFileField($field_name, $type_name); $this->createFileField($field_name, $type_name);
$field = field_info_field($field_name); $field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name); $instance = field_info_instance('node', $field_name, $type_name);
...@@ -297,7 +297,7 @@ class FileFieldDisplayTestCase extends FileFieldTestCase { ...@@ -297,7 +297,7 @@ class FileFieldDisplayTestCase extends FileFieldTestCase {
* Test normal formatter display on node display. * Test normal formatter display on node display.
*/ */
function testNodeDisplay() { function testNodeDisplay() {
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$type_name = 'article'; $type_name = 'article';
$field_settings = array( $field_settings = array(
'display_field' => '1', 'display_field' => '1',
...@@ -352,7 +352,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { ...@@ -352,7 +352,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
*/ */
function testRequired() { function testRequired() {
$type_name = 'article'; $type_name = 'article';
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createFileField($field_name, $type_name, array(), array('required' => '1')); $this->createFileField($field_name, $type_name, array(), array('required' => '1'));
$field = field_info_field($field_name); $field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name); $instance = field_info_instance('node', $field_name, $type_name);
...@@ -398,7 +398,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { ...@@ -398,7 +398,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
*/ */
function testFileMaxSize() { function testFileMaxSize() {
$type_name = 'article'; $type_name = 'article';
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createFileField($field_name, $type_name, array(), array('required' => '1')); $this->createFileField($field_name, $type_name, array(), array('required' => '1'));
$field = field_info_field($field_name); $field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name); $instance = field_info_instance('node', $field_name, $type_name);
...@@ -450,7 +450,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { ...@@ -450,7 +450,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
*/ */
function testFileExtension() { function testFileExtension() {
$type_name = 'article'; $type_name = 'article';
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createFileField($field_name, $type_name); $this->createFileField($field_name, $type_name);
$field = field_info_field($field_name); $field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name); $instance = field_info_instance('node', $field_name, $type_name);
...@@ -507,7 +507,7 @@ class FileFieldPathTestCase extends FileFieldTestCase { ...@@ -507,7 +507,7 @@ class FileFieldPathTestCase extends FileFieldTestCase {
* Test normal formatter display on node display. * Test normal formatter display on node display.
*/ */
function testUploadPath() { function testUploadPath() {
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$type_name = 'article'; $type_name = 'article';
$field = $this->createFileField($field_name, $type_name); $field = $this->createFileField($field_name, $type_name);
$test_file = $this->getTestFile('text'); $test_file = $this->getTestFile('text');
......
...@@ -570,7 +570,7 @@ class ImageFieldTestCase extends DrupalWebTestCase { ...@@ -570,7 +570,7 @@ class ImageFieldTestCase extends DrupalWebTestCase {
*/ */
function uploadNodeImage($image, $field_name, $type) { function uploadNodeImage($image, $field_name, $type) {
$edit = array( $edit = array(
'title' => $this->randomName(), 'title' => $this->randomString(),
); );
$edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = realpath($image->uri); $edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_0]'] = realpath($image->uri);
$this->drupalPost('node/add/' . $type, $edit, t('Save')); $this->drupalPost('node/add/' . $type, $edit, t('Save'));
...@@ -598,7 +598,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { ...@@ -598,7 +598,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
* Test image formatters on node display. * Test image formatters on node display.
*/ */
function testImageFieldFormatters() { function testImageFieldFormatters() {
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createImageField($field_name, 'article'); $this->createImageField($field_name, 'article');
// Create a new node with an image attached. // Create a new node with an image attached.
...@@ -647,7 +647,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { ...@@ -647,7 +647,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
* Tests for image field settings. * Tests for image field settings.
*/ */
function testImageFieldSettings() { function testImageFieldSettings() {
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$instance_settings = array( $instance_settings = array(
'alt_field' => 1, 'alt_field' => 1,
'file_extensions' => 'gif jpg jpeg', 'file_extensions' => 'gif jpg jpeg',
...@@ -705,7 +705,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { ...@@ -705,7 +705,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
*/ */
function testImageFieldDefaultImage() { function testImageFieldDefaultImage() {
// Create a new image field. // Create a new image field.
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$this->createImageField($field_name, 'article'); $this->createImageField($field_name, 'article');
// Create a new node, with no images and verify that no images are // Create a new node, with no images and verify that no images are
...@@ -751,7 +751,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { ...@@ -751,7 +751,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
// Clear field info cache so the new default image is detected. // Clear field info cache so the new default image is detected.
field_info_cache_clear(); field_info_cache_clear();
$field = field_info_field($field_name); $field = field_info_field($field_name);
$this->assertFalse($field['settings']['default_image'], t('Default image removed from field.')); $this->assertFalse($field['settings']['default_image'], t('Default image removed from field.'));
} }
} }
...@@ -771,7 +771,7 @@ class ImageFieldValidateTestCase extends ImageFieldTestCase { ...@@ -771,7 +771,7 @@ class ImageFieldValidateTestCase extends ImageFieldTestCase {
* Test min/max resolution settings. * Test min/max resolution settings.
*/ */
function testResolution() { function testResolution() {
$field_name = 'field_' . strtolower($this->randomName()); $field_name = strtolower($this->randomName());
$instance_settings = array( $instance_settings = array(
'max_resolution' => '100x100', 'max_resolution' => '100x100',
'min_resolution' => '50x50', 'min_resolution' => '50x50',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment