You are here

function DatabaseAlterTestCase::testAlterChangeConditional in SimpleTest 7

Test that we can alter a query's conditionals.

File

tests/database_test.test, line 2184

Class

DatabaseAlterTestCase
Select alter tests.

Code

function testAlterChangeConditional() {
  $query = db_select('test_task');
  $tid_field = $query
    ->addField('test_task', 'tid');
  $pid_field = $query
    ->addField('test_task', 'pid');
  $task_field = $query
    ->addField('test_task', 'task');
  $people_alias = $query
    ->join('test', 'people', "test_task.pid = people.id");
  $name_field = $query
    ->addField($people_alias, 'name', 'name');
  $query
    ->condition('test_task.tid', '1');
  $query
    ->orderBy($tid_field);
  $query
    ->addTag('database_test_alter_change_conditional');
  $result = $query
    ->execute();
  $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.'));
}