function AlterTest::testAlterWithJoin in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/AlterTest.php \Drupal\system\Tests\Database\AlterTest::testAlterWithJoin()
Tests that we can alter the joins on a query.
File
- core/
modules/ system/ src/ Tests/ Database/ AlterTest.php, line 35 - Contains \Drupal\system\Tests\Database\AlterTest.
Class
- AlterTest
- Tests the hook_query_alter capabilities of the Select builder.
Namespace
Drupal\system\Tests\DatabaseCode
function testAlterWithJoin() {
$query = db_select('test_task');
$tid_field = $query
->addField('test_task', 'tid');
$task_field = $query
->addField('test_task', 'task');
$query
->orderBy($task_field);
$query
->addTag('database_test_alter_add_join');
$result = $query
->execute();
$records = $result
->fetchAll();
$this
->assertEqual(count($records), 2, 'Returned the correct number of rows.');
$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.');
}