database_test.module

Same filename in other branches
  1. 7.x modules/simpletest/tests/database_test.module
  2. 8.9.x core/modules/system/tests/modules/database_test/database_test.module
  3. 10 core/modules/system/tests/modules/database_test/database_test.module
  4. 11.x core/modules/system/tests/modules/database_test/database_test.module

Database test module.

File

core/modules/system/tests/modules/database_test/database_test.module

View source
<?php


/**
 * @file
 * Database test module.
 */
use Drupal\Core\Database\Query\AlterableInterface;

/**
 * Implements hook_query_alter().
 */
function database_test_query_alter(AlterableInterface $query) {
    if ($query->hasTag('database_test_alter_add_range')) {
        $query->range(0, 2);
    }
    if ($query->hasTag('database_test_alter_add_join')) {
        $people_alias = $query->join('test', 'people', "[test_task].[pid] = [%alias].[id]");
        $query->addField($people_alias, 'name', 'name');
        $query->condition($people_alias . '.id', 2);
    }
    if ($query->hasTag('database_test_alter_change_conditional')) {
        $conditions =& $query->conditions();
        $conditions[0]['value'] = 2;
    }
    if ($query->hasTag('database_test_alter_change_fields')) {
        $fields =& $query->getFields();
        unset($fields['age']);
    }
    if ($query->hasTag('database_test_alter_change_expressions')) {
        $expressions =& $query->getExpressions();
        $expressions['double_age']['expression'] = '[age]*3';
    }
}

/**
 * Implements hook_query_TAG_alter().
 *
 * Called by DatabaseTestCase::testAlterRemoveRange.
 */
function database_test_query_database_test_alter_remove_range_alter(AlterableInterface $query) {
    $query->range();
}

Functions

Title Deprecated Summary
database_test_query_alter Implements hook_query_alter().
database_test_query_database_test_alter_remove_range_alter Implements hook_query_TAG_alter().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.