From b1416327854f1c974b43f14a639f904b97320043 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 16 Oct 2012 22:58:47 +0100 Subject: [PATCH] some mock objects, for testing (coming soon, maybe) --- core/config.class.php | 8 ++++++++ core/database.class.php | 31 ++++++++++++++++++++++++++++++- core/page.class.php | 3 +++ core/user.class.php | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/core/config.class.php b/core/config.class.php index 4fdfc2b4..285fb352 100644 --- a/core/config.class.php +++ b/core/config.class.php @@ -214,4 +214,12 @@ class DatabaseConfig extends BaseConfig { $this->database->cache->delete("config"); } } + +class MockConfig extends HardcodeConfig { + public function __construct($config=array()) { + $config["db_version"] = "999"; + $config["anon_id"] = "0"; + parent::__construct($config); + } +} ?> diff --git a/core/database.class.php b/core/database.class.php index f9e4dabd..0c07b248 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -483,6 +483,35 @@ class Database { return NULL; } } - +} + +class MockDatabase extends Database { + var $query_id = 0; + var $responses = array(); + var $cache = null; + + public function __construct($responses = array()) { + $this->cache = new NoCache(); + $this->responses = $responses; + } + public function execute($query, $params=array()) { + log_debug("mock-database", + "QUERY: " . $query . + "\nARGS: " . var_export($params, true) . + "\nRETURN: " . var_export($this->responses[$this->query_id], true) + ); + return $this->responses[$this->query_id++]; + } + + public function get_all($query, $args=array()) {return $this->execute($query, $args);} + public function get_row($query, $args=array()) {return $this->execute($query, $args);} + public function get_col($query, $args=array()) {return $this->execute($query, $args);} + public function get_pairs($query, $args=array()) {return $this->execute($query, $args);} + public function get_one($query, $args=array()) {return $this->execute($query, $args);} + public function get_last_insert_id($seq) {return $this->query_id;} + + public function scoreql_to_sql($sql) {return $sql;} + public function create_table($name, $def) {} + public function connect_engine() {} } ?> diff --git a/core/page.class.php b/core/page.class.php index 6a562f38..879b4a53 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -283,4 +283,7 @@ class Page { $this->add_html_header(""); } } + +class MockPage extends Page { +} ?> diff --git a/core/user.class.php b/core/user.class.php index a609ebd5..a2f4981a 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -200,4 +200,18 @@ class User { return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token()); } } + +class MockUser extends User { + public function __construct($name) { + $row = array( + "name" => $name, + "id" => 1, + "email" => "", + "joindate" => "", + "pass" => "", + "class" => "admin", + ); + parent::__construct($row); + } +} ?>