Permalink
Browse files

Style fix.

Improved check for createDatabase.
  • Loading branch information...
gpongelli committed Jun 11, 2012
1 parent 5a75e70 commit 60352cc8028a3aa2a647f4ae9f68feb535693be6
@@ -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.
*
@@ -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.
*
@@ -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.
*

0 comments on commit 60352cc

Please sign in to comment.