summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/common.test16
-rw-r--r--modules/simpletest/tests/database_test.test962
-rw-r--r--modules/simpletest/tests/file.test9
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.test14
4 files changed, 656 insertions, 345 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index e8e403330..cc4606951 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -2298,6 +2298,12 @@ class FormatDateUnitTest extends DrupalWebTestCase {
$edit = array('date_format' => $admin_date_format);
$this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+ // Add a new date format which just differs in the case.
+ $admin_date_format_uppercase = 'j M Y';
+ $edit = array('date_format' => $admin_date_format_uppercase);
+ $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+ $this->assertText(t('Custom date format added.'));
+
// Add new date type.
$edit = array(
'date_type' => 'Example Style',
@@ -2306,8 +2312,18 @@ class FormatDateUnitTest extends DrupalWebTestCase {
);
$this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type'));
+ // Add a second date format with a different case than the first.
+ $edit = array(
+ 'machine_name' => 'example_style_uppercase',
+ 'date_type' => 'Example Style Uppercase',
+ 'date_format' => $admin_date_format_uppercase,
+ );
+ $this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type'));
+ $this->assertText(t('New date type added successfully.'));
+
$timestamp = strtotime('2007-03-10T00:00:00+00:00');
$this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07', t('Test format_date() using an admin-defined date type.'));
+ $this->assertIdentical(format_date($timestamp, 'example_style_uppercase', '', 'America/Los_Angeles'), '9 Mar 2007', 'Test format_date() using an admin-defined date type with different case.');
$this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'medium'), t('Test format_date() defaulting to medium when $type not found.'));
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 6e1d15979..b58578e99 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -48,7 +48,7 @@ class DatabaseTestCase extends DrupalWebTestCase {
}
foreach ($schema as $name => $data) {
- $this->assertTrue(db_table_exists($name), t('Table @name created successfully.', array('@name' => $name)));
+ $this->assertTrue(db_table_exists($name), format_string('Table @name created successfully.', array('@name' => $name)));
}
}
@@ -191,25 +191,25 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
$db1 = Database::getConnection('default', 'default');
$db2 = Database::getConnection('slave', 'default');
- $this->assertNotNull($db1, t('default connection is a real connection object.'));
- $this->assertNotNull($db2, t('slave connection is a real connection object.'));
- $this->assertNotIdentical($db1, $db2, t('Each target refers to a different connection.'));
+ $this->assertNotNull($db1, 'default connection is a real connection object.');
+ $this->assertNotNull($db2, 'slave connection is a real connection object.');
+ $this->assertNotIdentical($db1, $db2, 'Each target refers to a different connection.');
// Try to open those targets another time, that should return the same objects.
$db1b = Database::getConnection('default', 'default');
$db2b = Database::getConnection('slave', 'default');
- $this->assertIdentical($db1, $db1b, t('A second call to getConnection() returns the same object.'));
- $this->assertIdentical($db2, $db2b, t('A second call to getConnection() returns the same object.'));
+ $this->assertIdentical($db1, $db1b, 'A second call to getConnection() returns the same object.');
+ $this->assertIdentical($db2, $db2b, 'A second call to getConnection() returns the same object.');
// Try to open an unknown target.
$unknown_target = $this->randomName();
$db3 = Database::getConnection($unknown_target, 'default');
- $this->assertNotNull($db3, t('Opening an unknown target returns a real connection object.'));
- $this->assertIdentical($db1, $db3, t('An unknown target opens the default connection.'));
+ $this->assertNotNull($db3, 'Opening an unknown target returns a real connection object.');
+ $this->assertIdentical($db1, $db3, 'An unknown target opens the default connection.');
// Try to open that unknown target another time, that should return the same object.
$db3b = Database::getConnection($unknown_target, 'default');
- $this->assertIdentical($db3, $db3b, t('A second call to getConnection() returns the same object.'));
+ $this->assertIdentical($db3, $db3b, 'A second call to getConnection() returns the same object.');
}
/**
@@ -227,7 +227,7 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
$db1 = Database::getConnection('default', 'default');
$db2 = Database::getConnection('slave', 'default');
- $this->assertIdentical($db1, $db2, t('Both targets refer to the same connection.'));
+ $this->assertIdentical($db1, $db2, 'Both targets refer to the same connection.');
}
/**
@@ -242,7 +242,7 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
$db2 = Database::getConnection('default', 'default');
// Opening a connection after closing it should yield an object different than the original.
- $this->assertNotIdentical($db1, $db2, t('Opening the default connection after it is closed returns a new object.'));
+ $this->assertNotIdentical($db1, $db2, 'Opening the default connection after it is closed returns a new object.');
}
/**
@@ -257,8 +257,8 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
// In the MySQL driver, the port can be different, so check individual
// options.
- $this->assertEqual($connection_info['default']['driver'], $connectionOptions['driver'], t('The default connection info driver matches the current connection options driver.'));
- $this->assertEqual($connection_info['default']['database'], $connectionOptions['database'], t('The default connection info database matches the current connection options database.'));
+ $this->assertEqual($connection_info['default']['driver'], $connectionOptions['driver'], 'The default connection info driver matches the current connection options driver.');
+ $this->assertEqual($connection_info['default']['database'], $connectionOptions['database'], 'The default connection info database matches the current connection options database.');
// Set up identical slave and confirm connection options are identical.
Database::addConnectionInfo('default', 'slave', $connection_info['default']);
@@ -267,7 +267,7 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
// Get a fresh copy of the default connection options.
$connectionOptions = $db->getConnectionOptions();
- $this->assertIdentical($connectionOptions, $connectionOptions2, t('The default and slave connection options are identical.'));
+ $this->assertIdentical($connectionOptions, $connectionOptions2, 'The default and slave connection options are identical.');
// Set up a new connection with different connection info.
$test = $connection_info['default'];
@@ -277,7 +277,46 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
// Get a fresh copy of the default connection options.
$connectionOptions = $db->getConnectionOptions();
- $this->assertNotEqual($connection_info['default']['database'], $connectionOptions['database'], t('The test connection info database does not match the current connection options database.'));
+ $this->assertNotEqual($connection_info['default']['database'], $connectionOptions['database'], 'The test connection info database does not match the current connection options database.');
+ }
+}
+
+/**
+ * Test cloning Select queries.
+ */
+class DatabaseSelectCloneTest extends DatabaseTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Select tests, cloning',
+ 'description' => 'Test cloning Select queries.',
+ 'group' => 'Database',
+ );
+ }
+
+ /**
+ * Test that subqueries as value within conditions are cloned properly.
+ */
+ function testSelectConditionSubQueryCloning() {
+ $subquery = db_select('test', 't');
+ $subquery->addField('t', 'id', 'id');
+ $subquery->condition('age', 28, '<');
+
+ $query = db_select('test', 't');
+ $query->addField('t', 'name', 'name');
+ $query->condition('id', $subquery, 'IN');
+
+ $clone = clone $query;
+ // Cloned query should not be altered by the following modification
+ // happening on original query.
+ $subquery->condition('age', 25, '>');
+
+ $clone_result = $clone->countQuery()->execute()->fetchField();
+ $query_result = $query->countQuery()->execute()->fetchField();
+
+ // Make sure the cloned query has not been modified
+ $this->assertEqual(3, $clone_result, 'The cloned query returns the expected number of rows');
+ $this->assertEqual(2, $query_result, 'The query returns the expected number of rows');
}
}
@@ -302,14 +341,14 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
function testQueryFetchDefault() {
$records = array();
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25));
- $this->assertTrue($result instanceof DatabaseStatementInterface, t('Result set is a Drupal statement object.'));
+ $this->assertTrue($result instanceof DatabaseStatementInterface, 'Result set is a Drupal statement object.');
foreach ($result as $record) {
$records[] = $record;
- $this->assertTrue(is_object($record), t('Record is an object.'));
- $this->assertIdentical($record->name, 'John', t('25 year old is John.'));
+ $this->assertTrue(is_object($record), 'Record is an object.');
+ $this->assertIdentical($record->name, 'John', '25 year old is John.');
}
- $this->assertIdentical(count($records), 1, t('There is only one record.'));
+ $this->assertIdentical(count($records), 1, 'There is only one record.');
}
/**
@@ -320,11 +359,11 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_OBJ));
foreach ($result as $record) {
$records[] = $record;
- $this->assertTrue(is_object($record), t('Record is an object.'));
- $this->assertIdentical($record->name, 'John', t('25 year old is John.'));
+ $this->assertTrue(is_object($record), 'Record is an object.');
+ $this->assertIdentical($record->name, 'John', '25 year old is John.');
}
- $this->assertIdentical(count($records), 1, t('There is only one record.'));
+ $this->assertIdentical(count($records), 1, 'There is only one record.');
}
/**
@@ -335,12 +374,12 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $record) {
$records[] = $record;
- if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
- $this->assertIdentical($record['name'], 'John', t('Record can be accessed associatively.'));
+ if ($this->assertTrue(is_array($record), 'Record is an array.')) {
+ $this->assertIdentical($record['name'], 'John', 'Record can be accessed associatively.');
}
}
- $this->assertIdentical(count($records), 1, t('There is only one record.'));
+ $this->assertIdentical(count($records), 1, 'There is only one record.');
}
/**
@@ -353,12 +392,12 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => 'FakeRecord'));
foreach ($result as $record) {
$records[] = $record;
- if ($this->assertTrue($record instanceof FakeRecord, t('Record is an object of class FakeRecord.'))) {
- $this->assertIdentical($record->name, 'John', t('25 year old is John.'));
+ if ($this->assertTrue($record instanceof FakeRecord, 'Record is an object of class FakeRecord.')) {
+ $this->assertIdentical($record->name, 'John', '25 year old is John.');
}
}
- $this->assertIdentical(count($records), 1, t('There is only one record.'));
+ $this->assertIdentical(count($records), 1, 'There is only one record.');
}
}
@@ -387,8 +426,8 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_NUM));
foreach ($result as $record) {
$records[] = $record;
- if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
- $this->assertIdentical($record[0], 'John', t('Record can be accessed numerically.'));
+ if ($this->assertTrue(is_array($record), 'Record is an array.')) {
+ $this->assertIdentical($record[0], 'John', 'Record can be accessed numerically.');
}
}
@@ -403,13 +442,13 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
$result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_BOTH));
foreach ($result as $record) {
$records[] = $record;
- if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
- $this->assertIdentical($record[0], 'John', t('Record can be accessed numerically.'));
- $this->assertIdentical($record['name'], 'John', t('Record can be accessed associatively.'));
+ if ($this->assertTrue(is_array($record), 'Record is an array.')) {
+ $this->assertIdentical($record[0], 'John', 'Record can be accessed numerically.');
+ $this->assertIdentical($record['name'], 'John', 'Record can be accessed associatively.');
}
}
- $this->assertIdentical(count($records), 1, t('There is only one record.'));
+ $this->assertIdentical(count($records), 1, 'There is only one record.');
}
/**
@@ -419,12 +458,12 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
$records = array();
$result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
$column = $result->fetchCol();
- $this->assertIdentical(count($column), 3, t('fetchCol() returns the right number of records.'));
+ $this->assertIdentical(count($column), 3, 'fetchCol() returns the right number of records.');
$result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
$i = 0;
foreach ($result as $record) {
- $this->assertIdentical($record->name, $column[$i++], t('Column matches direct accesss.'));
+ $this->assertIdentical($record->name, $column[$i++], 'Column matches direct accesss.');
}
}
}
@@ -456,9 +495,9 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
$query->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
- $this->assertIdentical($num_records_before + 1, (int) $num_records_after, t('Record inserts correctly.'));
+ $this->assertIdentical($num_records_before + 1, (int) $num_records_after, '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.'));
+ $this->assertIdentical($saved_age, '29', 'Can retrieve after inserting.');
}
/**
@@ -485,13 +524,13 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertIdentical($num_records_before + 3, $num_records_after, 'Record inserts correctly.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
- $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
- $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
- $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
/**
@@ -520,13 +559,13 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertIdentical((int) $num_records_before + 3, (int) $num_records_after, 'Record inserts correctly.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
- $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
- $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
- $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
/**
@@ -542,11 +581,11 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
->values(array('Moe', '32'))
->execute();
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
- $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
- $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '31', 'Can retrieve after inserting.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
- $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '32', 'Can retrieve after inserting.');
}
/**
@@ -560,7 +599,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
))
->execute();
- $this->assertIdentical($id, '5', t('Auto-increment ID returned successfully.'));
+ $this->assertIdentical($id, '5', 'Auto-increment ID returned successfully.');
}
/**
@@ -586,7 +625,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
->execute();
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
- $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}
}
@@ -608,12 +647,12 @@ class DatabaseInsertLOBTestCase extends DatabaseTestCase {
*/
function testInsertOneBlob() {
$data = "This is\000a test.";
- $this->assertTrue(strlen($data) === 15, t('Test data contains a NULL.'));
+ $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
$id = db_insert('test_one_blob')
->fields(array('blob1' => $data))
->execute();
$r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
- $this->assertTrue($r['blob1'] === $data, t('Can insert a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
+ $this->assertTrue($r['blob1'] === $data, format_string('Can insert a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
}
/**
@@ -627,7 +666,7 @@ class DatabaseInsertLOBTestCase extends DatabaseTestCase {
))
->execute();
$r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
- $this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', t('Can insert multiple blobs per row.'));
+ $this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', 'Can insert multiple blobs per row.');
}
}
@@ -654,7 +693,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}
/**
@@ -666,13 +705,13 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase {
try {
$result = db_insert('test')->execute();
// This is only executed if no exception has been thrown.
- $this->fail(t('Expected exception NoFieldsException has not been thrown.'));
+ $this->fail('Expected exception NoFieldsException has not been thrown.');
} catch (NoFieldsException $e) {
- $this->pass(t('Expected exception NoFieldsException has been thrown.'));
+ $this->pass('Expected exception NoFieldsException has been thrown.');
}
$num_records_after = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField();
- $this->assertIdentical($num_records_before, $num_records_after, t('Do nothing as no fields are specified.'));
+ $this->assertIdentical($num_records_before, $num_records_after, 'Do nothing as no fields are specified.');
}
/**
@@ -687,7 +726,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
}
}
@@ -712,10 +751,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('name' => 'Tiffany'))
->condition('id', 1)
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, 'Updated 1 record.');
$saved_name = db_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 1))->fetchField();
- $this->assertIdentical($saved_name, 'Tiffany', t('Updated name successfully.'));
+ $this->assertIdentical($saved_name, 'Tiffany', 'Updated name successfully.');
}
/**
@@ -727,10 +766,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('age' => NULL))
->condition('name', 'Kermit')
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, 'Updated 1 record.');
$saved_age = db_query('SELECT age FROM {test_null} WHERE name = :name', array(':name' => 'Kermit'))->fetchField();
- $this->assertNull($saved_age, t('Updated name successfully.'));
+ $this->assertNull($saved_age, 'Updated name successfully.');
}
/**
@@ -741,10 +780,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('job', 'Singer')
->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -755,10 +794,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('age', 26, '>')
->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -769,10 +808,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->where('age > :age', array(':age' => 26))
->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -784,10 +823,10 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->where('age > :age', array(':age' => 26))
->condition('name', 'Ringo');
$num_updated = $update->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, '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.'));
+ $this->assertIdentical($num_matches, '1', 'Updated fields successfully.');
}
/**
@@ -807,7 +846,21 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
$num_rows = db_update('test')
->expression('age', 'age * age')
->execute();
- $this->assertIdentical($num_rows, 3, t('Number of affected rows are returned.'));
+ $this->assertIdentical($num_rows, 3, 'Number of affected rows are returned.');
+ }
+
+ /**
+ * Confirm that we can update the primary key of a record successfully.
+ */
+ function testPrimaryKeyUpdate() {
+ $num_updated = db_update('test')
+ ->fields(array('id' => 42, 'name' => 'John'))
+ ->condition('id', 1)
+ ->execute();
+ $this->assertIdentical($num_updated, 1, 'Updated 1 record.');
+
+ $saved_name= db_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 42))->fetchField();
+ $this->assertIdentical($saved_name, 'John', 'Updated primary key successfully.');
}
}
@@ -835,10 +888,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->condition('name', 'Paul')
);
$num_updated = $update->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -849,10 +902,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('name', array('John', 'Paul'), 'IN')
->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -865,10 +918,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('name', array('John', 'Paul', 'George'), 'NoT IN')
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, '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.'));
+ $this->assertIdentical($num_matches, '1', 'Updated fields successfully.');
}
/**
@@ -879,10 +932,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('age', array(25, 26), 'BETWEEN')
->execute();
- $this->assertIdentical($num_updated, 2, t('Updated 2 records.'));
+ $this->assertIdentical($num_updated, 2, '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.'));
+ $this->assertIdentical($num_matches, '2', 'Updated fields successfully.');
}
/**
@@ -893,10 +946,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->condition('name', '%ge%', 'LIKE')
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, '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.'));
+ $this->assertIdentical($num_matches, '1', 'Updated fields successfully.');
}
/**
@@ -910,15 +963,15 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->fields(array('job' => 'Musician'))
->expression('age', 'age + :age', array(':age' => 4))
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, '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.'));
+ $this->assertIdentical($num_matches, '1', '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.'));
- $this->assertEqual($person->job, 'Musician', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Ringo', 'Name set correctly.');
+ $this->assertEqual($person->age, $before_age + 4, 'Age set correctly.');
+ $this->assertEqual($person->job, 'Musician', 'Job set correctly.');
$GLOBALS['larry_test'] = 0;
}
@@ -931,10 +984,10 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase {
->condition('name', 'Ringo')
->expression('age', 'age + :age', array(':age' => 4))
->execute();
- $this->assertIdentical($num_updated, 1, t('Updated 1 record.'));
+ $this->assertIdentical($num_updated, 1, 'Updated 1 record.');
$after_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
- $this->assertEqual($before_age + 4, $after_age, t('Age updated correctly'));
+ $this->assertEqual($before_age + 4, $after_age, 'Age updated correctly');
}
}
@@ -956,7 +1009,7 @@ class DatabaseUpdateLOBTestCase extends DatabaseTestCase {
*/
function testUpdateOneBlob() {
$data = "This is\000a test.";
- $this->assertTrue(strlen($data) === 15, t('Test data contains a NULL.'));
+ $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.');
$id = db_insert('test_one_blob')
->fields(array('blob1' => $data))
->execute();
@@ -968,7 +1021,7 @@ class DatabaseUpdateLOBTestCase extends DatabaseTestCase {
->execute();
$r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
- $this->assertTrue($r['blob1'] === $data, t('Can update a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
+ $this->assertTrue($r['blob1'] === $data, format_string('Can update a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
}
/**
@@ -988,7 +1041,7 @@ class DatabaseUpdateLOBTestCase extends DatabaseTestCase {
->execute();
$r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
- $this->assertTrue($r['blob1'] === 'and so' && $r['blob2'] === 'is this', t('Can update multiple blobs per row.'));
+ $this->assertTrue($r['blob1'] === 'and so' && $r['blob2'] === 'is this', 'Can update multiple blobs per row.');
}
}
@@ -1028,10 +1081,10 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase {
->condition('pid', $subquery, 'IN');
$num_deleted = $delete->execute();
- $this->assertEqual($num_deleted, 1, t("Deleted 1 record."));
+ $this->assertEqual($num_deleted, 1, "Deleted 1 record.");
$num_records_after = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.'));
+ $this->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.');
}
/**
@@ -1043,10 +1096,10 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase {
$num_deleted = db_delete('test')
->condition('id', 1)
->execute();
- $this->assertIdentical($num_deleted, 1, t('Deleted 1 record.'));
+ $this->assertIdentical($num_deleted, 1, 'Deleted 1 record.');
$num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.'));
+ $this->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.');
}
/**
@@ -1058,7 +1111,7 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase {
db_truncate('test')->execute();
$num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField();
- $this->assertEqual(0, $num_records_after, t('Truncate really deletes everything.'));
+ $this->assertEqual(0, $num_records_after, 'Truncate really deletes everything.');
}
}
@@ -1089,15 +1142,15 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
))
->execute();
- $this->assertEqual($result, MergeQuery::STATUS_INSERT, t('Insert status returned.'));
+ $this->assertEqual($result, MergeQuery::STATUS_INSERT, 'Insert status returned.');
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before + 1, $num_records_after, t('Merge inserted properly.'));
+ $this->assertEqual($num_records_before + 1, $num_records_after, '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.'));
- $this->assertEqual($person->job, 'Presenter', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
+ $this->assertEqual($person->age, 31, 'Age set correctly.');
+ $this->assertEqual($person->job, 'Presenter', 'Job set correctly.');
}
/**
@@ -1114,15 +1167,15 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
))
->execute();
- $this->assertEqual($result, MergeQuery::STATUS_UPDATE, t('Update status returned.'));
+ $this->assertEqual($result, MergeQuery::STATUS_UPDATE, 'Update status returned.');
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, '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.'));
- $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
+ $this->assertEqual($person->age, 31, 'Age set correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
}
/**
@@ -1138,12 +1191,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, '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.'));
- $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
+ $this->assertEqual($person->age, 30, 'Age skipped correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
}
/**
@@ -1164,12 +1217,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, '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.'));
- $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Joe', 'Name set correctly.');
+ $this->assertEqual($person->age, 30, 'Age skipped correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
}
/**
@@ -1193,12 +1246,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, '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.'));
- $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
+ $this->assertEqual($person->name, 'Tiffany', 'Name set correctly.');
+ $this->assertEqual($person->age, $age_before + 4, 'Age updated correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job set correctly.');
}
/**
@@ -1212,12 +1265,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->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.'));
+ $this->assertEqual($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
$person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Presenter'))->fetch();
- $this->assertEqual($person->name, '', t('Name set correctly.'));
- $this->assertEqual($person->age, 0, t('Age set correctly.'));
- $this->assertEqual($person->job, 'Presenter', t('Job set correctly.'));
+ $this->assertEqual($person->name, '', 'Name set correctly.');
+ $this->assertEqual($person->age, 0, 'Age set correctly.');
+ $this->assertEqual($person->job, 'Presenter', 'Job set correctly.');
}
/**
@@ -1231,12 +1284,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
- $this->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
- $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
- $this->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
+ $this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
+ $this->assertEqual($person->age, 30, 'Age skipped correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
db_merge('test_people')
->key(array('job' => 'Speaker'))
@@ -1244,12 +1297,12 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
- $this->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.'));
+ $this->assertEqual($num_records_before, $num_records_after, 'Merge skipped properly.');
$person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
- $this->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
- $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
- $this->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
+ $this->assertEqual($person->name, 'Meredith', 'Name skipped correctly.');
+ $this->assertEqual($person->age, 30, 'Age skipped correctly.');
+ $this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
}
/**
@@ -1266,10 +1319,10 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
->execute();
}
catch (InvalidMergeQueryException $e) {
- $this->pass(t('InvalidMergeQueryException thrown for invalid query.'));
+ $this->pass('InvalidMergeQueryException thrown for invalid query.');
return;
}
- $this->fail(t('No InvalidMergeQueryException thrown'));
+ $this->fail('No InvalidMergeQueryException thrown');
}
}
@@ -1300,7 +1353,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$num_records++;
}
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
/**
@@ -1320,8 +1373,8 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$query = (string)$query;
$expected = "/* Testing query comments */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
- $this->assertEqual($query, $expected, t('The flattened query contains the comment string.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
+ $this->assertEqual($query, $expected, 'The flattened query contains the comment string.');
}
/**
@@ -1341,8 +1394,8 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$query = (string)$query;
$expected = "/* Testing query comments SELECT nid FROM {node}; -- */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
- $this->assertEqual($query, $expected, t('The flattened query contains the sanitised comment string.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
+ $this->assertEqual($query, $expected, 'The flattened query contains the sanitised comment string.');
}
/**
@@ -1356,13 +1409,13 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$result = $query->execute();
// Check that the aliases are being created the way we want.
- $this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
- $this->assertEqual($age_field, 'age', t('Age field alias is correct.'));
+ $this->assertEqual($name_field, 'name', 'Name field alias is correct.');
+ $this->assertEqual($age_field, 'age', '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.'));
- $this->assertEqual($record->$age_field, 27, t('Fetched age is correct.'));
+ $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
+ $this->assertEqual($record->$age_field, 27, 'Fetched age is correct.');
}
/**
@@ -1376,13 +1429,13 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$result = $query->execute();
// Check that the aliases are being created the way we want.
- $this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
- $this->assertEqual($age_field, 'double_age', t('Age field alias is correct.'));
+ $this->assertEqual($name_field, 'name', 'Name field alias is correct.');
+ $this->assertEqual($age_field, 'double_age', '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.'));
- $this->assertEqual($record->$age_field, 27*2, t('Fetched age expression is correct.'));
+ $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
+ $this->assertEqual($record->$age_field, 27*2, 'Fetched age expression is correct.');
}
/**
@@ -1397,14 +1450,14 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$result = $query->execute();
// Check that the aliases are being created the way we want.
- $this->assertEqual($age_double_field, 'expression', t('Double age field alias is correct.'));
- $this->assertEqual($age_triple_field, 'expression_2', t('Triple age field alias is correct.'));
+ $this->assertEqual($age_double_field, 'expression', 'Double age field alias is correct.');
+ $this->assertEqual($age_triple_field, 'expression_2', 'Triple 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.'));
- $this->assertEqual($record->$age_double_field, 27*2, t('Fetched double age expression is correct.'));
- $this->assertEqual($record->$age_triple_field, 27*3, t('Fetched triple age expression is correct.'));
+ $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
+ $this->assertEqual($record->$age_double_field, 27*2, 'Fetched double age expression is correct.');
+ $this->assertEqual($record->$age_triple_field, 27*3, 'Fetched triple age expression is correct.');
}
/**
@@ -1417,17 +1470,17 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->execute()->fetchObject();
// Check that all fields we asked for are present.
- $this->assertNotNull($record->id, t('ID field is present.'));
- $this->assertNotNull($record->name, t('Name field is present.'));
- $this->assertNotNull($record->age, t('Age field is present.'));
- $this->assertNotNull($record->job, t('Job field is present.'));
+ $this->assertNotNull($record->id, 'ID field is present.');
+ $this->assertNotNull($record->name, 'Name field is present.');
+ $this->assertNotNull($record->age, 'Age field is present.');
+ $this->assertNotNull($record->job, 'Job field is present.');
// Ensure that we got the right record.
// Check that all fields we asked for are present.
- $this->assertEqual($record->id, 2, t('ID field has the correct value.'));
- $this->assertEqual($record->name, 'George', t('Name field has the correct value.'));
- $this->assertEqual($record->age, 27, t('Age field has the correct value.'));
- $this->assertEqual($record->job, 'Singer', t('Job field has the correct value.'));
+ $this->assertEqual($record->id, 2, 'ID field has the correct value.');
+ $this->assertEqual($record->name, 'George', 'Name field has the correct value.');
+ $this->assertEqual($record->age, 27, 'Age field has the correct value.');
+ $this->assertEqual($record->job, 'Singer', 'Job field has the correct value.');
}
/**
@@ -1440,17 +1493,17 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->execute()->fetchObject();
// Check that all fields we asked for are present.
- $this->assertNotNull($record->id, t('ID field is present.'));
- $this->assertNotNull($record->name, t('Name field is present.'));
- $this->assertNotNull($record->age, t('Age field is present.'));
- $this->assertNotNull($record->job, t('Job field is present.'));
+ $this->assertNotNull($record->id, 'ID field is present.');
+ $this->assertNotNull($record->name, 'Name field is present.');
+ $this->assertNotNull($record->age, 'Age field is present.');
+ $this->assertNotNull($record->job, 'Job field is present.');
// Ensure that we got the right record.
// Check that all fields we asked for are present.
- $this->assertEqual($record->id, 2, t('ID field has the correct value.'));
- $this->assertEqual($record->name, 'George', t('Name field has the correct value.'));
- $this->assertEqual($record->age, 27, t('Age field has the correct value.'));
- $this->assertEqual($record->job, 'Singer', t('Job field has the correct value.'));
+ $this->assertEqual($record->id, 2, 'ID field has the correct value.');
+ $this->assertEqual($record->name, 'George', 'Name field has the correct value.');
+ $this->assertEqual($record->age, 27, 'Age field has the correct value.');
+ $this->assertEqual($record->job, 'Singer', 'Job field has the correct value.');
}
/**
@@ -1464,8 +1517,8 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->isNull('age')
->execute()->fetchCol();
- $this->assertEqual(count($names), 1, t('Correct number of records found with NULL age.'));
- $this->assertEqual($names[0], 'Fozzie', t('Correct record returned for NULL age.'));
+ $this->assertEqual(count($names), 1, 'Correct number of records found with NULL age.');
+ $this->assertEqual($names[0], 'Fozzie', 'Correct record returned for NULL age.');
}
/**
@@ -1480,9 +1533,9 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->orderBy('name')
->execute()->fetchCol();
- $this->assertEqual(count($names), 2, t('Correct number of records found withNOT NULL age.'));
- $this->assertEqual($names[0], 'Gonzo', t('Correct record returned for NOT NULL age.'));
- $this->assertEqual($names[1], 'Kermit', t('Correct record returned for NOT NULL age.'));
+ $this->assertEqual(count($names), 2, 'Correct number of records found withNOT NULL age.');
+ $this->assertEqual($names[0], 'Gonzo', 'Correct record returned for NOT NULL age.');
+ $this->assertEqual($names[1], 'Kermit', 'Correct record returned for NOT NULL age.');
}
/**
@@ -1503,10 +1556,10 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$names = $query_1->execute()->fetchCol();
// Ensure we only get 2 records.
- $this->assertEqual(count($names), 2, t('UNION correctly discarded duplicates.'));
+ $this->assertEqual(count($names), 2, 'UNION correctly discarded duplicates.');
- $this->assertEqual($names[0], 'George', t('First query returned correct name.'));
- $this->assertEqual($names[1], 'Ringo', t('Second query returned correct name.'));
+ $this->assertEqual($names[0], 'George', 'First query returned correct name.');
+ $this->assertEqual($names[1], 'Ringo', 'Second query returned correct name.');
}
/**
@@ -1526,11 +1579,11 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$names = $query_1->execute()->fetchCol();
// Ensure we get all 3 records.
- $this->assertEqual(count($names), 3, t('UNION ALL correctly preserved duplicates.'));
+ $this->assertEqual(count($names), 3, 'UNION ALL correctly preserved duplicates.');
- $this->assertEqual($names[0], 'George', t('First query returned correct first name.'));
- $this->assertEqual($names[1], 'Ringo', t('Second query returned correct second name.'));
- $this->assertEqual($names[2], 'Ringo', t('Third query returned correct name.'));
+ $this->assertEqual($names[0], 'George', 'First query returned correct first name.');
+ $this->assertEqual($names[1], 'Ringo', 'Second query returned correct second name.');
+ $this->assertEqual($names[2], 'Ringo', 'Third query returned correct name.');
}
/**
@@ -1565,7 +1618,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->orderBy('id')
->execute()
->fetchCol();
- $this->assertEqual($ordered_ids, $expected_ids, t('A query without random ordering returns IDs in the correct order.'));
+ $this->assertEqual($ordered_ids, $expected_ids, 'A query without random ordering returns IDs in the correct order.');
// Now perform the same query, but instead choose a random ordering. We
// expect this to contain a differently ordered version of the original
@@ -1576,10 +1629,10 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->orderRandom()
->execute()
->fetchCol();
- $this->assertNotEqual($randomized_ids, $ordered_ids, t('A query with random ordering returns an unordered set of IDs.'));
+ $this->assertNotEqual($randomized_ids, $ordered_ids, 'A query with random ordering returns an unordered set of IDs.');
$sorted_ids = $randomized_ids;
sort($sorted_ids);
- $this->assertEqual($sorted_ids, $ordered_ids, t('After sorting the random list, the result matches the original query.'));
+ $this->assertEqual($sorted_ids, $ordered_ids, 'After sorting the random list, the result matches the original query.');
// Now perform the exact same query again, and make sure the order is
// different.
@@ -1589,10 +1642,10 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
->orderRandom()
->execute()
->fetchCol();
- $this->assertNotEqual($randomized_ids_second_set, $randomized_ids, t('Performing the query with random ordering a second time returns IDs in a different order.'));
+ $this->assertNotEqual($randomized_ids_second_set, $randomized_ids, 'Performing the query with random ordering a second time returns IDs in a different order.');
$sorted_ids_second_set = $randomized_ids_second_set;
sort($sorted_ids_second_set);
- $this->assertEqual($sorted_ids_second_set, $sorted_ids, t('After sorting the second random list, the result matches the sorted version of the first random list.'));
+ $this->assertEqual($sorted_ids_second_set, $sorted_ids, 'After sorting the second random list, the result matches the sorted version of the first random list.');
}
/**
@@ -1649,7 +1702,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// WHERE tt.task = 'code'
$people = $select->execute()->fetchCol();
- $this->assertEqual(count($people), 1, t('Returned the correct number of rows.'));
+ $this->assertEqual(count($people), 1, 'Returned the correct number of rows.');
}
}
@@ -1676,7 +1729,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// INNER JOIN test t ON t.id=tt.pid
$people = $select->execute()->fetchCol();
- $this->assertEqual(count($people), 1, t('Returned the correct number of rows.'));
+ $this->assertEqual(count($people), 1, 'Returned the correct number of rows.');
}
/**
@@ -1699,7 +1752,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// FROM test tt2
// WHERE tt2.pid IN (SELECT tt.pid AS pid FROM test_task tt WHERE tt.priority=1)
$people = $select->execute()->fetchCol();
- $this->assertEqual(count($people), 5, t('Returned the correct number of rows.'));
+ $this->assertEqual(count($people), 5, 'Returned the correct number of rows.');
}
/**
@@ -1723,7 +1776,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// INNER JOIN (SELECT tt.pid AS pid FROM test_task tt WHERE priority=1) tt ON t.id=tt.pid
$people = $select->execute()->fetchCol();
- $this->assertEqual(count($people), 2, t('Returned the correct number of rows.'));
+ $this->assertEqual(count($people), 2, 'Returned the correct number of rows.');
}
/**
@@ -1753,7 +1806,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// Ensure that we got the right record.
$record = $result->fetch();
- $this->assertEqual($record->name, 'George', t('Fetched name is correct using EXISTS query.'));
+ $this->assertEqual($record->name, 'George', 'Fetched name is correct using EXISTS query.');
}
/**
@@ -1783,7 +1836,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// Ensure that we got the right number of records.
$people = $query->execute()->fetchCol();
- $this->assertEqual(count($people), 3, t('NOT EXISTS query returned the correct results.'));
+ $this->assertEqual(count($people), 3, 'NOT EXISTS query returned the correct results.');
}
}
@@ -1814,11 +1867,11 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase {
$last_age = 0;
foreach ($result as $record) {
$num_records++;
- $this->assertTrue($record->age >= $last_age, t('Results returned in correct order.'));
+ $this->assertTrue($record->age >= $last_age, 'Results returned in correct order.');
$last_age = $record->age;
}
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
/**
@@ -1845,11 +1898,11 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase {
$num_records++;
foreach ($record as $kk => $col) {
if ($expected[$k][$kk] != $results[$k][$kk]) {
- $this->assertTrue(FALSE, t('Results returned in correct order.'));
+ $this->assertTrue(FALSE, 'Results returned in correct order.');
}
}
}
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
/**
@@ -1866,11 +1919,11 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase {
$last_age = 100000000;
foreach ($result as $record) {
$num_records++;
- $this->assertTrue($record->age <= $last_age, t('Results returned in correct order.'));
+ $this->assertTrue($record->age <= $last_age, 'Results returned in correct order.');
$last_age = $record->age;
}
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
}
@@ -1904,12 +1957,12 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$last_priority = 0;
foreach ($result as $record) {
$num_records++;
- $this->assertTrue($record->$priority_field >= $last_priority, t('Results returned in correct order.'));
- $this->assertNotEqual($record->$name_field, 'Ringo', t('Taskless person not selected.'));
+ $this->assertTrue($record->$priority_field >= $last_priority, 'Results returned in correct order.');
+ $this->assertNotEqual($record->$name_field, 'Ringo', 'Taskless person not selected.');
$last_priority = $record->$priority_field;
}
- $this->assertEqual($num_records, 7, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 7, 'Returned the correct number of rows.');
}
/**
@@ -1930,11 +1983,11 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
foreach ($result as $record) {
$num_records++;
- $this->assertTrue(strcmp($record->$name_field, $last_name) >= 0, t('Results returned in correct order.'));
+ $this->assertTrue(strcmp($record->$name_field, $last_name) >= 0, 'Results returned in correct order.');
$last_priority = $record->$name_field;
}
- $this->assertEqual($num_records, 8, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 8, 'Returned the correct number of rows.');
}
/**
@@ -1953,7 +2006,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$records = array();
foreach ($result as $record) {
$num_records++;
- $this->assertTrue($record->$count_field >= $last_count, t('Results returned in correct order.'));
+ $this->assertTrue($record->$count_field >= $last_count, 'Results returned in correct order.');
$last_count = $record->$count_field;
$records[$record->$task_field] = $record->$count_field;
}
@@ -1967,10 +2020,10 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
);
foreach ($correct_results as $task => $count) {
- $this->assertEqual($records[$task], $count, t("Correct number of '@task' records found.", array('@task' => $task)));
+ $this->assertEqual($records[$task], $count, format_string("Correct number of '@task' records found.", array('@task' => $task)));
}
- $this->assertEqual($num_records, 6, t('Returned the correct number of total rows.'));
+ $this->assertEqual($num_records, 6, 'Returned the correct number of total rows.');
}
/**
@@ -1990,8 +2043,8 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$records = array();
foreach ($result as $record) {
$num_records++;
- $this->assertTrue($record->$count_field >= 2, t('Record has the minimum count.'));
- $this->assertTrue($record->$count_field >= $last_count, t('Results returned in correct order.'));
+ $this->assertTrue($record->$count_field >= 2, 'Record has the minimum count.');
+ $this->assertTrue($record->$count_field >= $last_count, 'Results returned in correct order.');
$last_count = $record->$count_field;
$records[$record->$task_field] = $record->$count_field;
}
@@ -2001,10 +2054,10 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
);
foreach ($correct_results as $task => $count) {
- $this->assertEqual($records[$task], $count, t("Correct number of '@task' records found.", array('@task' => $task)));
+ $this->assertEqual($records[$task], $count, format_string("Correct number of '@task' records found.", array('@task' => $task)));
}
- $this->assertEqual($num_records, 1, t('Returned the correct number of total rows.'));
+ $this->assertEqual($num_records, 1, 'Returned the correct number of total rows.');
}
/**
@@ -2022,7 +2075,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$num_records++;
}
- $this->assertEqual($num_records, 2, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 2, 'Returned the correct number of rows.');
}
/**
@@ -2039,7 +2092,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$num_records++;
}
- $this->assertEqual($num_records, 6, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 6, 'Returned the correct number of rows.');
}
/**
@@ -2053,13 +2106,13 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$count = $query->countQuery()->execute()->fetchField();
- $this->assertEqual($count, 4, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 4, '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();
- $this->assertEqual($record->$name_field, 'George', t('Correct data retrieved.'));
- $this->assertEqual($record->$age_field, 27, t('Correct data retrieved.'));
+ $this->assertEqual($record->$name_field, 'George', 'Correct data retrieved.');
+ $this->assertEqual($record->$age_field, 27, 'Correct data retrieved.');
}
function testHavingCountQuery() {
@@ -2070,7 +2123,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$query->addField('test', 'age');
$query->addExpression('age + 1');
$count = count($query->execute()->fetchCol());
- $this->assertEqual($count, 4, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 4, 'Counted the correct number of records.');
}
/**
@@ -2085,20 +2138,20 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
// Check that the 'all_fields' statement is handled properly.
$tables = $query->getTables();
- $this->assertEqual($tables['test']['all_fields'], 1, t('Query correctly sets \'all_fields\' statement.'));
+ $this->assertEqual($tables['test']['all_fields'], 1, 'Query correctly sets \'all_fields\' statement.');
$tables = $count->getTables();
- $this->assertFalse(isset($tables['test']['all_fields']), t('Count query correctly unsets \'all_fields\' statement.'));
+ $this->assertFalse(isset($tables['test']['all_fields']), 'Count query correctly unsets \'all_fields\' statement.');
// Check that the ordering clause is handled properly.
$orderby = $query->getOrderBy();
- $this->assertEqual($orderby['name'], 'ASC', t('Query correctly sets ordering clause.'));
+ $this->assertEqual($orderby['name'], 'ASC', 'Query correctly sets ordering clause.');
$orderby = $count->getOrderBy();
- $this->assertFalse(isset($orderby['name']), t('Count query correctly unsets ordering caluse.'));
+ $this->assertFalse(isset($orderby['name']), 'Count query correctly unsets ordering caluse.');
// Make sure that the count query works.
$count = $count->execute()->fetchField();
- $this->assertEqual($count, 4, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 4, 'Counted the correct number of records.');
}
@@ -2113,11 +2166,11 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
// records in the {test} table).
$query = db_select('test');
$query->fields('test', array('fail'));
- $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), t('Count Query removed fields'));
+ $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), 'Count Query removed fields');
$query = db_select('test');
$query->addExpression('fail');
- $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), t('Count Query removed expressions'));
+ $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), 'Count Query removed expressions');
}
/**
@@ -2130,7 +2183,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$count = $query->countQuery()->execute()->fetchField();
- $this->assertEqual($count, 6, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 6, 'Counted the correct number of records.');
}
/**
@@ -2143,7 +2196,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$count = $query->countQuery()->execute()->fetchField();
- $this->assertEqual($count, 3, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 3, 'Counted the correct number of records.');
// Use a column alias as, without one, the query can succeed for the wrong
// reason.
@@ -2155,7 +2208,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$count = $query->countQuery()->execute()->fetchField();
- $this->assertEqual($count, 3, t('Counted the correct number of records.'));
+ $this->assertEqual($count, 3, 'Counted the correct number of records.');
}
/**
@@ -2172,7 +2225,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$query->condition(db_or()->condition('age', 26)->condition('age', 27));
$job = $query->execute()->fetchField();
- $this->assertEqual($job, 'Songwriter', t('Correct data retrieved.'));
+ $this->assertEqual($job, 'Songwriter', 'Correct data retrieved.');
}
/**
@@ -2185,8 +2238,8 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$query->addField($alias, 'job', 'otherjob');
$query->where("$alias.name <> test.name");
$crowded_job = $query->execute()->fetch();
- $this->assertEqual($crowded_job->job, $crowded_job->otherjob, t('Correctly joined same table twice.'));
- $this->assertNotEqual($crowded_job->name, $crowded_job->othername, t('Correctly joined same table twice.'));
+ $this->assertEqual($crowded_job->job, $crowded_job->otherjob, 'Correctly joined same table twice.');
+ $this->assertNotEqual($crowded_job->name, $crowded_job->othername, 'Correctly joined same table twice.');
}
}
@@ -2251,7 +2304,7 @@ class DatabaseSelectComplexTestCase2 extends DatabaseTestCase {
// Verify that the string only has one copy of condition placeholder 0.
$pos = strpos($str, 'db_condition_placeholder_0', 0);
$pos2 = strpos($str, 'db_condition_placeholder_0', $pos + 1);
- $this->assertFalse($pos2, "Condition placeholder is not repeated");
+ $this->assertFalse($pos2, 'Condition placeholder is not repeated.');
}
}
@@ -2295,7 +2348,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
$correct_number = $count - ($limit * $page);
}
- $this->assertEqual(count($data->names), $correct_number, t('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
+ $this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
}
}
@@ -2329,7 +2382,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
$correct_number = $count - ($limit * $page);
}
- $this->assertEqual(count($data->names), $correct_number, t('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
+ $this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
}
}
@@ -2351,7 +2404,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
$ages = $outer_query
->execute()
->fetchCol();
- $this->assertEqual($ages, array(25, 26, 27, 28), t('Inner pager query returned the correct ages.'));
+ $this->assertEqual($ages, array(25, 26, 27, 28), 'Inner pager query returned the correct ages.');
}
/**
@@ -2371,7 +2424,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
$ages = $query
->execute()
->fetchCol();
- $this->assertEqual($ages, array('George', 'Ringo'), t('Pager query with having expression returned the correct ages.'));
+ $this->assertEqual($ages, array('George', 'Ringo'), 'Pager query with having expression returned the correct ages.');
}
/**
@@ -2387,7 +2440,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
->limit(1)
->execute()
->fetchField();
- $this->assertEqual($name, 'Paul', t('Pager query #1 with a specified element ID returned the correct results.'));
+ $this->assertEqual($name, 'Paul', 'Pager query #1 with a specified element ID returned the correct results.');
// Setting an element smaller than the previous one
// should not overwrite the pager $maxElement with a smaller value.
@@ -2398,7 +2451,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
->limit(1)
->execute()
->fetchField();
- $this->assertEqual($name, 'George', t('Pager query #2 with a specified element ID returned the correct results.'));
+ $this->assertEqual($name, 'George', 'Pager query #2 with a specified element ID returned the correct results.');
$name = db_select('test', 't')->extend('PagerDefault')
->fields('t', array('name'))
@@ -2406,7 +2459,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
->limit(1)
->execute()
->fetchField();
- $this->assertEqual($name, 'John', t('Pager query #3 with a generated element ID returned the correct results.'));
+ $this->assertEqual($name, 'John', 'Pager query #3 with a generated element ID returned the correct results.');
unset($_GET['page']);
}
@@ -2446,8 +2499,8 @@ class DatabaseSelectTableSortDefaultTestCase extends DatabaseTestCase {
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
- $this->assertEqual($first->task, $sort['first'], t('Items appear in the correct order.'));
- $this->assertEqual($last->task, $sort['last'], t('Items appear in the correct order.'));
+ $this->assertEqual($first->task, $sort['first'], 'Items appear in the correct order.');
+ $this->assertEqual($last->task, $sort['last'], 'Items appear in the correct order.');
}
}
@@ -2472,8 +2525,8 @@ class DatabaseSelectTableSortDefaultTestCase extends DatabaseTestCase {
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
- $this->assertEqual($first->task, $sort['first'], t('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
- $this->assertEqual($last->task, $sort['last'], t('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
+ $this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
+ $this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
}
}
@@ -2513,8 +2566,8 @@ class DatabaseTaggingTestCase extends DatabaseTestCase {
$query->addTag('test');
- $this->assertTrue($query->hasTag('test'), t('hasTag() returned true.'));
- $this->assertFalse($query->hasTag('other'), t('hasTag() returned false.'));
+ $this->assertTrue($query->hasTag('test'), 'hasTag() returned true.');
+ $this->assertFalse($query->hasTag('other'), 'hasTag() returned false.');
}
/**
@@ -2528,8 +2581,8 @@ class DatabaseTaggingTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertTrue($query->hasAllTags('test', 'other'), 'hasAllTags() returned true.');
+ $this->assertFalse($query->hasAllTags('test', 'stuff'), 'hasAllTags() returned false.');
}
/**
@@ -2542,8 +2595,8 @@ class DatabaseTaggingTestCase extends DatabaseTestCase {
$query->addTag('test');
- $this->assertTrue($query->hasAnyTag('test', 'other'), t('hasAnyTag() returned true.'));
- $this->assertFalse($query->hasAnyTag('other', 'stuff'), t('hasAnyTag() returned false.'));
+ $this->assertTrue($query->hasAnyTag('test', 'other'), 'hasAnyTag() returned true.');
+ $this->assertFalse($query->hasAnyTag('other', 'stuff'), 'hasAnyTag() returned false.');
}
/**
@@ -2564,10 +2617,10 @@ class DatabaseTaggingTestCase extends DatabaseTestCase {
$query->addMetaData('test', $data);
$return = $query->getMetaData('test');
- $this->assertEqual($data, $return, t('Corect metadata returned.'));
+ $this->assertEqual($data, $return, 'Corect metadata returned.');
$return = $query->getMetaData('nothere');
- $this->assertNull($return, t('Non-existent key returned NULL.'));
+ $this->assertNull($return, 'Non-existent key returned NULL.');
}
}
@@ -2602,7 +2655,7 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$num_records++;
}
- $this->assertEqual($num_records, 2, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 2, 'Returned the correct number of rows.');
}
/**
@@ -2619,14 +2672,14 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$records = $result->fetchAll();
- $this->assertEqual(count($records), 2, t('Returned the correct number of rows.'));
+ $this->assertEqual(count($records), 2, '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.'));
- $this->assertEqual($records[1]->name, 'George', t('Correct data retrieved.'));
- $this->assertEqual($records[1]->$tid_field, 5, t('Correct data retrieved.'));
- $this->assertEqual($records[1]->$task_field, 'sleep', t('Correct data retrieved.'));
+ $this->assertEqual($records[0]->name, 'George', 'Correct data retrieved.');
+ $this->assertEqual($records[0]->$tid_field, 4, 'Correct data retrieved.');
+ $this->assertEqual($records[0]->$task_field, 'sing', 'Correct data retrieved.');
+ $this->assertEqual($records[1]->name, 'George', 'Correct data retrieved.');
+ $this->assertEqual($records[1]->$tid_field, 5, 'Correct data retrieved.');
+ $this->assertEqual($records[1]->$task_field, 'sleep', 'Correct data retrieved.');
}
/**
@@ -2647,11 +2700,11 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$records = $result->fetchAll();
- $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
- $this->assertEqual($records[0]->$name_field, 'John', t('Correct data retrieved.'));
- $this->assertEqual($records[0]->$tid_field, 2, t('Correct data retrieved.'));
- $this->assertEqual($records[0]->$pid_field, 1, t('Correct data retrieved.'));
- $this->assertEqual($records[0]->$task_field, 'sleep', t('Correct data retrieved.'));
+ $this->assertEqual(count($records), 1, 'Returned the correct number of rows.');
+ $this->assertEqual($records[0]->$name_field, 'John', 'Correct data retrieved.');
+ $this->assertEqual($records[0]->$tid_field, 2, 'Correct data retrieved.');
+ $this->assertEqual($records[0]->$pid_field, 1, 'Correct data retrieved.');
+ $this->assertEqual($records[0]->$task_field, 'sleep', 'Correct data retrieved.');
}
/**
@@ -2665,8 +2718,8 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$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.'));
+ $this->assertEqual($record->$name_field, 'George', 'Correct data retrieved.');
+ $this->assertFalse(isset($record->$age_field), 'Age field not found, as intended.');
}
/**
@@ -2683,8 +2736,8 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
// Ensure that we got the right record.
$record = $result->fetch();
- $this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.'));
- $this->assertEqual($record->$age_field, 27*3, t('Fetched age expression is correct.'));
+ $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
+ $this->assertEqual($record->$age_field, 27*3, 'Fetched age expression is correct.');
}
/**
@@ -2699,7 +2752,7 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$num_records = count($query->execute()->fetchAll());
- $this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
+ $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
/**
@@ -2723,8 +2776,8 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$name_field = $query->addField('pq', 'name');
$record = $query->execute()->fetch();
- $this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.'));
- $this->assertEqual($record->$age_field, 27*3, t('Fetched age expression is correct.'));
+ $this->assertEqual($record->$name_field, 'George', 'Fetched name is correct.');
+ $this->assertEqual($record->$age_field, 27*3, 'Fetched age expression is correct.');
}
}
@@ -2758,31 +2811,31 @@ class DatabaseRegressionTestCase extends DatabaseTestCase {
))->execute();
$from_database = db_query('SELECT name FROM {test} WHERE name = :name', array(':name' => $name))->fetchField();
- $this->assertIdentical($name, $from_database, t("The database handles UTF-8 characters cleanly."));
+ $this->assertIdentical($name, $from_database, "The database handles UTF-8 characters cleanly.");
}
/**
* Test the db_table_exists() function.
*/
function testDBTableExists() {
- $this->assertIdentical(TRUE, db_table_exists('node'), t('Returns true for existent table.'));
- $this->assertIdentical(FALSE, db_table_exists('nosuchtable'), t('Returns false for nonexistent table.'));
+ $this->assertIdentical(TRUE, db_table_exists('node'), 'Returns true for existent table.');
+ $this->assertIdentical(FALSE, db_table_exists('nosuchtable'), 'Returns false for nonexistent table.');
}
/**
* Test the db_field_exists() function.
*/
function testDBFieldExists() {
- $this->assertIdentical(TRUE, db_field_exists('node', 'nid'), t('Returns true for existent column.'));
- $this->assertIdentical(FALSE, db_field_exists('node', 'nosuchcolumn'), t('Returns false for nonexistent column.'));
+ $this->assertIdentical(TRUE, db_field_exists('node', 'nid'), 'Returns true for existent column.');
+ $this->assertIdentical(FALSE, db_field_exists('node', 'nosuchcolumn'), 'Returns false for nonexistent column.');
}
/**
* Test the db_index_exists() function.
*/
function testDBIndexExists() {
- $this->assertIdentical(TRUE, db_index_exists('node', 'node_created'), t('Returns true for existent index.'));
- $this->assertIdentical(FALSE, db_index_exists('node', 'nosuchindex'), t('Returns false for nonexistent index.'));
+ $this->assertIdentical(TRUE, db_index_exists('node', 'node_created'), 'Returns true for existent index.');
+ $this->assertIdentical(FALSE, db_index_exists('node', 'nosuchindex'), 'Returns false for nonexistent index.');
}
}
@@ -2813,10 +2866,10 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
$queries = Database::getLog('testing', 'default');
- $this->assertEqual(count($queries), 3, t('Correct number of queries recorded.'));
+ $this->assertEqual(count($queries), 3, 'Correct number of queries recorded.');
foreach ($queries as $query) {
- $this->assertEqual($query['caller']['function'], __FUNCTION__, t('Correct function in query log.'));
+ $this->assertEqual($query['caller']['function'], __FUNCTION__, 'Correct function in query log.');
}
}
@@ -2835,8 +2888,8 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
$queries1 = Database::getLog('testing1');
$queries2 = Database::getLog('testing2');
- $this->assertEqual(count($queries1), 2, t('Correct number of queries recorded for log 1.'));
- $this->assertEqual(count($queries2), 1, t('Correct number of queries recorded for log 2.'));
+ $this->assertEqual(count($queries1), 2, 'Correct number of queries recorded for log 1.');
+ $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for log 2.');
}
/**
@@ -2856,9 +2909,9 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
$queries1 = Database::getLog('testing1');
- $this->assertEqual(count($queries1), 2, t('Recorded queries from all targets.'));
- $this->assertEqual($queries1[0]['target'], 'default', t('First query used default target.'));
- $this->assertEqual($queries1[1]['target'], 'slave', t('Second query used slave target.'));
+ $this->assertEqual(count($queries1), 2, 'Recorded queries from all targets.');
+ $this->assertEqual($queries1[0]['target'], 'default', 'First query used default target.');
+ $this->assertEqual($queries1[1]['target'], 'slave', 'Second query used slave target.');
}
/**
@@ -2882,9 +2935,9 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
$queries1 = Database::getLog('testing1');
- $this->assertEqual(count($queries1), 2, t('Recorded queries from all targets.'));
- $this->assertEqual($queries1[0]['target'], 'default', t('First query used default target.'));
- $this->assertEqual($queries1[1]['target'], 'default', t('Second query used default target as fallback.'));
+ $this->assertEqual(count($queries1), 2, 'Recorded queries from all targets.');
+ $this->assertEqual($queries1[0]['target'], 'default', 'First query used default target.');
+ $this->assertEqual($queries1[1]['target'], 'default', 'Second query used default target as fallback.');
}
/**
@@ -2910,8 +2963,8 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
$queries1 = Database::getLog('testing1');
$queries2 = Database::getLog('testing1', 'test2');
- $this->assertEqual(count($queries1), 1, t('Correct number of queries recorded for first connection.'));
- $this->assertEqual(count($queries2), 1, t('Correct number of queries recorded for second connection.'));
+ $this->assertEqual(count($queries1), 1, 'Correct number of queries recorded for first connection.');
+ $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.');
}
}
@@ -2938,7 +2991,7 @@ class DatabaseSerializeQueryTestCase extends DatabaseTestCase {
// assertion.
$query = unserialize(serialize($query));
$results = $query->execute()->fetchCol();
- $this->assertEqual($results[0], 28, t('Query properly executed after unserialization.'));
+ $this->assertEqual($results[0], 28, 'Query properly executed after unserialization.');
}
}
@@ -2964,12 +3017,12 @@ class DatabaseRangeQueryTestCase extends DrupalWebTestCase {
function testRangeQuery() {
// Test if return correct number of rows.
$range_rows = db_query_range("SELECT name FROM {system} ORDER BY name", 2, 3)->fetchAll();
- $this->assertEqual(count($range_rows), 3, t('Range query work and return correct number of rows.'));
+ $this->assertEqual(count($range_rows), 3, 'Range query work and return correct number of rows.');
// Test if return target data.
$raw_rows = db_query('SELECT name FROM {system} ORDER BY name')->fetchAll();
$raw_rows = array_slice($raw_rows, 2, 3);
- $this->assertEqual($range_rows, $raw_rows, t('Range query work and return target data.'));
+ $this->assertEqual($range_rows, $raw_rows, 'Range query work and return target data.');
}
}
@@ -3003,19 +3056,19 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase {
$this->drupalGet('database_test/db_query_temporary');
$data = json_decode($this->drupalGetContent());
if ($data) {
- $this->assertEqual($this->countTableRows("system"), $data->row_count, t('The temporary table contains the correct amount of rows.'));
- $this->assertFalse(db_table_exists($data->table_name), t('The temporary table is, indeed, temporary.'));
+ $this->assertEqual($this->countTableRows("system"), $data->row_count, 'The temporary table contains the correct amount of rows.');
+ $this->assertFalse(db_table_exists($data->table_name), 'The temporary table is, indeed, temporary.');
}
else {
- $this->fail(t("The creation of the temporary table failed."));
+ $this->fail("The creation of the temporary table failed.");
}
// Now try to run two db_query_temporary() in the same request.
$table_name_system = db_query_temporary('SELECT status FROM {system}', array());
$table_name_users = db_query_temporary('SELECT uid FROM {users}', array());
- $this->assertEqual($this->countTableRows($table_name_system), $this->countTableRows("system"), t('A temporary table was created successfully in this request.'));
- $this->assertEqual($this->countTableRows($table_name_users), $this->countTableRows("users"), t('A second temporary table was created successfully in this request.'));
+ $this->assertEqual($this->countTableRows($table_name_system), $this->countTableRows("system"), 'A temporary table was created successfully in this request.');
+ $this->assertEqual($this->countTableRows($table_name_users), $this->countTableRows("users"), 'A second temporary table was created successfully in this request.');
}
}
@@ -3050,7 +3103,7 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase {
':a4' => ' a ',
':a5' => 'test.',
));
- $this->assertIdentical($result->fetchField(), 'This is a test.', t('Basic CONCAT works.'));
+ $this->assertIdentical($result->fetchField(), 'This is a test.', 'Basic CONCAT works.');
}
/**
@@ -3063,7 +3116,7 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase {
':a3' => '.',
':age' => 25,
));
- $this->assertIdentical($result->fetchField(), 'The age of John is 25.', t('Field CONCAT works.'));
+ $this->assertIdentical($result->fetchField(), 'The age of John is 25.', 'Field CONCAT works.');
}
/**
@@ -3082,14 +3135,14 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase {
->countQuery()
->execute()
->fetchField();
- $this->assertIdentical($num_matches, '2', t('Found 2 records.'));
+ $this->assertIdentical($num_matches, '2', 'Found 2 records.');
// Match only "Ring_" using a LIKE expression with no wildcards.
$num_matches = db_select('test', 't')
->condition('name', db_like('Ring_'), 'LIKE')
->countQuery()
->execute()
->fetchField();
- $this->assertIdentical($num_matches, '1', t('Found 1 record.'));
+ $this->assertIdentical($num_matches, '1', 'Found 1 record.');
}
/**
@@ -3113,14 +3166,14 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase {
->countQuery()
->execute()
->fetchField();
- $this->assertIdentical($num_matches, '2', t('Found 2 records.'));
+ $this->assertIdentical($num_matches, '2', 'Found 2 records.');
// Match only the former using a LIKE expression with no wildcards.
$num_matches = db_select('test', 't')
->condition('name', db_like('abc%\_'), 'LIKE')
->countQuery()
->execute()
->fetchField();
- $this->assertIdentical($num_matches, '1', t('Found 1 record.'));
+ $this->assertIdentical($num_matches, '1', 'Found 1 record.');
}
}
@@ -3151,9 +3204,9 @@ class DatabaseCaseSensitivityTestCase extends DatabaseTestCase {
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
- $this->assertIdentical($num_records_before + 1, (int) $num_records_after, t('Record inserts correctly.'));
+ $this->assertIdentical($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'john'))->fetchField();
- $this->assertIdentical($saved_age, '2', t('Can retrieve after inserting.'));
+ $this->assertIdentical($saved_age, '2', 'Can retrieve after inserting.');
}
}
@@ -3196,7 +3249,7 @@ class DatabaseInvalidDataTestCase extends DatabaseTestCase {
'job' => 'Singer',
))
->execute();
- $this->fail(t('Insert succeedded when it should not have.'));
+ $this->fail('Insert succeedded when it should not have.');
}
catch (Exception $e) {
// Check if the first record was inserted.
@@ -3208,14 +3261,14 @@ class DatabaseInvalidDataTestCase extends DatabaseTestCase {
// Database engines that don't support transactions can leave partial
// inserts in place when an error occurs. This is the case for MySQL
// when running on a MyISAM table.
- $this->pass(t("The whole transaction has not been rolled-back when a duplicate key insert occurs, this is expected because the database doesn't support transactions"));
+ $this->pass("The whole transaction has not been rolled-back when a duplicate key insert occurs, this is expected because the database doesn't support transactions");
}
else {
- $this->fail(t('The whole transaction is rolled back when a duplicate key insert occurs.'));
+ $this->fail('The whole transaction is rolled back when a duplicate key insert occurs.');
}
}
else {
- $this->pass(t('The whole transaction is rolled back when a duplicate key insert occurs.'));
+ $this->pass('The whole transaction is rolled back when a duplicate key insert occurs.');
}
// Ensure the other values were not inserted.
@@ -3224,7 +3277,7 @@ class DatabaseInvalidDataTestCase extends DatabaseTestCase {
->condition('age', array(17, 75), 'IN')
->execute()->fetchObject();
- $this->assertFalse($record, t('The rest of the insert aborted as expected.'));
+ $this->assertFalse($record, 'The rest of the insert aborted as expected.');
}
}
@@ -3252,7 +3305,7 @@ class DatabaseQueryTestCase extends DatabaseTestCase {
function testArraySubstitution() {
$names = db_query('SELECT name FROM {test} WHERE age IN (:ages) ORDER BY age', array(':ages' => array(25, 26, 27)))->fetchAll();
- $this->assertEqual(count($names), 3, t('Correct number of names returned'));
+ $this->assertEqual(count($names), 3, 'Correct number of names returned');
}
}
@@ -3320,19 +3373,19 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
))
->execute();
- $this->assertTrue($connection->inTransaction(), t('In transaction before calling nested transaction.'));
+ $this->assertTrue($connection->inTransaction(), 'In transaction before calling nested transaction.');
// We're already in a transaction, but we call ->transactionInnerLayer
// to nest another transaction inside the current one.
$this->transactionInnerLayer($suffix, $rollback, $ddl_statement);
- $this->assertTrue($connection->inTransaction(), t('In transaction after calling nested transaction.'));
+ $this->assertTrue($connection->inTransaction(), 'In transaction after calling nested transaction.');
if ($rollback) {
// Roll back the transaction, if requested.
// This rollback should propagate to the last savepoint.
$txn->rollback();
- $this->assertTrue(($connection->transactionDepth() == $depth), t('Transaction has rolled back to the last savepoint after calling rollback().'));
+ $this->assertTrue(($connection->transactionDepth() == $depth), 'Transaction has rolled back to the last savepoint after calling rollback().');
}
}
@@ -3358,7 +3411,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$txn = db_transaction();
$depth2 = $connection->transactionDepth();
- $this->assertTrue($depth < $depth2, t('Transaction depth is has increased with new transaction.'));
+ $this->assertTrue($depth < $depth2, 'Transaction depth is has increased with new transaction.');
// Insert a single row into the testing table.
db_insert('test')
@@ -3368,7 +3421,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
))
->execute();
- $this->assertTrue($connection->inTransaction(), t('In transaction inside nested transaction.'));
+ $this->assertTrue($connection->inTransaction(), 'In transaction inside nested transaction.');
if ($ddl_statement) {
$table = array(
@@ -3383,14 +3436,14 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
);
db_create_table('database_test_1', $table);
- $this->assertTrue($connection->inTransaction(), t('In transaction inside nested transaction.'));
+ $this->assertTrue($connection->inTransaction(), 'In transaction inside nested transaction.');
}
if ($rollback) {
// Roll back the transaction, if requested.
// This rollback should propagate to the last savepoint.
$txn->rollback();
- $this->assertTrue(($connection->transactionDepth() == $depth), t('Transaction has rolled back to the last savepoint after calling rollback().'));
+ $this->assertTrue(($connection->transactionDepth() == $depth), 'Transaction has rolled back to the last savepoint after calling rollback().');
}
}
@@ -3411,9 +3464,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// Neither of the rows we inserted in the two transaction layers
// should be present in the tables post-rollback.
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField();
- $this->assertNotIdentical($saved_age, '24', t('Cannot retrieve DavidB row after commit.'));
+ $this->assertNotIdentical($saved_age, '24', 'Cannot retrieve DavidB row after commit.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
- $this->assertNotIdentical($saved_age, '19', t('Cannot retrieve DanielB row after commit.'));
+ $this->assertNotIdentical($saved_age, '19', 'Cannot retrieve DanielB row after commit.');
}
catch (Exception $e) {
$this->fail($e->getMessage());
@@ -3437,9 +3490,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// Because our current database claims to not support transactions,
// the inserted rows should be present despite the attempt to roll back.
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField();
- $this->assertIdentical($saved_age, '24', t('DavidB not rolled back, since transactions are not supported.'));
+ $this->assertIdentical($saved_age, '24', 'DavidB not rolled back, since transactions are not supported.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
- $this->assertIdentical($saved_age, '19', t('DanielB not rolled back, since transactions are not supported.'));
+ $this->assertIdentical($saved_age, '19', 'DanielB not rolled back, since transactions are not supported.');
}
catch (Exception $e) {
$this->fail($e->getMessage());
@@ -3459,9 +3512,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// Because we committed, both of the inserted rows should be present.
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidA'))->fetchField();
- $this->assertIdentical($saved_age, '24', t('Can retrieve DavidA row after commit.'));
+ $this->assertIdentical($saved_age, '24', 'Can retrieve DavidA row after commit.');
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielA'))->fetchField();
- $this->assertIdentical($saved_age, '19', t('Can retrieve DanielA row after commit.'));
+ $this->assertIdentical($saved_age, '19', 'Can retrieve DanielA row after commit.');
}
catch (Exception $e) {
$this->fail($e->getMessage());
@@ -3553,7 +3606,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// $this->fail(t('Rolling back a transaction containing DDL should fail.'));
}
catch (DatabaseTransactionNoActiveException $e) {
- $this->pass(t('Rolling back a transaction containing DDL should fail.'));
+ $this->pass('Rolling back a transaction containing DDL should fail.');
}
$this->assertRowPresent('row');
}
@@ -3606,7 +3659,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
*/
function assertRowPresent($name, $message = NULL) {
if (!isset($message)) {
- $message = t('Row %name is present.', array('%name' => $name));
+ $message = format_string('Row %name is present.', array('%name' => $name));
}
$present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchField();
return $this->assertTrue($present, $message);
@@ -3622,7 +3675,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
*/
function assertRowAbsent($name, $message = NULL) {
if (!isset($message)) {
- $message = t('Row %name is absent.', array('%name' => $name));
+ $message = format_string('Row %name is absent.', array('%name' => $name));
}
$present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchField();
return $this->assertFalse($present, $message);
@@ -3646,10 +3699,10 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$this->insertRow('inner');
// Pop the inner transaction.
unset($transaction2);
- $this->assertTrue($database->inTransaction(), t('Still in a transaction after popping the inner transaction'));
+ $this->assertTrue($database->inTransaction(), 'Still in a transaction after popping the inner transaction');
// Pop the outer transaction.
unset($transaction);
- $this->assertFalse($database->inTransaction(), t('Transaction closed after popping the outer transaction'));
+ $this->assertFalse($database->inTransaction(), 'Transaction closed after popping the outer transaction');
$this->assertRowPresent('outer');
$this->assertRowPresent('inner');
@@ -3662,10 +3715,10 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// Pop the outer transaction, nothing should happen.
unset($transaction);
$this->insertRow('inner-after-outer-commit');
- $this->assertTrue($database->inTransaction(), t('Still in a transaction after popping the outer transaction'));
+ $this->assertTrue($database->inTransaction(), 'Still in a transaction after popping the outer transaction');
// Pop the inner transaction, the whole transaction should commit.
unset($transaction2);
- $this->assertFalse($database->inTransaction(), t('Transaction closed after popping the inner transaction'));
+ $this->assertFalse($database->inTransaction(), 'Transaction closed after popping the inner transaction');
$this->assertRowPresent('outer');
$this->assertRowPresent('inner');
$this->assertRowPresent('inner-after-outer-commit');
@@ -3679,11 +3732,11 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// Now rollback the inner transaction.
$transaction2->rollback();
unset($transaction2);
- $this->assertTrue($database->inTransaction(), t('Still in a transaction after popping the outer transaction'));
+ $this->assertTrue($database->inTransaction(), 'Still in a transaction after popping the outer transaction');
// Pop the outer transaction, it should commit.
$this->insertRow('outer-after-inner-rollback');
unset($transaction);
- $this->assertFalse($database->inTransaction(), t('Transaction closed after popping the inner transaction'));
+ $this->assertFalse($database->inTransaction(), 'Transaction closed after popping the inner transaction');
$this->assertRowPresent('outer');
$this->assertRowAbsent('inner');
$this->assertRowPresent('outer-after-inner-rollback');
@@ -3696,11 +3749,11 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$this->insertRow('inner');
// Pop the outer transaction, nothing should happen.
unset($transaction);
- $this->assertTrue($database->inTransaction(), t('Still in a transaction after popping the outer transaction'));
+ $this->assertTrue($database->inTransaction(), 'Still in a transaction after popping the outer transaction');
// Now rollback the inner transaction, it should rollback.
$transaction2->rollback();
unset($transaction2);
- $this->assertFalse($database->inTransaction(), t('Transaction closed after popping the inner transaction'));
+ $this->assertFalse($database->inTransaction(), 'Transaction closed after popping the inner transaction');
$this->assertRowPresent('outer');
$this->assertRowAbsent('inner');
@@ -3718,23 +3771,23 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
try {
$transaction->rollback();
unset($transaction);
- $this->fail(t('Rolling back the outer transaction while the inner transaction is active resulted in an exception.'));
+ $this->fail('Rolling back the outer transaction while the inner transaction is active resulted in an exception.');
}
catch (DatabaseTransactionOutOfOrderException $e) {
- $this->pass(t('Rolling back the outer transaction while the inner transaction is active resulted in an exception.'));
+ $this->pass('Rolling back the outer transaction while the inner transaction is active resulted in an exception.');
}
- $this->assertFalse($database->inTransaction(), t('No more in a transaction after rolling back the outer transaction'));
+ $this->assertFalse($database->inTransaction(), 'No more in a transaction after rolling back the outer transaction');
// Try to commit one inner transaction.
unset($transaction3);
- $this->pass(t('Trying to commit an inner transaction resulted in an exception.'));
+ $this->pass('Trying to commit an inner transaction resulted in an exception.');
// Try to rollback one inner transaction.
try {
$transaction->rollback();
unset($transaction2);
- $this->fail(t('Trying to commit an inner transaction resulted in an exception.'));
+ $this->fail('Trying to commit an inner transaction resulted in an exception.');
}
catch (DatabaseTransactionNoActiveException $e) {
- $this->pass(t('Trying to commit an inner transaction resulted in an exception.'));
+ $this->pass('Trying to commit an inner transaction resulted in an exception.');
}
$this->assertRowAbsent('outer');
$this->assertRowAbsent('inner');
@@ -3764,9 +3817,9 @@ class DatabaseNextIdCase extends DrupalWebTestCase {
// We can test for exact increase in here because we know there is no
// other process operating on these tables -- normally we could only
// expect $second > $first.
- $this->assertEqual($first + 1, $second, t('The second call from a sequence provides a number increased by one.'));
+ $this->assertEqual($first + 1, $second, 'The second call from a sequence provides a number increased by one.');
$result = db_next_id(1000);
- $this->assertEqual($result, 1001, t('Sequence provides a larger number than the existing ID.'));
+ $this->assertEqual($result, 1001, 'Sequence provides a larger number than the existing ID.');
}
}
@@ -3788,8 +3841,8 @@ class DatabaseEmptyStatementTestCase extends DrupalWebTestCase {
function testEmpty() {
$result = new DatabaseStatementEmpty();
- $this->assertTrue($result instanceof DatabaseStatementInterface, t('Class implements expected interface'));
- $this->assertNull($result->fetchObject(), t('Null result returned.'));
+ $this->assertTrue($result instanceof DatabaseStatementInterface, 'Class implements expected interface');
+ $this->assertNull($result->fetchObject(), 'Null result returned.');
}
/**
@@ -3799,11 +3852,11 @@ class DatabaseEmptyStatementTestCase extends DrupalWebTestCase {
$result = new DatabaseStatementEmpty();
foreach ($result as $record) {
- $this->fail(t('Iterating empty result set should not iterate.'));
+ $this->fail('Iterating empty result set should not iterate.');
return;
}
- $this->pass(t('Iterating empty result set skipped iteration.'));
+ $this->pass('Iterating empty result set skipped iteration.');
}
/**
@@ -3812,6 +3865,225 @@ class DatabaseEmptyStatementTestCase extends DrupalWebTestCase {
function testEmptyFetchAll() {
$result = new DatabaseStatementEmpty();
- $this->assertEqual($result->fetchAll(), array(), t('Empty array returned from empty result set.'));
+ $this->assertEqual($result->fetchAll(), array(), 'Empty array returned from empty result set.');
+ }
+}
+
+/**
+ * Tests management of database connections.
+ */
+class ConnectionUnitTest extends DrupalUnitTestCase {
+
+ protected $key;
+ protected $target;
+
+ protected $monitor;
+ protected $originalCount;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Connection unit tests',
+ 'description' => 'Tests management of database connections.',
+ 'group' => 'Database',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ $this->key = 'default';
+ $this->originalTarget = 'default';
+ $this->target = 'DatabaseConnectionUnitTest';
+
+ // Determine whether the database driver is MySQL. If it is not, the test
+ // methods will not be executed.
+ // @todo Make this test driver-agnostic, or find a proper way to skip it.
+ // @see http://drupal.org/node/1273478
+ $connection_info = Database::getConnectionInfo('default');
+ $this->skipTest = (bool) $connection_info['default']['driver'] != 'mysql';
+ if ($this->skipTest) {
+ // Insert an assertion to prevent Simpletest from interpreting the test
+ // as failure.
+ $this->pass('This test is only compatible with MySQL.');
+ }
+
+ // Create an additional connection to monitor the connections being opened
+ // and closed in this test.
+ // @see TestBase::changeDatabasePrefix()
+ $connection_info = Database::getConnectionInfo('default');
+ Database::addConnectionInfo('default', 'monitor', $connection_info['default']);
+ global $databases;
+ $databases['default']['monitor'] = $connection_info['default'];
+ $this->monitor = Database::getConnection('monitor');
+ }
+
+ /**
+ * Adds a new database connection info to Database.
+ */
+ protected function addConnection() {
+ // Add a new target to the connection, by cloning the current connection.
+ $connection_info = Database::getConnectionInfo($this->key);
+ Database::addConnectionInfo($this->key, $this->target, $connection_info[$this->originalTarget]);
+
+ // Verify that the new target exists.
+ $info = Database::getConnectionInfo($this->key);
+ // Note: Custom assertion message to not expose database credentials.
+ $this->assertIdentical($info[$this->target], $connection_info[$this->key], 'New connection info found.');
+ }
+
+ /**
+ * Returns the connection ID of the current test connection.
+ *
+ * @return integer
+ */
+ protected function getConnectionID() {
+ return (int) Database::getConnection($this->target, $this->key)->query('SELECT CONNECTION_ID()')->fetchField();
}
+
+ /**
+ * Asserts that a connection ID exists.
+ *
+ * @param integer $id
+ * The connection ID to verify.
+ */
+ protected function assertConnection($id) {
+ $list = $this->monitor->query('SHOW PROCESSLIST')->fetchAllKeyed(0, 0);
+ return $this->assertTrue(isset($list[$id]), format_string('Connection ID @id found.', array('@id' => $id)));
+ }
+
+ /**
+ * Asserts that a connection ID does not exist.
+ *
+ * @param integer $id
+ * The connection ID to verify.
+ */
+ protected function assertNoConnection($id) {
+ $list = $this->monitor->query('SHOW PROCESSLIST')->fetchAllKeyed(0, 0);
+ return $this->assertFalse(isset($list[$id]), format_string('Connection ID @id not found.', array('@id' => $id)));
+ }
+
+ /**
+ * Tests Database::closeConnection() without query.
+ *
+ * @todo getConnectionID() executes a query.
+ */
+ function testOpenClose() {
+ if ($this->skipTest) {
+ return;
+ }
+ // Add and open a new connection.
+ $this->addConnection();
+ $id = $this->getConnectionID();
+ Database::getConnection($this->target, $this->key);
+
+ // Verify that there is a new connection.
+ $this->assertConnection($id);
+
+ // Close the connection.
+ Database::closeConnection($this->target, $this->key);
+ // Wait 20ms to give the database engine sufficient time to react.
+ usleep(20000);
+
+ // Verify that we are back to the original connection count.
+ $this->assertNoConnection($id);
+ }
+
+ /**
+ * Tests Database::closeConnection() with a query.
+ */
+ function testOpenQueryClose() {
+ if ($this->skipTest) {
+ return;
+ }
+ // Add and open a new connection.
+ $this->addConnection();
+ $id = $this->getConnectionID();
+ Database::getConnection($this->target, $this->key);
+
+ // Verify that there is a new connection.
+ $this->assertConnection($id);
+
+ // Execute a query.
+ Database::getConnection($this->target, $this->key)->query('SHOW TABLES');
+
+ // Close the connection.
+ Database::closeConnection($this->target, $this->key);
+ // Wait 20ms to give the database engine sufficient time to react.
+ usleep(20000);
+
+ // Verify that we are back to the original connection count.
+ $this->assertNoConnection($id);
+ }
+
+ /**
+ * Tests Database::closeConnection() with a query and custom prefetch method.
+ */
+ function testOpenQueryPrefetchClose() {
+ if ($this->skipTest) {
+ return;
+ }
+ // Add and open a new connection.
+ $this->addConnection();
+ $id = $this->getConnectionID();
+ Database::getConnection($this->target, $this->key);
+
+ // Verify that there is a new connection.
+ $this->assertConnection($id);
+
+ // Execute a query.
+ Database::getConnection($this->target, $this->key)->query('SHOW TABLES')->fetchCol();
+
+ // Close the connection.
+ Database::closeConnection($this->target, $this->key);
+ // Wait 20ms to give the database engine sufficient time to react.
+ usleep(20000);
+
+ // Verify that we are back to the original connection count.
+ $this->assertNoConnection($id);
+ }
+
+ /**
+ * Tests Database::closeConnection() with a select query.
+ */
+ function testOpenSelectQueryClose() {
+ if ($this->skipTest) {
+ return;
+ }
+ // Add and open a new connection.
+ $this->addConnection();
+ $id = $this->getConnectionID();
+ Database::getConnection($this->target, $this->key);
+
+ // Verify that there is a new connection.
+ $this->assertConnection($id);
+
+ // Create a table.
+ $name = 'foo';
+ Database::getConnection($this->target, $this->key)->schema()->createTable($name, array(
+ 'fields' => array(
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ ),
+ ),
+ ));
+
+ // Execute a query.
+ Database::getConnection($this->target, $this->key)->select('foo', 'f')
+ ->fields('f', array('name'))
+ ->execute()
+ ->fetchAll();
+
+ // Drop the table.
+ Database::getConnection($this->target, $this->key)->schema()->dropTable($name);
+
+ // Close the connection.
+ Database::closeConnection($this->target, $this->key);
+ // Wait 20ms to give the database engine sufficient time to react.
+ usleep(20000);
+
+ // Verify that we are back to the original connection count.
+ $this->assertNoConnection($id);
+ }
+
}
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 3df31ba5f..ebaa0c034 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -2579,6 +2579,15 @@ class FileNameMungingTest extends FileTestCase {
}
/**
+ * Tests munging with a null byte in the filename.
+ */
+ function testMungeNullByte() {
+ $prefix = $this->randomName();
+ $filename = $prefix . '.' . $this->bad_extension . "\0.txt";
+ $this->assertEqual(file_munge_filename($filename, ''), $prefix . '.' . $this->bad_extension . '_.txt', 'A filename with a null byte is correctly munged to remove the null byte.');
+ }
+
+ /**
* If the allow_insecure_uploads variable evaluates to true, the file should
* come out untouched, no matter how evil the filename.
*/
diff --git a/modules/simpletest/tests/upgrade/upgrade.test b/modules/simpletest/tests/upgrade/upgrade.test
index 9df8ec779..cc849aa79 100644
--- a/modules/simpletest/tests/upgrade/upgrade.test
+++ b/modules/simpletest/tests/upgrade/upgrade.test
@@ -566,6 +566,20 @@ class BasicMinimalUpdatePath extends UpdatePathTestCase {
// Confirm that no {menu_links} entry exists for user/autocomplete.
$result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField();
$this->assertFalse($result, t('No {menu_links} entry exists for user/autocomplete'));
+
+ // Confirm that a date format that just differs in the case can be added.
+ $admin_date_format = 'j M y';
+ $edit = array('date_format' => $admin_date_format);
+ $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+
+ // Add a new date format which just differs in the case.
+ $admin_date_format_uppercase = 'j M Y';
+ $edit = array('date_format' => $admin_date_format_uppercase);
+ $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+ $this->assertText(t('Custom date format added.'));
+
+ // Verify that the unique key on {date_formats}.format still exists.
+ $this->assertTrue(db_index_exists('date_formats', 'formats'), 'Unique key on {date_formats} exists');
}
}