? modules/simpletest/variable-profile-279455-1.patch Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.648 diff -u -p -r1.648 comment.module --- modules/comment/comment.module 6 Sep 2008 08:36:19 -0000 1.648 +++ modules/comment/comment.module 9 Sep 2008 00:56:34 -0000 @@ -1122,7 +1122,7 @@ function comment_validate($edit) { $node = node_load($edit['nid']); if (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) { if ($edit['name']) { - $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name'])); + $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE username = LOWER('%s')", $edit['name'])); if ($taken != 0) { form_set_error('name', t('The name you used belongs to a registered user.')); } Index: modules/contact/contact.test =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v retrieving revision 1.8 diff -u -p -r1.8 contact.test --- modules/contact/contact.test 2 Aug 2008 05:16:47 -0000 1.8 +++ modules/contact/contact.test 9 Sep 2008 00:56:34 -0000 @@ -60,7 +60,7 @@ class ContactSitewideTestCase extends Dr $recipients = array('simpletest@example.com', 'simpletest2@example.com', 'simpletest3@example.com'); $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); $this->assertRaw(t('Category %category has been added.', array('%category' => $category)), t('Category successfully added.')); - + // Test update contact form category $categories = $this->getCategories(); $category_id = $this->updateCategory($categories, $category = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); @@ -70,7 +70,7 @@ class ContactSitewideTestCase extends Dr $this->assertEqual($category_array['reply'], $reply); $this->assertFalse($category_array['selected']); $this->assertRaw(t('Category %category has been updated.', array('%category' => $category)), t('Category successfully updated.')); - + $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE); $this->assertRaw(t('Category %category has been added.', array('%category' => $category)), t('Category successfully added.')); Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.167 diff -u -p -r1.167 menu.module --- modules/menu/menu.module 21 Aug 2008 19:36:37 -0000 1.167 +++ modules/menu/menu.module 9 Sep 2008 00:56:34 -0000 @@ -315,13 +315,13 @@ function menu_nodeapi(&$node, $op) { if (isset($node->nid)) { // Give priority to the default menu $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", array( - ':path' => 'node/'. $node->nid, + ':path' => 'node/'. $node->nid, ':menu_name' => $menu_name, ), 0, 1)); // Check all menus if a link does not exist in the default menu. if (!$mlid) { $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array( - ':path' => 'node/'. $node->nid, + ':path' => 'node/'. $node->nid, ), 0, 1)); } if ($mlid) { Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.974 diff -u -p -r1.974 node.module --- modules/node/node.module 6 Sep 2008 08:36:20 -0000 1.974 +++ modules/node/node.module 9 Sep 2008 00:56:35 -0000 @@ -2786,7 +2786,7 @@ function node_assign_owner_action_form($ // Use dropdown for fewer than 200 users; textbox for more than that. if (intval($count) < 200) { $options = array(); - $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY name"); + $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY username"); while ($data = db_fetch_object($result)) { $options[$data->name] = $data->name; } @@ -2813,7 +2813,7 @@ function node_assign_owner_action_form($ } function node_assign_owner_action_validate($form, $form_state) { - $count = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE name = '%s'", $form_state['values']['owner_name'])); + $count = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE username = LOWER('%s')", $form_state['values']['owner_name'])); if (intval($count) != 1) { form_set_error('owner_name', t('Please enter a valid username.')); } @@ -2821,7 +2821,7 @@ function node_assign_owner_action_valida function node_assign_owner_action_submit($form, $form_state) { // Username can change, so we need to store the ID, not the username. - $uid = db_result(db_query("SELECT uid from {users} WHERE name = '%s'", $form_state['values']['owner_name'])); + $uid = db_result(db_query("SELECT uid from {users} WHERE username = LOWER('%s')", $form_state['values']['owner_name'])); return array('owner_uid' => $uid); } Index: modules/profile/profile.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.pages.inc,v retrieving revision 1.3 diff -u -p -r1.3 profile.pages.inc --- modules/profile/profile.pages.inc 21 Aug 2008 19:36:38 -0000 1.3 +++ modules/profile/profile.pages.inc 9 Sep 2008 00:56:35 -0000 @@ -111,7 +111,7 @@ function profile_autocomplete($field, $s $matches = array(); if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", array( - ':fid' => $field, + ':fid' => $field, ':value' => $string .'%', ), 0, 10); while ($data = db_fetch_object($result)) { Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.264 diff -u -p -r1.264 search.module --- modules/search/search.module 6 Sep 2008 08:36:20 -0000 1.264 +++ modules/search/search.module 9 Sep 2008 00:56:35 -0000 @@ -570,8 +570,8 @@ function search_index($sid, $type, $text // Insert results into search index foreach ($results[0] as $word => $score) { - // If a word already exists in the database, its score gets increased - // appropriately. If not, we create a new record with the appropriate + // If a word already exists in the database, its score gets increased + // appropriately. If not, we create a new record with the appropriate // starting score. db_merge('search_index')->key(array( 'word' => $word, Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.37 diff -u -p -r1.37 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 6 Sep 2008 08:36:20 -0000 1.37 +++ modules/simpletest/drupal_web_test_case.php 9 Sep 2008 00:56:35 -0000 @@ -72,12 +72,12 @@ class DrupalWebTestCase { $db_prefix = $this->db_prefix_original; db_insert('simpletest')->fields(array( 'test_id' => $this->test_id, - 'test_class' => get_class($this), - 'status' => $status, + 'test_class' => get_class($this), + 'status' => $status, 'message' => substr($message, 0, 255), // Some messages are too long for the database. - 'message_group' => $group, - 'caller' => $function['function'], - 'line' => $function['line'], + 'message_group' => $group, + 'caller' => $function['function'], + 'line' => $function['line'], 'file' => $function['file'], ))->execute(); $this->_assertions[] = array( @@ -405,7 +405,7 @@ class DrupalWebTestCase { node_types_rebuild(); $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type))); - + // Reset permissions so that permissions for this content type are available. $this->checkPermissions(array(), TRUE); @@ -645,7 +645,7 @@ class DrupalWebTestCase { // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); - + include_once './includes/install.inc'; drupal_install_system(); @@ -659,7 +659,7 @@ class DrupalWebTestCase { // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); - + // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); Index: modules/simpletest/tests/database_test.install =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.install,v retrieving revision 1.1 diff -u -p -r1.1 database_test.install --- modules/simpletest/tests/database_test.install 31 Aug 2008 11:43:41 -0000 1.1 +++ modules/simpletest/tests/database_test.install 9 Sep 2008 00:56:35 -0000 @@ -3,7 +3,7 @@ /** * Implementation of hook_schema(). - * + * * The database tests use the database API which depends on schema * information for certain operations on certain databases. * Therefore, the schema must actually be declared in a normal module @@ -14,28 +14,28 @@ function database_test_schema() { 'description' => 'Basic test table for the database unit tests.', 'fields' => array( 'id' => array( - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, ), 'name' => array( 'description' => "A person's name", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, 'default' => '', ), 'age' => array( 'description' => "The person's age", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, 'default' => 0), 'job' => array( 'description' => "The person's job", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, 'default' => 'Undefined', ), ), @@ -47,7 +47,7 @@ function database_test_schema() { 'ages' => array('age'), ), ); - + // This is an alternate version of the same table that is structured the same // but has a non-serial Primary Key. $schema['test_people'] = array( @@ -55,23 +55,23 @@ function database_test_schema() { 'fields' => array( 'name' => array( 'description' => "A person's name", - 'type' => 'varchar', - 'length' => 255, + 'type' => 'varchar', + 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'age' => array( 'description' => "The person's age", - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, 'default' => 0, ), 'job' => array( 'description' => "The person's job", - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, 'default' => '', ), ), @@ -86,7 +86,7 @@ function database_test_schema() { 'fields' => array( 'id' => array( 'description' => 'Simple unique ID.', - 'type' => 'serial', + 'type' => 'serial', 'not null' => TRUE, ), 'blob1' => array( @@ -102,7 +102,7 @@ function database_test_schema() { 'fields' => array( 'id' => array( 'description' => 'Simple unique ID.', - 'type' => 'serial', + 'type' => 'serial', 'not null' => TRUE, ), 'blob1' => array( @@ -122,28 +122,28 @@ function database_test_schema() { 'fields' => array( 'tid' => array( 'description' => 'Task ID, primary key.', - 'type' => 'serial', + 'type' => 'serial', 'not null' => TRUE, ), 'pid' => array( 'description' => 'The {test_people}.pid, foreign key for the test table.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, 'default' => 0, ), 'task' => array( 'description' => 'The task to be completed.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, 'default' => '', ), 'priority' => array( 'description' => 'The priority of the task.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, 'default' => 0, ), ), Index: modules/simpletest/tests/database_test.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.module,v retrieving revision 1.1 diff -u -p -r1.1 database_test.module --- modules/simpletest/tests/database_test.module 31 Aug 2008 11:43:41 -0000 1.1 +++ modules/simpletest/tests/database_test.module 9 Sep 2008 00:56:35 -0000 @@ -13,26 +13,26 @@ function database_test_query_alter(Selec if ($query->hasTag('database_test_alter_remove_range')) { $query->range(); } - + if ($query->hasTag('database_test_alter_add_join')) { $people_alias = $query->join('test', 'people', "test_task.pid=people.id"); $name_field = $query->addField('people', 'name', 'name'); $query->condition($people_alias . '.id', 2); } - + if ($query->hasTag('database_test_alter_change_conditional')) { $conditions =& $query->conditions(); $conditions[0]['value'] = 2; } - + if ($query->hasTag('database_test_alter_change_fields')) { $fields =& $query->getFields(); unset($fields['age']); } - + if ($query->hasTag('database_test_alter_change_expressions')) { $expressions =& $query->getExpressions(); $expressions['double_age']['expression'] = 'age*3'; - } + } } Index: modules/simpletest/tests/database_test.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.test,v retrieving revision 1.3 diff -u -p -r1.3 database_test.test --- modules/simpletest/tests/database_test.test 5 Sep 2008 09:25:52 -0000 1.3 +++ modules/simpletest/tests/database_test.test 9 Sep 2008 00:56:35 -0000 @@ -7,12 +7,12 @@ * PDO supports using a new instance of an arbitrary class for records * rather than just a stdClass or array. This class is for testing that * functionality. (See testQueryFetchClass() below) - */ + */ class FakeRecord { } /** * Base test class for databases. - * + * * Because all database tests share the same test data, we can centralize that * here. */ @@ -27,10 +27,10 @@ class DatabaseTestCase extends DrupalWeb $schema['test_one_blob'] = drupal_get_schema('test_one_blob'); $schema['test_two_blobs'] = drupal_get_schema('test_two_blobs'); $schema['test_task'] = drupal_get_schema('test_task'); - + $ret = array(); - - // This ends up being a test for table drop and create, too, which is + + // This ends up being a test for table drop and create, too, which is // nice. foreach ($schema as $name => $data) { if (db_table_exists($name)) { @@ -38,11 +38,11 @@ class DatabaseTestCase extends DrupalWeb } db_create_table($ret, $name, $data); } - + foreach ($schema as $name => $data) { $this->assertTrue(db_table_exists($name), t('Table @name created successfully.', array('@name' => $name))); } - + $this->addSampleData(); } catch (Exception $e) { @@ -53,7 +53,7 @@ class DatabaseTestCase extends DrupalWeb /** * Setup our sample data. * - * These are added using db_query(), since we're not trying to test the + * These are added using db_query(), since we're not trying to test the * INSERT operations here, just populate. */ function addSampleData() { @@ -69,38 +69,38 @@ class DatabaseTestCase extends DrupalWeb db_query("INSERT INTO {test_people} (name, age, job) VALUES ('Meredith', 30, 'Speaker')"); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $john, - ':task' => 'eat', + ':pid' => $john, + ':task' => 'eat', ':priority' => 3, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $john, - ':task' => 'sleep', + ':pid' => $john, + ':task' => 'sleep', ':priority' => 4, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $john, - ':task' => 'code', + ':pid' => $john, + ':task' => 'code', ':priority' => 1, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $george, - ':task' => 'sing', + ':pid' => $george, + ':task' => 'sing', ':priority' => 2, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $george, - ':task' => 'sleep', + ':pid' => $george, + ':task' => 'sleep', ':priority' => 2, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $paul, - ':task' => 'found new band', + ':pid' => $paul, + ':task' => 'found new band', ':priority' => 1, )); db_query("INSERT INTO {test_task} (pid, task, priority) VALUES (:pid, :task, :priority)", array( - ':pid' => $paul, - ':task' => 'perform at superbowl', + ':pid' => $paul, + ':task' => 'perform at superbowl', ':priority' => 3, )); } @@ -109,11 +109,11 @@ class DatabaseTestCase extends DrupalWeb /** * Test fetch actions, part 1. - * + * * We get timeout errors if we try to run too many tests at once. */ class DatabaseFetchTestCase extends DatabaseTestCase { - + function getInfo() { return array( 'name' => t('Fetch tests'), @@ -191,7 +191,7 @@ class DatabaseFetchTestCase extends Data /** * Test fetch actions, part 2. - * + * * We get timeout errors if we try to run too many tests at once. */ class DatabaseFetch2TestCase extends DatabaseTestCase { @@ -241,7 +241,7 @@ class DatabaseFetch2TestCase extends Dat /** * Confirm that we can fetch an entire column of a result set at once. - */ + */ function testQueryFetchCol() { $records = array(); $result = db_query("SELECT name FROM {test} WHERE age > :age", array(':age' => 25)); @@ -276,7 +276,7 @@ class DatabaseInsertTestCase extends Dat function testSimpleInsert() { try { $num_records_before = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); - + $query = db_insert('test'); $query->fields(array( 'name' => 'Yoko', @@ -286,7 +286,7 @@ class DatabaseInsertTestCase extends Dat $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); $this->assertIdentical($num_records_before + 1, (int)$num_records_after, t('Record inserts correctly.')); - + $saved_age = db_query("SELECT age FROM {test} WHERE name = :name", array(':name' => 'Yoko'))->fetchField(); $this->assertIdentical($saved_age, '29', t('Can retrieve after inserting.')); } @@ -299,26 +299,26 @@ class DatabaseInsertTestCase extends Dat * Test that we can insert multiple records in one query object. */ function testMultiInsert() { - try { + try { $num_records_before = (int) db_query("SELECT COUNT(*) FROM {test}")->fetchField(); - + $query = db_insert('test'); $query->fields(array( 'name' => 'Larry', 'age' => '30', )); - + // We should be able to specify values in any order if named. $query->values(array( 'age' => '31', 'name' => 'Curly', )); - + // We should be able to say "use the field order". // This is not the recommended mechanism for most cases, but it should work. $query->values(array('Moe', '32')); $query->execute(); - + $num_records_after = (int) db_query("SELECT COUNT(*) FROM {test}")->fetchField(); $this->assertIdentical($num_records_before + 3, $num_records_after, t('Record inserts correctly.')); $saved_age = db_query("SELECT age FROM {test} WHERE name = :name", array(':name' => 'Larry'))->fetchField(); @@ -327,7 +327,7 @@ class DatabaseInsertTestCase extends Dat $this->assertIdentical($saved_age, '31', t('Can retrieve by name.')); $saved_age = db_query("SELECT age FROM {test} WHERE name = :name", array(':name' => 'Moe'))->fetchField(); $this->assertIdentical($saved_age, '32', t('Can retrieve by name.')); - } + } catch (Exception $e) { $this->assertTrue(FALSE, $e->getMessage()); } @@ -339,26 +339,26 @@ class DatabaseInsertTestCase extends Dat function testRepeatedInsert() { try { $num_records_before = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); - + $query = db_insert('test'); - + $query->fields(array( 'name' => 'Larry', 'age' => '30', )); $query->execute(); // This should run the insert, but leave the fields intact. - + // We should be able to specify values in any order if named. $query->values(array( 'age' => '31', 'name' => 'Curly', )); $query->execute(); - + // We should be able to say "use the field order". $query->values(array('Moe', '32')); $query->execute(); - + $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); $this->assertIdentical((int) $num_records_before + 3, (int) $num_records_after, t('Record inserts correctly.')); $saved_age = db_query("SELECT age FROM {test} WHERE name = :name", array(':name' => 'Larry'))->fetchField(); @@ -367,7 +367,7 @@ class DatabaseInsertTestCase extends Dat $this->assertIdentical($saved_age, '31', t('Can retrieve by name.')); $saved_age = db_query("SELECT age FROM {test} WHERE name = :name", array(':name' => 'Moe'))->fetchField(); $this->assertIdentical($saved_age, '32', t('Can retrieve by name.')); - } + } catch (Exception $e) { $this->assertTrue(FALSE, $e->getMessage()); } @@ -399,9 +399,9 @@ class DatabaseInsertTestCase extends Dat 'age' => '30', )) ->execute(); - + $this->assertIdentical($id, '5', t('Auto-increment ID returned successfully.')); - } + } catch (Exception $e) { $this->assertTrue(FALSE, $e->getMessage()); } @@ -438,7 +438,7 @@ class DatabaseInsertLOBTestCase extends */ function testInsertMultipleBlob() { $id = db_insert('test_two_blobs')->fields(array( - 'blob1' => 'This is', + 'blob1' => 'This is', 'blob2' => 'a test', )) ->execute(); @@ -460,7 +460,7 @@ class DatabaseInsertDefaultsTestCase ext 'group' => t('Database'), ); } - + /** * Test that we can run a query that is "default values for everything". */ @@ -468,9 +468,9 @@ class DatabaseInsertDefaultsTestCase ext try { $query = db_insert('test')->useDefaults(array('job')); $id = $query->execute(); - + $schema = drupal_get_schema('test'); - + $job = db_query("SELECT job FROM {test} WHERE id = :id", array(':id' => $id))->fetchField(); $this->assertEqual($job, $schema['fields']['job']['default'], t('Default field value is set.')); } @@ -486,9 +486,9 @@ class DatabaseInsertDefaultsTestCase ext try { $query = db_insert('test')->fields(array('name' => 'Bob'))->useDefaults(array('job')); $id = $query->execute(); - + $schema = drupal_get_schema('test'); - + $job = db_query("SELECT job FROM {test} WHERE id = :id", array(':id' => $id))->fetchField(); $this->assertEqual($job, $schema['fields']['job']['default'], t('Default field value is set.')); } @@ -521,7 +521,7 @@ class DatabaseUpdateTestCase extends Dat $saved_name = db_query("SELECT name FROM {test} WHERE id = :id", array(':id' => 1))->fetchField(); $this->assertIdentical($saved_name, 'Tiffany', t('Updated name successfully.')); } - + /** * Confirm that we can update a multiple records successfully. */ @@ -633,7 +633,7 @@ class DatabaseUpdateComplexTestCase exte ->condition('age', array(25, 26), 'BETWEEN') ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - + $num_matches = db_query("SELECT count(*) FROM {test} WHERE job = :job", array(':job' => 'Musician'))->fetchField(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -668,10 +668,10 @@ class DatabaseUpdateComplexTestCase exte ->expression('age', 'age + :age',array(':age' => 4)) ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - + $num_matches = db_query("SELECT count(*) FROM {test} WHERE job = :job", array(':job' => 'Musician'))->fetchField(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); - + $person = db_query("SELECT * FROM {test} WHERE name = :name", array(':name' => 'Ringo'))->fetch(); $this->assertEqual($person->name, 'Ringo', t('Name set correctly.')); $this->assertEqual($person->age, $before_age + 4, t('Age set correctly.')); @@ -712,13 +712,13 @@ class DatabaseUpdateLOBTestCase extends $r = db_fetch_array($res); $this->assertTrue($r['blob1'] === $data, t('Can update a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r)))); } - + /** * Confirm that we can update two blob columns in the same table. */ function testUpdateMultipleBlob() { $id = db_insert('test_two_blobs')->fields(array( - 'blob1' => 'This is', + 'blob1' => 'This is', 'blob2' => 'a test') ) ->execute(); @@ -782,18 +782,18 @@ class DatabaseMergeTestCase extends Data function testMergeInsert() { try{ $num_records_before = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); - + db_merge('test_people') ->key(array('job' => 'Presenter')) ->fields(array( - 'age' => 31, + 'age' => 31, 'name' => 'Tiffany', )) ->execute(); $num_records_after = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); $this->assertEqual($num_records_before + 1, $num_records_after, t('Merge inserted properly.')); - + $person = db_query("SELECT * FROM {test_people} WHERE job = :job", array(':job' => 'Presenter'))->fetch(); $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.')); $this->assertEqual($person->age, 31, t('Age set correctly.')); @@ -814,7 +814,7 @@ class DatabaseMergeTestCase extends Data $num_records_after = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); - + $person = db_query("SELECT * FROM {test_people} WHERE job = :job", array(':job' => 'Speaker'))->fetch(); $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.')); $this->assertEqual($person->age, 31, t('Age set correctly.')); @@ -831,7 +831,7 @@ class DatabaseMergeTestCase extends Data $num_records_after = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); - + $person = db_query("SELECT * FROM {test_people} WHERE job = :job", array(':job' => 'Speaker'))->fetch(); $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.')); $this->assertEqual($person->age, 30, t('Age skipped correctly.')); @@ -848,7 +848,7 @@ class DatabaseMergeTestCase extends Data $num_records_after = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); - + $person = db_query("SELECT * FROM {test_people} WHERE job = :job", array(':job' => 'Speaker'))->fetch(); $this->assertEqual($person->name, 'Joe', t('Name set correctly.')); $this->assertEqual($person->age, 30, t('Age skipped correctly.')); @@ -863,7 +863,7 @@ class DatabaseMergeTestCase extends Data $age_before = db_query("SELECT age FROM {test_people} WHERE job = 'Speaker'")->fetchField(); - // This is a very contrived example, as I have no idea why you'd want to + // This is a very contrived example, as I have no idea why you'd want to // change age this way, but that's beside the point. // Note that we are also double-setting age here, once as a literal and // once as an expression. This test will only pass if the expression wins, @@ -876,7 +876,7 @@ class DatabaseMergeTestCase extends Data $num_records_after = db_query("SELECT COUNT(*) FROM {test_people}")->fetchField(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); - + $person = db_query("SELECT * FROM {test_people} WHERE job = :job", array(':job' => 'Speaker'))->fetch(); $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.')); $this->assertEqual($person->age, $age_before + 4, t('Age updated correctly.')); @@ -907,12 +907,12 @@ class DatabaseSelectTestCase extends Dat $name_field = $query->addField('test', 'name'); $age_field = $query->addField('test', 'age', 'age'); $result = $query->execute(); - + $num_records = 0; foreach ($result as $record) { $num_records++; } - + $this->assertEqual($num_records, 4, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -929,11 +929,11 @@ class DatabaseSelectTestCase extends Dat $age_field = $query->addField('test', 'age', 'age'); $query->condition('age', 27); $result = $query->execute(); - + // Check that the aliases are being created the way we want. $this->assertEqual($name_field, 'test_name', t('Name field alias is correct.')); $this->assertEqual($age_field, 'age', t('Age field alias is correct.')); - + // Ensure that we got the right record. $record = $result->fetch(); $this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.')); @@ -949,11 +949,11 @@ class DatabaseSelectTestCase extends Dat $age_field = $query->addExpression("age*2", 'double_age'); $query->condition('age', 27); $result = $query->execute(); - + // Check that the aliases are being created the way we want. $this->assertEqual($name_field, 'test_name', t('Name field alias is correct.')); $this->assertEqual($age_field, 'double_age', t('Age field alias is correct.')); - + // Ensure that we got the right record. $record = $result->fetch(); $this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.')); @@ -984,7 +984,7 @@ class DatabaseSelectOrderedTestCase exte $age_field = $query->addField('test', 'age', 'age'); $query->orderBy($age_field); $result = $query->execute(); - + $num_records = 0; $last_age = 0; foreach ($result as $record) { @@ -992,7 +992,7 @@ class DatabaseSelectOrderedTestCase exte $this->assertTrue($record->age >= $last_age, t('Results returned in correct order.')); $last_age = $record->age; } - + $this->assertEqual($num_records, 4, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1012,7 +1012,7 @@ class DatabaseSelectOrderedTestCase exte $query->orderBy($job_field); $query->orderBy($age_field); $result = $query->execute(); - + $num_records = 0; $expected = array( array('Ringo', 28, 'Drummer'), @@ -1047,7 +1047,7 @@ class DatabaseSelectOrderedTestCase exte $age_field = $query->addField('test', 'age', 'age'); $query->orderBy($age_field, 'DESC'); $result = $query->execute(); - + $num_records = 0; $last_age = 100000000; foreach ($result as $record) { @@ -1055,7 +1055,7 @@ class DatabaseSelectOrderedTestCase exte $this->assertTrue($record->age <= $last_age, t('Results returned in correct order.')); $last_age = $record->age; } - + $this->assertEqual($num_records, 4, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1087,10 +1087,10 @@ class DatabaseSelectComplexTestCase exte $name_field = $query->addField($people_alias, 'name', 'name'); $task_field = $query->addField('t', 'task', 'task'); $priority_field = $query->addField('t', 'priority', 'priority'); - + $query->orderBy($priority_field); $result = $query->execute(); - + $num_records = 0; $last_priority = 0; foreach ($result as $record) { @@ -1099,7 +1099,7 @@ class DatabaseSelectComplexTestCase exte $this->assertNotEqual($record->$name_field, 'Ringo', t('Taskless person not selected.')); $last_priority = $record->$priority_field; } - + $this->assertEqual($num_records, 7, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1117,19 +1117,19 @@ class DatabaseSelectComplexTestCase exte $name_field = $query->addField('p', 'name', 'name'); $task_field = $query->addField($people_alias, 'task', 'task'); $priority_field = $query->addField($people_alias, 'priority', 'priority'); - + $query->orderBy($name_field); $result = $query->execute(); - + $num_records = 0; $last_name = 0; - + foreach ($result as $record) { $num_records++; $this->assertTrue(strcmp($record->$name_field, $last_name) >= 0, t('Results returned in correct order.')); $last_priority = $record->$name_field; } - + $this->assertEqual($num_records, 8, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1148,7 +1148,7 @@ class DatabaseSelectComplexTestCase exte $query->orderBy($count_field); $query->groupBy($task_field); $result = $query->execute(); - + $num_records = 0; $last_count = 0; $records = array(); @@ -1158,7 +1158,7 @@ class DatabaseSelectComplexTestCase exte $last_count = $record->$count_field; $records[$record->$task_field] = $record->$count_field; } - + $correct_results = array( 'eat' => 1, 'sleep' => 2, @@ -1166,7 +1166,7 @@ class DatabaseSelectComplexTestCase exte 'found new band' => 1, 'perform at superbowl' => 1, ); - + foreach ($correct_results as $task => $count) { $this->assertEqual($records[$task], $count, t("Correct number of '@task' records found.", array('@task' => $task))); } @@ -1190,7 +1190,7 @@ class DatabaseSelectComplexTestCase exte $query->groupBy($task_field); $query->havingCondition('COUNT(task)', 2, '>='); $result = $query->execute(); - + $num_records = 0; $last_count = 0; $records = array(); @@ -1201,11 +1201,11 @@ class DatabaseSelectComplexTestCase exte $last_count = $record->$count_field; $records[$record->$task_field] = $record->$count_field; } - + $correct_results = array( 'sleep' => 2, ); - + foreach ($correct_results as $task => $count) { $this->assertEqual($records[$task], $count, t("Correct number of '@task' records found.", array('@task' => $task))); } @@ -1227,12 +1227,12 @@ class DatabaseSelectComplexTestCase exte $age_field = $query->addField('test', 'age', 'age'); $query->range(0, 2); $result = $query->execute(); - + $num_records = 0; foreach ($result as $record) { $num_records++; } - + $this->assertEqual($num_records, 2, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1249,12 +1249,12 @@ class DatabaseSelectComplexTestCase exte $task_field = $query->addField('test_task', 'task'); $query->distinct(); $result = $query->execute(); - + $num_records = 0; foreach ($result as $record) { $num_records++; } - + $this->assertEqual($num_records, 6, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1271,11 +1271,11 @@ class DatabaseSelectComplexTestCase exte $name_field = $query->addField('test', 'name'); $age_field = $query->addField('test', 'age', 'age'); $query->orderBy('name'); - + $count = $query->countQuery()->execute()->fetchField(); - + $this->assertEqual($count, 4, t('Counted the correct number of records.')); - + // Now make sure we didn't break the original query! We should still have // all of the fields we asked for. $record = $query->execute()->fetch(); @@ -1290,7 +1290,7 @@ class DatabaseSelectComplexTestCase exte /** * Select tagging tests. - * + * * Tags are a way to flag queries for alter hooks so they know * what type of query it is, such as "node_access". */ @@ -1312,9 +1312,9 @@ class DatabaseTaggingTestCase extends Da $query = db_select('test'); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); - + $query->addTag('test'); - + $this->assertTrue($query->hasTag('test'), t('hasTag() returned true.')); $this->assertFalse($query->hasTag('other'), t('hasTag() returned false.')); } @@ -1331,10 +1331,10 @@ class DatabaseTaggingTestCase extends Da $query = db_select('test'); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); - + $query->addTag('test'); $query->addTag('other'); - + $this->assertTrue($query->hasAllTags('test', 'other'), t('hasAllTags() returned true.')); $this->assertFalse($query->hasAllTags('test', 'stuff'), t('hasAllTags() returned false.')); } @@ -1351,9 +1351,9 @@ class DatabaseTaggingTestCase extends Da $query = db_select('test'); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); - + $query->addTag('test'); - + $this->assertTrue($query->hasAnyTag('test', 'other'), t('hasAnyTag() returned true.')); $this->assertFalse($query->hasAnyTag('other', 'stuff'), t('hasAnyTag() returned false.')); } @@ -1364,7 +1364,7 @@ class DatabaseTaggingTestCase extends Da /** * Test that we can attach meta data to a query object. - * + * * This is how we pass additional context to alter hooks. */ function testMetaData() { @@ -1372,17 +1372,17 @@ class DatabaseTaggingTestCase extends Da $query = db_select('test'); $query->addField('test', 'name'); $query->addField('test', 'age', 'age'); - + $data = array( 'a' => 'A', 'b' => 'B', ); - + $query->addMetaData('test', $data); - + $return = $query->getMetaData('test'); $this->assertEqual($data, $return, t('Corect metadata returned.')); - + $return = $query->getMetaData('nothere'); $this->assertNull($return, t('Non-existant key returned NULL.')); } @@ -1394,7 +1394,7 @@ class DatabaseTaggingTestCase extends Da /** * Select alter tests. - * + * * @see database_test_query_alter(). */ class DatabaseAlterTestCase extends DatabaseTestCase { @@ -1423,7 +1423,7 @@ class DatabaseAlterTestCase extends Data foreach ($result as $record) { $num_records++; } - + $this->assertEqual($num_records, 2, t('Returned the correct number of rows.')); } catch(Exception $e) { @@ -1445,9 +1445,9 @@ class DatabaseAlterTestCase extends Data $result = $query->execute(); $records = $result->fetchAll(); - + $this->assertEqual(count($records), 2, t('Returned the correct number of rows.')); - + $this->assertEqual($records[0]->name, 'George', t('Correct data retrieved.')); $this->assertEqual($records[0]->$tid_field, 4, t('Correct data retrieved.')); $this->assertEqual($records[0]->$task_field, 'sing', t('Correct data retrieved.')); @@ -1493,7 +1493,7 @@ class DatabaseAlterTestCase extends Data /** * Select alter tests, part 2. - * + * * @see database_test_query_alter(). */ class DatabaseAlter2TestCase extends DatabaseTestCase { @@ -1516,7 +1516,7 @@ class DatabaseAlter2TestCase extends Dat $age_field = $query->addField('test', 'age', 'age'); $query->orderBy('name'); $query->addTag('database_test_alter_change_fields'); - + $record = $query->execute()->fetch(); $this->assertEqual($record->$name_field, 'George', t('Correct data retrieved.')); $this->assertFalse(isset($record->$age_field), t('Age field not found, as intended.')); @@ -1537,7 +1537,7 @@ class DatabaseAlter2TestCase extends Dat $query->condition('age', 27); $query->addTag('database_test_alter_change_expressions'); $result = $query->execute(); - + // Ensure that we got the right record. $record = $result->fetch(); Index: modules/simpletest/tests/menu.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/menu.test,v retrieving revision 1.1 diff -u -p -r1.1 menu.test --- modules/simpletest/tests/menu.test 2 Sep 2008 19:23:02 -0000 1.1 +++ modules/simpletest/tests/menu.test 9 Sep 2008 00:56:35 -0000 @@ -25,7 +25,7 @@ class MenuIncTestCase extends DrupalWebT // Enable dummy module that implements hook_menu. parent::setUp('hook_menu'); } - + /** * Tests for menu_name parameter for hook_menu(). */ Index: modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.281 diff -u -p -r1.281 statistics.module --- modules/statistics/statistics.module 6 Sep 2008 08:36:21 -0000 1.281 +++ modules/statistics/statistics.module 9 Sep 2008 00:56:35 -0000 @@ -68,12 +68,12 @@ function statistics_exit() { // Log this page access. db_insert('accesslog')->fields(array( 'title' => strip_tags(drupal_get_title()), - 'path' => $_GET['q'], - 'url' => $_SERVER['HTTP_REFERER'], - 'hostname' => ip_address(), - 'uid' => $user->uid, - 'sid' => session_id(), - 'timer' => timer_read('page'), + 'path' => $_GET['q'], + 'url' => $_SERVER['HTTP_REFERER'], + 'hostname' => ip_address(), + 'uid' => $user->uid, + 'sid' => session_id(), + 'timer' => timer_read('page'), 'timestamp' => $_SERVER['REQUEST_TIME'], ))->execute(); } Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.87 diff -u -p -r1.87 system.admin.inc --- modules/system/system.admin.inc 6 Sep 2008 08:36:21 -0000 1.87 +++ modules/system/system.admin.inc 9 Sep 2008 00:56:35 -0000 @@ -1781,7 +1781,7 @@ function system_status($check = FALSE) { } // MySQL import might have set the uid of the anonymous user to autoincrement // value. Let's try fixing it. See http://drupal.org/node/204411 - db_query("UPDATE {users} SET uid = uid - uid WHERE name = '' AND pass = '' AND status = 0"); + db_query("UPDATE {users} SET uid = uid - uid WHERE username = '' AND pass = '' AND status = 0"); return theme('status_report', $requirements); } Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.263 diff -u -p -r1.263 system.install --- modules/system/system.install 6 Sep 2008 08:36:21 -0000 1.263 +++ modules/system/system.install 9 Sep 2008 00:56:35 -0000 @@ -366,17 +366,17 @@ function system_install() { // uid 2 which is not what we want. So we insert the first user here, the // anonymous user. uid is 1 here for now, but very soon it will be changed // to 0. - db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', ''); + db_query("INSERT INTO {users} (name, username, mail) VALUES('%s', '%s', '%s')", '', '', ''); // We need some placeholders here as name and mail are uniques and data is // presumed to be a serialized array. Install will change uid 1 immediately // anyways. So we insert the superuser here, the uid is 2 here for now, but // very soon it will be changed to 1. - db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', $_SERVER['REQUEST_TIME'], serialize(array())); + db_query("INSERT INTO {users} (name, username, mail, created, data) VALUES('%s', '%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', 'placeholder-for-uid-1', $_SERVER['REQUEST_TIME'], serialize(array())); // This sets the above two users uid 0 (anonymous). We avoid an explicit 0 // otherwise MySQL might insert the next auto_increment value. - db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", ''); + db_query("UPDATE {users} SET uid = uid - uid WHERE username = '%s'", ''); // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem. - db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1'); + db_query("UPDATE {users} SET uid = 1 WHERE username = '%s'", 'placeholder-for-uid-1'); // Built-in roles. db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user'); Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.11 diff -u -p -r1.11 system.test --- modules/system/system.test 28 Aug 2008 08:37:46 -0000 1.11 +++ modules/system/system.test 9 Sep 2008 00:56:35 -0000 @@ -323,7 +323,7 @@ class AdminMetaTagTestCase extends Drupa class PageNotFoundTestCase extends DrupalWebTestCase { protected $admin_user; - + /** * Implementation of getInfo(). */ @@ -334,7 +334,7 @@ class PageNotFoundTestCase extends Drupa 'group' => t('System') ); } - + /** * Implementation of setUp(). */ @@ -349,7 +349,7 @@ class PageNotFoundTestCase extends Drupa function testPageNotFound() { $this->drupalGet($this->randomName(10)); $this->assertText(t('Page not found'), t('Found the default 404 page')); - + $edit = array( 'title' => $this->randomName(10), 'body' => $this->randomName(100) @@ -358,24 +358,24 @@ class PageNotFoundTestCase extends Drupa // Use a custom 404 page. $this->drupalPost('admin/settings/error-reporting', array('site_404' => 'node/' . $node->nid), t('Save configuration')); - + $this->drupalGet($this->randomName(10)); $this->assertText($node->title, t('Found the custom 404 page')); - + // Logout and check that the user login block is not shown on custom 404 pages. $this->drupalLogout(); - + $this->drupalGet($this->randomName(10)); $this->assertText($node->title, t('Found the custom 404 page')); $this->assertNoText(t('User login'), t('Blocks are not shown on the custom 404 page')); - + // Log back in and remove the custom 404 page. $this->drupalLogin($this->admin_user); $this->drupalPost('admin/settings/error-reporting', array(), t('Reset to defaults')); // Logout and check that the user login block is not shown on default 404 pages. $this->drupalLogout(); - + $this->drupalGet($this->randomName(10)); $this->assertText(t('Page not found'), t('Found the default 404 page')); $this->assertNoText(t('User login'), t('Blocks are not shown on the default 404 page')); Index: modules/taxonomy/taxonomy.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v retrieving revision 1.12 diff -u -p -r1.12 taxonomy.pages.inc --- modules/taxonomy/taxonomy.pages.inc 21 Aug 2008 19:36:38 -0000 1.12 +++ modules/taxonomy/taxonomy.pages.inc 9 Sep 2008 00:56:36 -0000 @@ -120,7 +120,7 @@ function taxonomy_autocomplete($vid, $st $matches = array(); if ($last_string != '') { $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = :vid AND LOWER(t.name) LIKE LOWER(:last_string)", 't', 'tid'), array( - ':vid' => $vid, + ':vid' => $vid, ':last_string' => '%'. $last_string .'%', ), 0, 10); Index: modules/user/user.install =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.install,v retrieving revision 1.12 diff -u -p -r1.12 user.install --- modules/user/user.install 7 May 2008 19:34:24 -0000 1.12 +++ modules/user/user.install 9 Sep 2008 00:56:36 -0000 @@ -103,6 +103,13 @@ function user_schema() { 'default' => '', 'description' => t('Unique user name.'), ), + 'username' => array( + 'type' => 'varchar', + 'length' => 60, + 'not null' => TRUE, + 'default' => '', + 'description' => t('LOWER() version of {users}.name for query performance. This column should be used for WHERE, ORDER BY, etc in queries, instead of {users}.name '), + ), 'pass' => array( 'type' => 'varchar', 'length' => 128, @@ -197,7 +204,7 @@ function user_schema() { 'mail' => array('mail'), ), 'unique keys' => array( - 'name' => array('name'), + 'username' => array('username'), ), 'primary key' => array('uid'), ); @@ -292,6 +299,18 @@ function user_update_7001() { } /** + * Add username column and populate it with lowercased versions of existing names. + */ +function user_update_7002() { + $ret = array(); + db_add_field($ret, 'users', 'username', array('type' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => '')); + $ret[] = update_sql("UPDATE {users} SET username = LOWER(name)"); + db_add_unique_key($ret, 'users', 'username', array('username')); + db_drop_unique_key($ret, 'users', 'name'); + return $ret; +} + +/** * @} End of "defgroup user-updates-6.x-to-7.x" * The next series of updates should start at 8000. */ Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.919 diff -u -p -r1.919 user.module --- modules/user/user.module 8 Sep 2008 15:44:57 -0000 1.919 +++ modules/user/user.module 9 Sep 2008 00:56:36 -0000 @@ -166,6 +166,10 @@ function user_load($array = array()) { $query[] = "pass = '%s'"; $params[] = $value; } + else if ($key == 'username') { + $query[] = "username = LOWER('%s')"; + $params[] = $value; + } else { $query[]= "LOWER($key) = LOWER('%s')"; $params[] = $value; @@ -234,6 +238,11 @@ function user_save($account, $edit = arr unset($edit['pass']); } + // If username isn't set, populate it with name. + if (empty($edit['username'])) { + $edit['username'] = $edit['name']; + } + if (is_object($account) && $account->uid) { user_module_invoke('update', $edit, $account, $category); $data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $account->uid))); @@ -264,6 +273,15 @@ function user_save($account, $edit = arr return FALSE; } + // Ensure $user->username is lowercase if it's the same as $user->name. + // We use the database to do the lowercasing to ensure correct searches + // in case of any discrepencies in character handling between the + // database and PHP. + // LOWER() is also slightly faster than mb_strtolower() for this task. + if ($edit['username'] == $edit['name']) { + db_query("UPDATE {users} SET username = LOWER(username) WHERE uid = %d", $account->uid); + } + // Reload user roles if provided. if (isset($edit['roles']) && is_array($edit['roles'])) { db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid); @@ -317,6 +335,14 @@ function user_save($account, $edit = arr return FALSE; } + // Ensure $user->username is lowercase if it's the same as $user->name. + // We use the database to do the lowercasing to ensure that there are + // no discrepencies in collation handling between the database and PHP. + // LOWER() is also slightly faster than mb_strtolower() for this task. + if ($edit['username'] == $edit['name']) { + db_query("UPDATE {users} SET username = LOWER(username) WHERE uid = %d", $edit['uid']); + } + // Build the initial user object. $user = user_load(array('uid' => $edit['uid'])); @@ -560,8 +586,8 @@ function user_access($string, $account = * * @return boolean TRUE for blocked users, FALSE for active. */ -function user_is_blocked($name) { - $deny = db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER('%s')", $name)); +function user_is_blocked($username) { + $deny = db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND username = LOWER('%s')", $username)); return $deny; } @@ -606,13 +632,13 @@ function user_search($op = 'search', $ke $keys = preg_replace('!\*+!', '%', $keys); if (user_access('administer users')) { // Administrators can also search in the otherwise private email field. - $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys); + $result = pager_query("SELECT name, uid, mail FROM {users} WHERE username LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys); while ($account = db_fetch_object($result)) { $find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); } } else { - $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); + $result = pager_query("SELECT name, uid FROM {users} WHERE username LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); while ($account = db_fetch_object($result)) { $find[] = array('title' => $account->name, 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); } @@ -1307,7 +1333,7 @@ function user_authenticate($form_values $password = trim($form_values['pass']); // Name and pass keys are required. if (!empty($form_values['name']) && !empty($password)) { - $account = db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s' AND status = 1", $form_values['name'])); + $account = db_fetch_object(db_query("SELECT * FROM {users} WHERE username = LOWER('%s') AND status = 1", $form_values['name'])); if ($account) { // Allow alternate password hashing schemes. require_once variable_get('password_inc', './includes/password.inc'); @@ -1519,7 +1545,7 @@ function _user_edit_validate($uid, &$edi if ($error = user_validate_name($edit['name'])) { form_set_error('name', $error); } - else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) { + else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND username = LOWER('%s')", $uid, $edit['name'])) > 0) { form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name']))); } } Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.16 diff -u -p -r1.16 user.pages.inc --- modules/user/user.pages.inc 6 Sep 2008 08:36:22 -0000 1.16 +++ modules/user/user.pages.inc 9 Sep 2008 00:56:36 -0000 @@ -12,7 +12,7 @@ function user_autocomplete($string = '') { $matches = array(); if ($string) { - $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", array(':name' => $string .'%'), 0, 10); + $result = db_query_range("SELECT name FROM {users} WHERE username LIKE LOWER(:name)", array(':name' => $string .'%'), 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); } Index: modules/user/user.test =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.test,v retrieving revision 1.12 diff -u -p -r1.12 user.test --- modules/user/user.test 6 Sep 2008 08:36:22 -0000 1.12 +++ modules/user/user.test 9 Sep 2008 00:56:36 -0000 @@ -39,7 +39,10 @@ class UserRegistrationTestCase extends D $this->assertTrue($user->uid > 0, t('User has valid user id.')); // Check user fields. - $this->assertEqual($user->name, $name, t('Username matches.')); + $this->assertEqual($user->name, $name, t('User name matches.')); + $name = db_result(db_query("SELECT LOWER(name) FROM {users} WHERE uid = %d", $user->uid)); + $username = db_result(db_query("SELECT username FROM {users} WHERE uid = %d", $user->uid)); + $this->assertEqual($name, $username, t('Username matches.')); $this->assertEqual($user->mail, $mail, t('E-mail address matches.')); $this->assertEqual($user->theme, '', t('Correct theme field.')); $this->assertEqual($user->signature, '', t('Correct signature field.')); @@ -50,6 +53,10 @@ class UserRegistrationTestCase extends D $this->assertEqual($user->picture, '', t('Correct picture field.')); $this->assertEqual($user->init, $mail, t('Correct init field.')); + // Attempt to register with a duplicate username. + $this->drupalPost('user/register', $edit, t('Create new account')); + $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name'])), t('Duplicate username registration prevented.')); + // Attempt to login with incorrect password. $edit = array(); $edit['name'] = $name; @@ -464,6 +471,68 @@ class UserPermissionsTestCase extends Dr } +class UserSearchTestCase extends DrupalWebTestCase { + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('User search'), + 'description' => t('Tests user integration with the search module.'), + 'group' => t('User') + ); + } + + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp('search'); + // Create users. + $this->normal_user = $this->drupalCreateUser(array('access user profiles', 'search content')); + $this->admin_user = $this->drupalCreateUser(array('administer users', 'search content')); + } + + function testUserSearch() { + // Register a new user for searching. + $edit = array(); + $edit['name'] = $name = $this->randomName(); + $edit['mail'] = $mail = $edit['name'] . '@example.com'; + $this->drupalPost('user/register', $edit, t('Create new account')); + $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), t('User registered successfully.')); + $this->drupalLogin($this->admin_user); + $this->drupalGet('search/user'); + $this->assertResponse(200, t('User search page exists.')); + + // Search for a username with 'administer users' permission. + $edit = array(); + $edit['keys'] = $name; + $this->drupalPost(NULL, $edit, t('Search')); + $this->assertRaw($name, t('Username search successful.')); + // Email address search. + $this->drupalGet('search/user'); + $edit = array(); + $edit['keys'] = $mail; + $this->drupalPost(NULL, $edit, t('Search')); + $this->assertRaw($name, t('Email search successful.')); + $this->drupalLogout(); + + // Search for a username with 'access user profiles' permission. + $this->drupalLogin($this->normal_user); + $this->drupalGet('search/user'); + $this->assertResponse(200, t('User search page exists.')); + $edit = array(); + $edit['keys'] = $name; + $this->drupalPost(NULL, $edit, t('Search')); + $this->assertRaw($name, t('Username search successful')); + // E-mail address search. + $edit = array(); + $edit['keys'] = $mail; + $this->drupalPost(NULL, $edit, t('Search')); + $this->assertRaw($name, t('Email search does not return results without appropriate permission')); + } +} + class UserAdminTestCase extends DrupalWebTestCase { /** * Implementation of getInfo(). @@ -494,7 +563,7 @@ class UserAdminTestCase extends DrupalWe $this->assertText($user_c->name, t('Found user C on admin users page')); $this->assertText($admin_user->name, t('Found Admin user on admin users page')); - // Filter the users by permission 'administer taxonomy'. + // Filter the users by permission 'administer taxonomy'. $edit = array(); $edit['filter'] = 'permission'; $edit['permission'] = 'administer taxonomy';