Permalink
Browse files

Metadata handling added

  • Loading branch information...
1 parent 3bb480f commit 324214465c167ef1b6badbf895236ae4ea1ed91e @arunoda committed Nov 18, 2009
@@ -39,7 +39,7 @@
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/
-$autoload['libraries'] = array();
+$autoload['libraries'] = array('database');
/*
@@ -51,7 +51,7 @@
| $autoload['helper'] = array('url', 'file');
*/
-$autoload['helper'] = array('user');
+$autoload['helper'] = array('user','metadata');
/*
@@ -38,9 +38,9 @@
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
-$db['default']['username'] = "";
-$db['default']['password'] = "";
-$db['default']['database'] = "";
+$db['default']['username'] = "root";
+$db['default']['password'] = "maxapower";
+$db['default']['database'] = "code51test";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
@@ -10,7 +10,6 @@ function Welcome()
function index()
{
$this->load->view('welcome_message');
- var_dump($this->user);
}
}
@@ -0,0 +1,40 @@
+<?php
+
+class Metadata{
+
+ public static function set($key,$value,$namespace='global'){
+ $CI= get_instance();
+ $db=$CI->db;
+ $sql="insert into metadata values('"
+ .$key."','"
+ .$value."','"
+ .$namespace."') "
+ ." ON DUPLICATE KEY UPDATE `value`='$value'";
+ return $db->query($sql);
+
+ }
+
+ public static function get($key,$namespace='global'){
+ $CI= get_instance();
+ $db=$CI->db;
+ $sql="SELECT * FROM metadata WHERE `key` LIKE '$key' AND `namespace` ".
+ "LIKE '$namespace'";
+ $query= $db->query($sql);
+
+ if($query->result()==null) return null;
+ $rtn=array();
+ foreach($query->result() as $val){
+ $rtn[$val->namespace][$val->key]=$val->value;
+ }
+ return $rtn;
+ }
+
+ public static function delete($key,$namespace='global'){
+ $CI= get_instance();
+ $db=$CI->db;
+ $sql="DELETE FROM metadata WHERE `key` LIKE '$key' AND `namespace` ".
+ "LIKE '$namespace'";
+ return $db->query($sql);
+ }
+
+}
@@ -0,0 +1,33 @@
+<?php
+
+class Metadata_helper extends CodeIgniterUnitTestCase{
+ function test_included(){
+ $this->assertTrue(class_exists('Metadata'));
+ }
+
+ function test_set(){
+ $this->assertTrue(Metadata::set('key','value','namespace'));
+ }
+
+ function test_get(){
+ $users=Metadata::get('email','user._');
+ $usernames=array();
+ foreach ($users as $user){
+ $usernames[]=$user['email'];
+ }
+ }
+
+ function test_delete(){
+ $this->assertTrue(Metadata::delete('email','user.1'));
+ }
+
+ function test_all1(){
+ Metadata::set('username','arunoda','user.1');
+ $res=Metadata::get('username','user.1');
+ $this->assertEqual('arunoda',$res['user.1']['username']);
+
+ Metadata::delete('user%','user.%');
+ $res=Metadata::get('username','user.1');
+ $this->assertNull($res,"found $res");
+ }
+}
@@ -4,4 +4,19 @@ class User_helper extends CodeIgniterUnitTestCase{
function test_included(){
$this->assertTrue(class_exists('User'));
}
+
+ /**
+ * Functionalities we expect from the POC
+ * --------------------------------------
+ * 1.fields (id,username,email,fullname,salt,password)
+ * 2.save()
+ * 3.get_id()
+ * 4.set_password()
+ * 5.set_session()
+ * 5.check_password()
+ * 6.::by_id()
+ * 7.::by_username()
+ * 8.::by_email()
+ * 9.::by_session()
+ */
}
@@ -0,0 +1,7 @@
+<?php
+
+class Database_Library extends CodeIgniterUnitTestCase{
+ function test_included(){
+ $this->assertNotNull($this->ci->db,"Database not defined!");
+ }
+}

0 comments on commit 3242144

Please sign in to comment.