Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull first schema tests into DBTNG #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ abstract class Database {
// We cannot rely on the registry yet, because the registry requires an
// open database connection.
$driver_class = 'DatabaseConnection_' . $driver;
require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/database.inc';
require_once DBTNG_DIR . '/' . $driver . '/database.inc';
$new_connection = new $driver_class(self::$databaseInfo[$key][$target]);
$new_connection->setTarget($target);
$new_connection->setKey($key);
Expand Down
157 changes: 157 additions & 0 deletions default.settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

/**
* Database settings:
*
* The $databases array specifies the database connection or
* connections that DBTNG may use. DBTNG is able to connect
* to multiple databases, including multiple types of databases,
* during the same request.
*
* Each database connection is specified as an array of settings,
* similar to the following:
* @code
* array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'port' => 3306,
* 'prefix' => 'myprefix_',
* 'collation' => 'utf8_general_ci',
* );
* @endcode
*
* The "driver" property indicates what DBTNG driver the connection
* should use. This is usually the same as the name of the database
* type, such as mysql or sqlite, but not always. The other
* properties will vary depending on the driver. For SQLite, you must
* specify a database file name in a directory that is writable by the
* webserver. For most other drivers, you must specify a
* username, password, host, and database name.
*
* Some database engines support transactions. In order to enable
* transaction support for a given database, set the 'transactions' key
* to TRUE. To disable it, set it to FALSE. Note that the default value
* varies by driver. For MySQL, the default is FALSE since MyISAM tables
* do not support transactions.
*
* For each database, you may optionally specify multiple "target" databases.
* A target database allows DBTNG to try to send certain queries to a
* different database if it can but fall back to the default connection if not.
* That is useful for master/slave replication, as DBTNG may try to connect
* to a slave server when appropriate and if one is not available will simply
* fall back to the single master server.
*
* The general format for the $databases array is as follows:
* @code
* $databases['default']['default'] = $info_array;
* $databases['default']['slave'][] = $info_array;
* $databases['default']['slave'][] = $info_array;
* $databases['extra']['default'] = $info_array;
* @endcode
*
* In the above example, $info_array is an array of settings described above.
* The first line sets a "default" database that has one master database
* (the second level default). The second and third lines create an array
* of potential slave databases. DBTNG will select one at random for a given
* request as needed. The fourth line creates a new database with a name of
* "extra".
*
* For a single database configuration, the following is sufficient:
* @code
* $databases['default']['default'] = array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => 'main_',
* 'collation' => 'utf8_general_ci',
* );
* @endcode
*
* You can optionally set prefixes for some or all database table names
* by using the 'prefix' setting. If a prefix is specified, the table
* name will be prepended with its value. Be sure to use valid database
* characters only, usually alphanumeric and underscore. If no prefixes
* are desired, leave it as an empty string ''.
*
* To have all database names prefixed, set 'prefix' as a string:
* @code
* 'prefix' => 'main_',
* @endcode
* To provide prefixes for specific tables, set 'prefix' as an array.
* The array's keys are the table names and the values are the prefixes.
* The 'default' element is mandatory and holds the prefix for any tables
* not specified elsewhere in the array. Example:
* @code
* 'prefix' => array(
* 'default' => 'main_',
* 'users' => 'shared_',
* 'sessions' => 'shared_',
* 'role' => 'shared_',
* 'authmap' => 'shared_',
* ),
* @endcode
* You can also use a reference to a schema/database as a prefix. This maybe
* useful if your DBTNG installation exists in a schema that is not the default
* or you want to access several databases from the same code base at the same
* time.
* Example:
* @code
* 'prefix' => array(
* 'default' => 'main.',
* 'users' => 'shared.',
* 'sessions' => 'shared.',
* 'role' => 'shared.',
* 'authmap' => 'shared.',
* );
* @endcode
* NOTE: MySQL and SQLite's definition of a schema is a database.
*
* Database configuration format:
* @code
* $databases['default']['default'] = array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => '',
* );
* $databases['default']['default'] = array(
* 'driver' => 'pgsql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => '',
* );
* $databases['default']['default'] = array(
* 'driver' => 'sqlite',
* 'database' => '/path/to/databasefilename',
* );
* @endcode
*/

global $databases;

$databases['default']['default'] = array(
'driver' => 'pgsql',
'database' => 'dbtng',
'username' => 'drupal',
'host' => 'localhost',
'prefix' => '',
);

if (!function_exists('t')) {
function t($text, $vars = array()) {
return strtr($text, $vars);
}
}

define('DBTNG_DIR', dirname(__FILE__));

include_once DBTNG_DIR . '/database.inc';
2 changes: 1 addition & 1 deletion pgsql/schema.inc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
// Set the correct database-engine specific datatype.
// In case one is already provided, force it to lowercase.
if (isset($field['pgsql_type'])) {
$field['pgsql_type'] = drupal_strtolower($field['pgsql_type']);
$field['pgsql_type'] = strtolower($field['pgsql_type']);
}
else {
$map = $this->getFieldTypeMap();
Expand Down
157 changes: 157 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

/**
* Database settings:
*
* The $databases array specifies the database connection or
* connections that DBTNG may use. DBTNG is able to connect
* to multiple databases, including multiple types of databases,
* during the same request.
*
* Each database connection is specified as an array of settings,
* similar to the following:
* @code
* array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'port' => 3306,
* 'prefix' => 'myprefix_',
* 'collation' => 'utf8_general_ci',
* );
* @endcode
*
* The "driver" property indicates what DBTNG driver the connection
* should use. This is usually the same as the name of the database
* type, such as mysql or sqlite, but not always. The other
* properties will vary depending on the driver. For SQLite, you must
* specify a database file name in a directory that is writable by the
* webserver. For most other drivers, you must specify a
* username, password, host, and database name.
*
* Some database engines support transactions. In order to enable
* transaction support for a given database, set the 'transactions' key
* to TRUE. To disable it, set it to FALSE. Note that the default value
* varies by driver. For MySQL, the default is FALSE since MyISAM tables
* do not support transactions.
*
* For each database, you may optionally specify multiple "target" databases.
* A target database allows DBTNG to try to send certain queries to a
* different database if it can but fall back to the default connection if not.
* That is useful for master/slave replication, as DBTNG may try to connect
* to a slave server when appropriate and if one is not available will simply
* fall back to the single master server.
*
* The general format for the $databases array is as follows:
* @code
* $databases['default']['default'] = $info_array;
* $databases['default']['slave'][] = $info_array;
* $databases['default']['slave'][] = $info_array;
* $databases['extra']['default'] = $info_array;
* @endcode
*
* In the above example, $info_array is an array of settings described above.
* The first line sets a "default" database that has one master database
* (the second level default). The second and third lines create an array
* of potential slave databases. DBTNG will select one at random for a given
* request as needed. The fourth line creates a new database with a name of
* "extra".
*
* For a single database configuration, the following is sufficient:
* @code
* $databases['default']['default'] = array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => 'main_',
* 'collation' => 'utf8_general_ci',
* );
* @endcode
*
* You can optionally set prefixes for some or all database table names
* by using the 'prefix' setting. If a prefix is specified, the table
* name will be prepended with its value. Be sure to use valid database
* characters only, usually alphanumeric and underscore. If no prefixes
* are desired, leave it as an empty string ''.
*
* To have all database names prefixed, set 'prefix' as a string:
* @code
* 'prefix' => 'main_',
* @endcode
* To provide prefixes for specific tables, set 'prefix' as an array.
* The array's keys are the table names and the values are the prefixes.
* The 'default' element is mandatory and holds the prefix for any tables
* not specified elsewhere in the array. Example:
* @code
* 'prefix' => array(
* 'default' => 'main_',
* 'users' => 'shared_',
* 'sessions' => 'shared_',
* 'role' => 'shared_',
* 'authmap' => 'shared_',
* ),
* @endcode
* You can also use a reference to a schema/database as a prefix. This maybe
* useful if your DBTNG installation exists in a schema that is not the default
* or you want to access several databases from the same code base at the same
* time.
* Example:
* @code
* 'prefix' => array(
* 'default' => 'main.',
* 'users' => 'shared.',
* 'sessions' => 'shared.',
* 'role' => 'shared.',
* 'authmap' => 'shared.',
* );
* @endcode
* NOTE: MySQL and SQLite's definition of a schema is a database.
*
* Database configuration format:
* @code
* $databases['default']['default'] = array(
* 'driver' => 'mysql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => '',
* );
* $databases['default']['default'] = array(
* 'driver' => 'pgsql',
* 'database' => 'databasename',
* 'username' => 'username',
* 'password' => 'password',
* 'host' => 'localhost',
* 'prefix' => '',
* );
* $databases['default']['default'] = array(
* 'driver' => 'sqlite',
* 'database' => '/path/to/databasefilename',
* );
* @endcode
*/

global $databases;

$databases['default']['default'] = array(
'driver' => 'pgsql',
'database' => 'drupal7',
'username' => 'drupal',
'host' => 'localhost',
'prefix' => '',
);

if (!function_exists('t')) {
function t($text, $vars = array()) {
return strtr($text, $vars);
}
}

define('DBTNG_DIR', dirname(__FILE__));

include_once DBTNG_DIR . '/database.inc';
2 changes: 1 addition & 1 deletion sqlite/database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @{
*/

include_once DRUPAL_ROOT . '/includes/database/prefetch.inc';
include_once DBTNG_DIR . '/prefetch.inc';

/**
* Specific SQLite implementation of DatabaseConnection.
Expand Down
40 changes: 40 additions & 0 deletions tests/DBTNG_PHPUnit_Framework_TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

class DBTNG_PHPUnit_Framework_TestCase extends PHPUnit_Framework_TestCase {

protected $databasePrefix;

public function __construct() {
parent::__construct();
$settings = realpath(dirname(__FILE__) . '/../settings.php');
require_once $settings;
}

public function setUp() {
$this->databasePrefix = 'dbtngtest' . mt_rand(1000, 1000000);
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
Database::renameConnection('default', 'dbtng_original_default');
foreach ($connection_info as $target => $value) {
$connection_info[$target]['prefix'] = array(
'default' => $value['prefix']['default'] . $this->databasePrefix,
);
}
Database::addConnectionInfo('default', 'default', $connection_info['default']);
}

public function tearDown() {
// This would be better if it were database specific, but for now we'll
// live with information_schema.
$connection_info = Database::getConnectionInfo('default');
$result = db_query("SELECT table_name FROM information_schema.tables WHERE table_catalog = '" . $connection_info['database'] . "' AND table_schema = 'public'")->fetchAll();
foreach ($result as $row) {
db_drop_table($row->table_name);
}

// Get back to the original connection.
Database::removeConnection('default');
Database::renameConnection('dbtng_original_default', 'default');
}

}
9 changes: 9 additions & 0 deletions tests/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* DBTNG TEST SUITE *
DBTNG uses PHPUnit to run its test suite. To run the tests
You'll need to first install the phpunit framework. See
http://www.phpunit.de/manual/current/en/installation.html
for more information on installing phpunit.

Run unit tests by using the phpunit CLI tool:
$ phpunit tests/schema.test

Loading