Skip to content

Commit

Permalink
Minor fix to xajax stuff in listcontent
Browse files Browse the repository at this point in the history
add a new test (now testing classes that use the database is possible)
remove a few scripts we don't use.
minor fix to cms_userprefs.
  • Loading branch information
calguy1000 committed Nov 23, 2012
1 parent 4fd77f3 commit 448dc16
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 134 deletions.
2 changes: 1 addition & 1 deletion admin/listcontent.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// $xajax->register(XAJAX_FUNCTION,'reorder_display_list');
// $xajax->register(XAJAX_FUNCTION,'reorder_process');
$xajax->processRequest();
$headtext = $xajax->getJavascript($config['root_url'] . '/lib/xajax')."\n";
$headtext = $xajax->getJavascript('../lib/xajax')."\n";
include_once("header.php");

function prettyurls_ok()
Expand Down
21 changes: 0 additions & 21 deletions autogen.sh

This file was deleted.

8 changes: 0 additions & 8 deletions cleardb.sh

This file was deleted.

25 changes: 0 additions & 25 deletions generatedump.php

This file was deleted.

49 changes: 21 additions & 28 deletions lib/classes/class.cms_userprefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ private static function _read($userid)
$db = cmsms()->GetDb();
$query = 'SELECT preference,value FROM '.cms_db_prefix().'userprefs WHERE user_id = ?';
$dbr = $db->GetArray($query,array($userid));
if( is_array($dbr) )
{
if( !is_array(self::$_prefs) ) self::$_prefs = array();
self::$_prefs[$userid] = array();
for( $i = 0; $i < count($dbr); $i++ )
{
$row = $dbr[$i];
self::$_prefs[$userid][$row['preference']] = $row['value'];
}
if( is_array($dbr) ) {
if( !is_array(self::$_prefs) ) self::$_prefs = array();
self::$_prefs[$userid] = array();
for( $i = 0; $i < count($dbr); $i++ ) {
$row = $dbr[$i];
self::$_prefs[$userid][$row['preference']] = $row['value'];
}
}
}

private static function _userid($value = '')
private static function _userid()
{
return get_userid(false);
}
Expand All @@ -76,10 +74,9 @@ private static function _reset()
public static function get_for_user($userid,$key,$dflt = '')
{
self::_read($userid);
if( isset(self::$_prefs[$userid][$key]) )
{
return self::$_prefs[$userid][$key];
}
if( isset(self::$_prefs[$userid][$key]) ) {
return self::$_prefs[$userid][$key];
}
return $dflt;
}

Expand Down Expand Up @@ -136,16 +133,14 @@ public static function set_for_user($userid,$key,$value)
{
self::_read($userid);
$db = cmsms()->GetDb();
if( !self::exists_for_user($userid,$key) )
{
$query = 'INSERT INTO '.cms_db_prefix().'userprefs (user_id,preference,value) VALUES (?,?,?)';
$dbr = $db->Execute($query,array($userid,$key,$value));
}
else
{
$query = 'UPDATE '.cms_db_prefix().'userprefs SET value = ? WHERE user_id = ? AND preference = ?';
$dbr = $db->Execute($query,array($value,$userid,$key));
}
if( !self::exists_for_user($userid,$key) ) {
$query = 'INSERT INTO '.cms_db_prefix().'userprefs (user_id,preference,value) VALUES (?,?,?)';
$dbr = $db->Execute($query,array($userid,$key,$value));
}
else {
$query = 'UPDATE '.cms_db_prefix().'userprefs SET value = ? WHERE user_id = ? AND preference = ?';
$dbr = $db->Execute($query,array($value,$userid,$key));
}
self::$_prefs[$userid][$key] = $value;
}

Expand Down Expand Up @@ -177,11 +172,9 @@ public static function remove_for_user($userid,$key = '',$like = FALSE)
$parms = array();
$query = 'DELETE FROM '.cms_db_prefix().'userprefs WHERE user_id = ?';
$parms[] = $userid;
if( $key )
{
if( $key ) {
$query2 = ' AND preference = ?';
if( $like )
{
if( $like ) {
$query2 = ' AND preference LIKE ?';
$key .= '%';
}
Expand Down
51 changes: 0 additions & 51 deletions release-cleanup.sh

This file was deleted.

58 changes: 58 additions & 0 deletions tests/database/class.CmsApp.pseudo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

//require_once('cms_test_base.php');
require_once(CMSMS.'/lib/adodb_lite/adodb.inc.php');

function &cmsms()
{
return CmsApp::get_instance();
}

function cms_db_prefix()
{
$config = cmsms()->GetConfig();
return $config['db_prefix'];
}

final class CmsApp
{
private $_db;
private static $_instance;

public static function &get_instance()
{
if( !self::$_instance ) {
self::$_instance = new CmsApp;
}
return self::$_instance;
}

protected function __construct()
{
}

public function &GetDb()
{
if( !$this->_db ) {
$config = $this->GetConfig();
$this->_db = ADONewConnection('mysqli','pear:date:extend');
$r = $this->_db->Connect($config['db_host'],$config['db_user'],$config['db_pass'],$config['db_name']);
if( !$r ) {
$str = "Attempt to connect to database {$config['db_name']} on {$config['db_user']}@{$config['db_host']} failed";
throw new Exception($str);
}
$this->_db->SetFetchMode(ADODB_FETCH_ASSOC);
}
return $this->_db;
}

public function GetConfig()
{
global $test_settings;
return $test_settings;
}


} // end of class

?>
62 changes: 62 additions & 0 deletions tests/database/test_cms_siteprefs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

require_once('class.CmsApp.pseudo.php');
require_once(CMSMS.'/lib/classes/class.cms_siteprefs.php');

class Test_cms_siteprefs extends UnitTestCase
{
public function setUp()
{
parent::setUp();

$config = cmsms()->GetConfig();
$dbdict = NewDataDictionary(cmsms()->GetDb());
$taboptarray = array('mysql' => 'ENGINE MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci',
'mysqli' => 'ENGINE MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci');

$flds = "
sitepref_name C(255) KEY,
sitepref_value text,
create_date DT,
modified_date DT
";
$sqlarray = $dbdict->CreateTableSQL($config['db_prefix'].'siteprefs', $flds, $taboptarray);
$return = $dbdict->ExecuteSQLArray($sqlarray);
}

public function tearDown()
{
$config = cmsms()->GetConfig();
$dbdict = NewDataDictionary(cmsms()->GetDb());
$sqlarray = $dbdict->DropTableSQL($config['db_prefix'].'siteprefs');
$return = $dbdict->ExecuteSQLArray($sqlarray);
}

public function TestSetGet1()
{
cms_siteprefs::set('test1','val1');
cms_siteprefs::set('test2','val2');
$this->assertEqual(cms_siteprefs::get('test1'),'val1');
}

public function TestExists()
{
$this->assertTrue(cms_siteprefs::exists('test1'));
}

public function TestRemove()
{
cms_siteprefs::remove('test2');
$this->assertFalse(cms_siteprefs::exists('test2'));
}

public function TestExists2()
{
cms_siteprefs::set('test1','');
$this->assertTrue(cms_siteprefs::exists('test1'));

cms_siteprefs::set('test1',null);
$this->assertTrue(cms_siteprefs::exists('test1'));
}
} // end of class
?>

0 comments on commit 448dc16

Please sign in to comment.