Skip to content

Commit

Permalink
Style fix.
Browse files Browse the repository at this point in the history
Improved check for createDatabase.
  • Loading branch information
gpongelli committed Jun 11, 2012
1 parent 5a75e70 commit 60352cc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libraries/joomla/database/driver.php
Expand Up @@ -436,12 +436,19 @@ public function createDatabase($options, $utf = true)
{
throw new RuntimeException('$options object must not be null.');
}
elseif (!isset($options->db_name) || empty($options->db_name))
{
throw new RuntimeException('$options object must have db_name set.');
}
elseif (!isset($options->db_user) || empty($options->db_user))
{
throw new RuntimeException('$options object must have db_user set.');
}

$this->setQuery($this->getCreateDatabaseQuery($options, $utf));
return $this->execute();
}



/**
* Disconnects the database.
*
Expand Down Expand Up @@ -571,7 +578,7 @@ protected function getCreateDatabaseQuery($options, $utf)

return $query;
}

/**
* Method to get the database collation in use by sampling a text field of a table in the database.
*
Expand Down
Expand Up @@ -258,6 +258,51 @@ public function testCreateDatabase()
self::$driver->createDatabase(null);
}

/**
* Test createDatabase with null database's name.
*
* @return void
*
* @expectedException RuntimeException
*/
public function testCreateDatabase_nullDbName()
{
$obj = new JObject;
$obj->db_user = 'test';

self::$driver->createDatabase($obj);
}

/**
* Test createDatabase with null user's name.
*
* @return void
*
* @expectedException RuntimeException
*/
public function testCreateDatabase_nullUserName()
{
$obj = new JObject;
$obj->db_name = 'test';

self::$driver->createDatabase($obj);
}

/**
* Test createDatabase with empty user's name.
*
* @return void
*
* @expectedException RuntimeException
*/
public function testCreateDatabase_emptyUserName()
{
$obj = new JObject;
$obj->db_name = '';

self::$driver->createDatabase($obj);
}

/**
* Tests the JDatabasePostgresql escape method.
*
Expand Down

0 comments on commit 60352cc

Please sign in to comment.