function DatabaseSerializeQueryTestCase::testSerializeQuery

7.x database_test.test DatabaseSerializeQueryTestCase::testSerializeQuery()

Confirm that a query can be serialized and unserialized.

File

drupal-7.x/modules/simpletest/tests/database_test.test, line 3008

Class

DatabaseSerializeQueryTestCase
Query serialization tests.

Code

function testSerializeQuery() {
  $query = db_select('test');
  $query->addField('test', 'age');
  $query->condition('name', 'Ringo');
  // If this doesn't work, it will throw an exception, so no need for an
  // assertion.
  $query = unserialize(serialize($query));
  $results = $query->execute()->fetchCol();
  $this->assertEqual($results[0], 28, 'Query properly executed after unserialization.');
}