Commit 5aebca5a authored by webchick's avatar webchick
Browse files

Ahem. Really rolling back #522786 now.

parent 3afffc9d
......@@ -193,58 +193,4 @@ class SchemaTestCase extends DrupalWebTestCase {
return FALSE;
}
}
/**
* Tests creating unsigned columns and data integrity thereof.
*/
function testUnsignedColumns() {
// First create the table with just a serial column.
$table_name = 'unsigned_table';
$table_spec = array(
'fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE)),
'primary key' => array('serial_column'),
);
$ret = array();
db_create_table($ret, $table_name, $table_spec);
// Now set up columns for the other types.
$types = array('int', 'float', 'numeric');
foreach ($types as $type) {
$column_spec = array('type' => $type, 'unsigned'=> TRUE);
if ($type == 'numeric') {
$column_spec += array('precision' => 10, 'scale' => 0);
}
$column_name = $type . '_column';
$table_spec['fields'][$column_name] = $column_spec;
db_add_field($ret, $table_name, $column_name, $column_spec);
}
// Finally, check each column and try to insert invalid values into them.
foreach($table_spec['fields'] as $column_name => $column_spec) {
$this->assertTrue(db_column_exists($table_name, $column_name), t('Unsigned @type column was created.', array('@type' => $column_spec['type'])));
$this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), t('Unsigned @type column rejected a negative value.', array('@type' => $column_spec['type'])));
}
}
/**
* Tries to insert a negative value into columns defined as unsigned.
*
* @param $table_name
* The table to insert
* @param $column_name
* The column to insert
* @return
* TRUE if the insert succeeded, FALSE otherwise
*/
function tryUnsignedInsert($table_name, $column_name) {
try {
db_insert($table_name)
->fields(array($column_name => -1))
->execute();
return TRUE;
}
catch (Exception $e) {
return FALSE;
}
}
}
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