예제 #1
0
 public function test_update()
 {
     $x = new Character(__METHOD__, 1, $this->dbObj);
     $x->load($this->dbObj);
     $data = $x->data;
     $this->assertTrue(is_numeric($x->characterId));
     $this->assertTrue(is_array($x->data));
     $this->assertTrue(isset($data['character_name']), ToolBox::debug_print($data));
     $x->update('character_name', __FUNCTION__);
     $this->assertNotEquals($data, $x->data);
     $x->load($this->dbObj);
     $this->assertEquals($data, $x->data);
     $x->update('character_name', __CLASS__);
     $this->assertNotEquals($data, $x->data);
     $this->assertTrue($x->save($this->dbObj));
     $this->assertNotEquals($data, $x->load($this->dbObj));
     $data['character_name'] = __CLASS__;
     $this->assertEquals($data, $x->data);
     $changes = array('speed' => 999, 'hair_color' => "GReEEN", 'size' => "Medium Large-ish", 'notes' => "MOREea STUFfl   qaewrqwe   \n\t");
     $x->mass_update($changes);
     $this->assertTrue($x->save($this->dbObj));
     $afterMassUpdate = $x->load($this->dbObj);
     foreach ($changes as $k => $v) {
         $this->assertEquals($v, $afterMassUpdate[$k]);
     }
 }
예제 #2
0
 public function test_basics()
 {
     $this->assertTrue(is_dir($this->dir));
     $myFile = __CLASS__ . '-test.lock';
     $myTestContents = '(' . __FILE__ . ') ' . __METHOD__ . ': line #' . __LINE__ . ': This is a test... ' . microtime(true);
     $lf = new _test_csLockfile($this->dir, $myFile);
     $this->assertEquals($myFile, $lf->lockFile);
     $this->assertFalse(file_exists($myFile));
     $lf->create_lockfile($myTestContents);
     $this->assertEquals($this->dir . '/' . $myFile, $lf->get_lockfile(), ToolBox::debug_print($lf, 0));
     $this->assertTrue(file_exists($myFile));
     $this->assertEquals(file_get_contents($myFile), $myTestContents);
     $this->assertEquals(file_get_contents($myFile), $lf->read_lockfile());
     $this->assertNotEquals(file_get_contents($myFile), $myTestContents . ' ');
     $lf->delete_lockfile();
     $this->assertFalse(file_exists($myFile));
     $numLocks = 10;
     $locks = array();
     for ($x = 0; $x < $numLocks; $x++) {
         $locks[$x] = new _test_csLockfile($this->dir, $x . '.lock');
     }
     $this->assertEquals(count($locks), $numLocks);
     foreach ($locks as $i => $lock) {
         $this->assertFalse(file_exists($this->dir . '/' . $i . '.lock'));
         $this->assertTrue((bool) $lock->create_lockfile('test... ' . $i));
         $this->assertEquals(basename($this->dir . '/' . $i . '.lock'), basename($lock->get_lockfile()));
         $this->assertTrue($lock->delete_lockfile());
         $this->assertTrue((bool) strlen($lock->get_lockfile()));
         $this->assertFalse(file_exists($lock->get_lockfile()));
     }
 }
예제 #3
0
 public function test_connect()
 {
     $this->assertEquals('mysql', $this->type);
     $this->assertTrue(is_object($this->dbObj));
     $this->assertTrue($this->dbObj->is_connected());
     $this->assertEquals(1, parent::reset_db(__DIR__ . '/../setup/schema.mysql.sql'), ToolBox::debug_print($this->dbObj, 0));
 }
 public function test_get_logs()
 {
     $x = new cs_webdblogger($this->dbObj, __CLASS__);
     // create some logs to search through.
     //		$x->log_by_class(__METHOD__, "error");
     $createRecords = array('MAIN' => array('first', 'second', 'third', 'fourth'), 'xxx' => array('fifth', 'sixth'), 'error' => array('seventh'), 'another' => array('EigTh'));
     $totalRecords = 0;
     $testRecords = array();
     $byClass = array();
     foreach ($createRecords as $class => $list) {
         foreach ($list as $details) {
             $id = $x->log_by_class($details, $class);
             $this->assertTrue(is_numeric($id));
             $testRecords[$id] = $details;
             if (isset($byClass[$class])) {
                 $byClass[$class]++;
             } else {
                 $byClass[$class] = 1;
             }
             $totalRecords++;
         }
     }
     foreach (array_keys($createRecords) as $class) {
         $theLogs = $x->get_logs($class);
         $this->assertEquals(count($createRecords[$class]), count($theLogs), "Failed to find logs that match '" . $class . "'... " . ToolBox::debug_print($theLogs));
     }
     //		$data = $x->get_logs(null);
     //
     //		$this->assertEquals(1, count($data), ToolBox::debug_print($data,1));
     //
     //		$this->assertEquals(1, count($x->get_logs('test')));
 }
예제 #5
0
 public function test_save()
 {
     $test = array(Message::TYPE_FATAL => array(0 => array('title' => "Fatal error", 'body' => "there was a fatal error... somewhere")), Message::TYPE_NOTICE => array(0 => array('title' => 'test', 'body' => 'The message body'), 1 => array('title' => 'another', 'body' => "a test body", 'url' => 'http://localhost/?x=y', 'linkText' => 'go to localhost')));
     $_SESSION[MessageQueue::SESSIONKEY] = $test;
     $q = new MessageQueue(true);
     $q->save();
     // make sure Message::save() hasn't been called (which saves to "message" instead of "messages")
     $this->assertFalse(isset($_SESSION[Message::SESSIONKEY]));
     //fix up our test data so things are in the correct order.
     foreach ($test as $k => $data) {
         foreach ($data as $i => $msg) {
             $url = null;
             if (isset($msg['url'])) {
                 $url = $msg['url'];
             }
             $txt = null;
             if (isset($msg['linkText'])) {
                 $txt = $msg['linkText'];
             }
             $newMsg = array('title' => $msg['title'], 'body' => $msg['body'], 'url' => $url, 'type' => $k, 'linkText' => $txt);
             $test[$k][$i] = $newMsg;
         }
     }
     $this->assertEquals($test, $_SESSION[MessageQueue::SESSIONKEY], ToolBox::debug_print($_SESSION, 0));
     $this->assertEquals(3, $q->getCount());
     $this->assertEquals(1, $q->getCount(Message::TYPE_FATAL));
     $this->assertEquals(2, $q->getCount(Message::TYPE_NOTICE));
     $this->assertEquals(0, $q->getCount(Message::TYPE_ERROR));
     $this->assertEquals(0, $q->getCount(Message::TYPE_STATUS));
 }
 public function run_upgrade()
 {
     #$this->db->beginTrans(__METHOD__);
     ToolBox::debug_print(__METHOD__ . ": running SQL file...");
     $this->db->run_sql_file(dirname(__FILE__) . '/schemaChangesFor_0.6.1.sql');
     #$this->db->commitTrans(__METHOD__);
     return true;
 }
 public function test_get_total_weight()
 {
     $x = new CharacterSheet($this->dbObj, __METHOD__, 1);
     $this->assertTrue(is_numeric($x->characterId), ToolBox::debug_print($x));
     $this->assertEquals(0, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(true), $x->get_total_weight(false));
     //now create some gear.
     $manualWeight = 0;
     $itemList = array();
     $createThis = array(array('torches', 1, 10), array('lead nuggets', 10, 10), array('misc', 4, 200));
     $g = new Gear();
     $g->characterId = $x->characterId;
     foreach ($createThis as $data) {
         $manualWeight += round($data[1] * $data[2], 1);
         $xData = array('character_id' => $x->characterId, 'gear_name' => $data[0], 'weight' => $data[1], 'quantity' => $data[2]);
         $id = $g->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
     }
     $this->assertEquals($manualWeight, Gear::calculate_list_weight($itemList));
     //now, at first, this should be 0 because we haven't re-loaded the sheet.
     $this->assertEquals(0, $x->get_total_weight(false));
     $this->assertEquals(0, $x->get_total_weight(true));
     $x->load();
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($manualWeight, $x->get_total_weight(true));
     $withWeapons = $manualWeight;
     $w = new Weapon();
     $w->characterId = $x->characterId;
     $wpns = array('great_sword' => 5, 'long_sword' => 2, 'short_sword' => 1);
     foreach ($wpns as $name => $wgt) {
         $xData = array('character_id' => $x->characterId, 'weapon_name' => $name, 'weight' => $wgt);
         $id = $w->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
         $withWeapons += $wgt;
     }
     $x->load();
     $this->assertNotEquals($manualWeight, $withWeapons);
     $this->assertTrue($withWeapons > $manualWeight);
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(), $x->get_total_weight(false));
     $this->assertEquals($withWeapons, $x->get_total_weight(true));
     $withArmor = $withWeapons;
     $a = new Armor();
     $rmr = array('big' => 10, 'small' => 1);
     foreach ($rmr as $name => $wgt) {
         $xData = array('character_id' => $x->characterId, 'armor_name' => $name, 'weight' => $wgt);
         $id = $a->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
         $withArmor += $wgt;
     }
     $x->load();
     $this->assertNotEquals($manualWeight, $withArmor);
     $this->assertTrue($withArmor > $withWeapons);
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(), $x->get_total_weight(false));
     $this->assertEquals($withArmor, $x->get_total_weight(true));
 }
예제 #8
0
 /**
  * @codeCoverageIgnore
  */
 public function check_requirements()
 {
     // TODO: make *sure* to stop if there's a lockfile from cs_webdbupgrade.
     $retval = false;
     if ($this->lock->is_lockfile_present()) {
         $retval = true;
     } else {
         ToolBox::debug_print(__METHOD__ . ": lockfile missing (" . $this->lock->get_lockfile() . ") while attempting to run test '" . $this->getLabel() . "'");
     }
     return $retval;
 }
예제 #9
0
function debug_backtrace($printItForMe = NULL, $removeHR = NULL)
{
    if (is_null($printItForMe)) {
        if (defined('DEBUGPRINTOPT')) {
            $printItForMe = constant('DEBUGPRINTOPT');
        } elseif (isset($GLOBALS['DEBUGPRINTOPT'])) {
            $printItForMe = $GLOBALS['DEBUGPRINTOPT'];
        }
    }
    if (is_null($removeHR)) {
        if (defined('DEBUGREMOVEHR')) {
            $removeHR = constant('DEBUGREMOVEHR');
        } elseif (isset($GLOBALS['DEBUGREMOVEHR'])) {
            $removeHR = $GLOBALS['DEBUGREMOVEHR'];
        }
    }
    //create our own backtrace data.
    $stuff = \debug_backtrace();
    if (is_array($stuff)) {
        $i = 0;
        foreach ($stuff as $num => $arr) {
            if ($arr['function'] !== "debug_print_backtrace") {
                $fromClass = '';
                if (isset($arr['class']) && strlen($arr['class'])) {
                    $fromClass = $arr['class'] . '::';
                }
                $args = '';
                foreach ($arr['args'] as $argData) {
                    $args = ToolBox::create_list($args, ToolBox::truncate_string(ToolBox::debug_print($argData, 0, 1, false), 600), ', ');
                }
                $fileDebug = "";
                if (isset($arr['file'])) {
                    $fileDebug = " from file <u>" . $arr['file'] . "</u>, line #" . $arr['line'];
                }
                $tempArr[$num] = $fromClass . $arr['function'] . '(' . $args . ')' . $fileDebug;
            }
        }
        array_reverse($tempArr);
        $myData = null;
        foreach ($tempArr as $num => $func) {
            $myData = ToolBox::create_list($myData, "#" . $i . " " . $func, "\n");
            $i++;
        }
    } else {
        //nothing available...
        $myData = $stuff;
    }
    $backTraceData = ToolBox::debug_print($myData, $printItForMe, $removeHR);
    return $backTraceData;
}
 public function run_upgrade()
 {
     // Check if there's an existing auth table...
     $doSecondarySql = false;
     $this->db->beginTrans(__METHOD__);
     ToolBox::debug_print(__METHOD__ . ": running SQL file...");
     $this->db->run_sql_file(dirname(__FILE__) . '/schemaChangesFor_0.4.1.sql');
     if ($doSecondarySql) {
         ToolBox::debug_print(__METHOD__ . ": running SQL file...");
         $this->db->run_sql_file(dirname(__FILE__) . '/schemaChangesFor_0.4.1__existingAuthTable.sql');
     }
     $this->db->commitTrans(__METHOD__);
     return true;
 }
예제 #11
0
 public function test_create_character_defaults_and_modifier()
 {
     $x = new Save();
     $y = new Ability();
     $y->characterId = $this->id;
     $x->characterId = $this->id;
     $y->create_defaults($this->dbObj);
     $numCreated = $x->create_character_defaults($this->dbObj);
     $list = $x->get_all($this->dbObj, $x->characterId);
     $this->assertEquals($numCreated, count($list), ToolBox::debug_print($list));
     foreach ($list as $k => $data) {
         $data = $x->_get_record_extras($data);
         $this->assertEquals($data['total'], $x->calculate_total_save_modifier($data));
     }
 }
예제 #12
0
 public function test_create_and_get_all()
 {
     $x = new Weapon();
     $x->characterId = $this->char->characterId;
     $createdWeapons = array();
     $inUse = array();
     $notInUse = array();
     $testData = array(array('weapon_name' => 'Magic Sword +1', 'total_attack_bonus' => 6, 'damage' => '2d6+9', 'critical' => '20x3', 'range' => 30, 'special' => __METHOD__ . " gives a +1 bonus to geek", 'ammunition' => 10, 'weight' => 3, 'size' => '[HS]', 'weapon_type' => 'geek', 'in_use' => false), array('weapon_name' => 'Test #2...', 'in_use' => true));
     foreach ($testData as $cData) {
         $cData['character_id'] = $x->characterId;
         $id = $x->create($this->dbObj, $cData);
         $this->assertTrue(is_numeric($id));
         $this->assertTrue($id > 0);
         $data = $x->load($this->dbObj);
         $this->assertTrue(is_array($data));
         $this->assertTrue(count($data) >= count($cData));
         $this->assertFalse(isset($createdWeapons[$id]));
         $createdWeapons[$id] = $data;
         if ($cData['in_use']) {
             $inUse[$id] = $data;
         } else {
             $notInUse[$id] = $data;
         }
     }
     $allWeapons = $x->get_all($this->dbObj, $x->characterId);
     $this->assertTrue(is_array($allWeapons));
     $this->assertEquals(count($testData), count($allWeapons), ToolBox::debug_print($allWeapons));
     $this->assertTrue(isset($allWeapons[$id]));
     $this->assertTrue(is_array($allWeapons[$id]));
     $this->assertEquals($data, $allWeapons[$id]);
     $testUsedWpns = $x->get_all($this->dbObj, $x->characterId, true);
     $testNotUsedWpns = $x->get_all($this->dbObj, $x->characterId, false);
     $this->assertNotEquals($testNotUsedWpns, $testUsedWpns);
     foreach ($testUsedWpns as $id => $data) {
         $this->assertTrue(isset($createdWeapons[$id]));
         $this->assertEquals($createdWeapons[$id], $data);
     }
     foreach ($testNotUsedWpns as $id => $data) {
         $this->assertTrue(isset($createdWeapons[$id]));
         $this->assertEquals($createdWeapons[$id], $data);
     }
 }
예제 #13
0
 /**
  * Processes all template vars & files, etc, to produce the final page.  NOTE: it is a wise idea
  * for most pages to have this called *last*.
  * 
  * @param $stripUndefVars		(bool,optional) Remove all undefined template vars.
  * 
  * @return (str)				Final, parsed page.
  */
 public function print_page($stripUndefVars = 1)
 {
     $this->unhandledVars = array();
     //Show any available messages.
     $errorBox = $this->process_set_message();
     if ($this->_hasFatalError) {
         $this->change_content($errorBox);
     } else {
         $this->add_template_var("error_msg", $errorBox);
     }
     if (isset($this->templateVars['main'])) {
         //this is done to simulate old behaviour (the "main" templateVar could overwrite the entire main template).
         $out = $this->templateVars['main'];
     } else {
         $out = $this->file_to_string($this->mainTemplate);
     }
     if (!strlen($out)) {
         ToolBox::debug_print($out);
         ToolBox::debug_print($this->mainTemplate);
         ToolBox::debug_print("MANUAL FILE CONTENTS::: " . htmlentities(file_get_contents($this->mainTemplate)));
         exit(__METHOD__ . ": mainTemplate (" . $this->mainTemplate . ") was empty...?");
     }
     $numLoops = 0;
     $tags = array();
     while (preg_match_all('/\\{.\\S+?\\}/', $out, $tags) && $numLoops < 10) {
         $out = ToolBox::mini_parser($out, $this->templateVars, '{', '}');
         $numLoops++;
     }
     if ($stripUndefVars) {
         $out = $this->strip_undef_template_vars($out, $this->unhandledVars);
     }
     print $out;
 }
예제 #14
0
 public function move_file($filename, $destination)
 {
     $retval = FALSE;
     if ($this->is_readable($filename)) {
         if ($this->check_chroot($destination)) {
             //do the move.
             $filename = $this->filename2absolute($filename);
             $destination = $this->filename2absolute($destination);
             $retval = rename($filename, $destination);
         } else {
             ToolBox::debug_print(__METHOD__ . ":: " . $this->check_chroot($destination), 1);
             throw new exception(__METHOD__ . ':: destination is not in the directory path (from=[' . $filename . '], to=[' . $destination . ']');
         }
     }
     return $retval;
 }
예제 #15
0
 public function test_inheritance()
 {
     $_main = new Template(__DIR__ . '/files/templates/inheritance_main.tmpl');
     $_sub = new Template(__DIR__ . '/files/templates/inheritance_sub.tmpl');
     $mainVars = array('inheritance' => "Loads of money", 'separate' => "ONLY FOR MAIN");
     $recordSet = array(0 => array('separate' => 'first'), 1 => array('separate' => 'second'), 2 => array('separate' => 'third'));
     $rows = $_sub->renderRows($recordSet);
     $_main->addVarList($mainVars);
     $_main->addVar('subTemplate', $rows, false);
     $rendered = $_main->render(false);
     $this->assertEquals(0, count(Template::getTemplateVarDefinitions($rendered)));
     $this->assertEquals(1, preg_match('/first||/', $rendered));
     $this->assertEquals(1, preg_match('/second||/', $rendered));
     $this->assertEquals(1, preg_match('/third||/', $rendered));
     $matches = array();
     $this->assertEquals(4, preg_match_all('/Loads of money/', $rendered, $matches), "inheritance failed: " . ToolBox::debug_print($matches, 0));
     $this->assertEquals(4, count($matches[0]), "inheritance failed, not all variables were filled in: " . ToolBox::debug_print($matches) . "\n\n" . ToolBox::debug_print($rendered));
 }
예제 #16
0
 public function test_get_user_data()
 {
     $x = new cs_authUser($this->dbObj);
     $data = $x->get_user_data('test', $x::STATUS_ENABLED);
     $this->assertTrue(is_array($data), ToolBox::debug_print($data));
     $this->assertTrue(isset($data['uid']));
     $this->assertTrue(isset($data['username']));
     $this->assertTrue(isset($data['passwd']));
     //		$this->assertTrue(isset($data['date_created']));
     //		$this->assertTrue(isset($data['last_login']));
     //		$this->assertTrue(isset($data['email']));
     $this->assertTrue(isset($data['user_status_id']));
     try {
         $this->assertFalse(is_array($x->get_user_data('test', $x::STATUS_DISABLED)));
     } catch (Exception $ex) {
         if (!preg_match('/failed to retrieve a single user \\(0\\)/', $ex->getMessage())) {
             $this->fail("unexpected or invalid exception message: " . $ex->getMessage());
         }
     }
     try {
         $this->assertFalse(is_array($x->get_user_data('test', $x::STATUS_PENDING)));
     } catch (Exception $ex) {
         if (!preg_match('/failed to retrieve a single user \\(0\\)/', $ex->getMessage())) {
             $this->fail("unexpected or invalid exception message: " . $ex->getMessage());
         }
     }
     try {
         $this->assertFalse(is_array($x->get_user_data('test', 99999)));
     } catch (Exception $ex) {
         if (!preg_match('/failed to retrieve a single user \\(0\\)/', $ex->getMessage())) {
             $this->fail("unexpected or invalid exception message: " . $ex->getMessage());
         }
     }
 }
 /**
  * Retrieve class name from the given id.
  */
 protected function get_class_name($classId)
 {
     if (is_numeric($classId)) {
         $sql = "SELECT class_name FROM " . self::classTable . " WHERE class_id=:classId";
         try {
             $numRows = $this->db->run_query($sql, array('classId' => $classId));
             $data = $this->db->get_single_record();
             if (is_array($data) && isset($data['class_name']) && $numRows == 1) {
                 $className = $data['class_name'];
             } else {
                 throw new exception(__METHOD__ . ": failed to retrieve class " . "name, or invalid return data::: " . ToolBox::debug_print($data, 0));
             }
         } catch (exception $e) {
             throw new exception(__METHOD__ . ": error encountered while " . "retrieving class name::: " . $e->getMessage());
         }
     } else {
         throw new exception(__METHOD__ . ": invalid class ID (" . $classId . ")");
     }
     return $className;
 }
예제 #18
0
 public function test_readWrite()
 {
     $this->reader = new FileSystem(__DIR__);
     $this->reader->cd("files");
     $this->writer = new FileSystem(__DIR__ . '/rw');
     $this->assertEquals($this->reader->realcwd, __DIR__ . '/files');
     $outsideLs = $this->reader->ls("templates");
     $this->reader->cd("templates");
     $insideLs = $this->reader->ls();
     $this->assertEquals($outsideLs, $insideLs);
     //okay, read all the files & make the writer create them.
     foreach ($insideLs as $file => $data) {
         if ($data['type'] == 'file') {
             $this->assertEquals(1, $this->writer->create_file($file));
             $this->assertNotEquals($this->writer->realcwd, $this->reader->realcwd);
             //now read data out of one & write into the other, make sure they're the same size.
             $fileSize = $this->writer->write($this->reader->read($file), $file);
             $this->assertEquals($fileSize, $data['size']);
             //now get rid of the new file.
             $this->writer->rm($file);
         }
     }
     //lets take the contents of ALL of those files, push it into one big file, and make sure it is identical.
     $testFilename_a = 'concat_file.txt';
     $testFilename_aplus = 'concat_file2.txt';
     $this->writer->create_file($testFilename_a);
     $this->writer->create_file($testFilename_aplus);
     $totalSize = 0;
     $totalContent = "";
     $loop = 0;
     foreach ($insideLs as $file => $data) {
         $totalSize += $data['size'];
         $content = $this->reader->read($file);
         $totalContent .= $content;
         $this->writer->openFile($testFilename_a, 'a');
         $this->writer->append_to_file($content, null);
         $this->writer->closeFile();
         $this->writer->openFile($testFilename_aplus, 'a+');
         $this->writer->append_to_file($content, null);
         $this->writer->closeFile();
         $loop++;
     }
     //now lets read each file & see if they have the proper content...
     $this->assertEquals($totalContent, $this->writer->read($testFilename_a));
     $this->assertEquals($totalContent, $this->writer->read($testFilename_aplus));
     //Generated from http://www.lipsum.com/feed/html
     $fileLines = array('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Nam nec risus eu mauris euismod convallis eget eget mi.', 'Morbi eget mi eu sapien mollis porttitor vitae ut augue.', 'Pellentesque porta volutpat sem, quis facilisis nulla dictum vitae.', 'Praesent tempus lorem sit amet tortor tempor blandit.');
     $appendTestFile = 'lipsum.txt';
     $this->writer->create_file($appendTestFile);
     $this->writer->openFile($appendTestFile, 'a+');
     //now let's make the array MASSIVE by replicating the file lines over & over again.
     $finalFileLines = array();
     $replicate = 100;
     $myContent = null;
     $actualNum = 0;
     for ($x = 0; $x < $replicate; $x++) {
         foreach ($fileLines as $x2 => $line) {
             $myLine = "line #" . $actualNum . " " . $line;
             $myContent .= $myLine . "\n";
             $this->writer->append_to_file($myLine);
             $actualNum++;
         }
     }
     $this->writer->closeFile();
     //now make sure the contents of the file are as expected...
     $this->assertEquals($myContent, $this->writer->read($appendTestFile));
     unset($myContent, $finalFileLines);
     //randomly pull a line and make sure it starts with the right phrase.
     $this->writer->openFile($appendTestFile, 'r');
     $linesToTest = 10;
     for ($i = 0; $i < $linesToTest; $i++) {
         $randomLine = rand(0, $actualNum - 1);
         $this->writer->go_to_line($randomLine);
         $lineContents = $this->writer->get_next_line();
         $actualLine = $randomLine + 1;
         $regex = "line #{$randomLine}";
         $error = "fetched line #{$randomLine} ({$actualLine}), should start with '{$regex}', but didn't... actual::: " . $lineContents;
         $this->assertTrue((bool) preg_match('/^' . $regex . ' /', $lineContents), $error);
     }
     $this->writer->go_to_last_line();
     $this->writer->go_to_line($this->writer->lineNum - 2);
     //go back two lines because we're actually past the last line, gotta go 2 up so when we fetch "the next line", it is actually the last.
     $lineContents = $this->writer->get_next_line();
     $this->assertTrue((bool) preg_match('/^line #' . ($this->writer->lineNum - 1) . ' /', $lineContents));
     $this->writer->closeFile();
     //now let's try moving a file.
     $newName = "movedFile.txt";
     $lsData = $this->writer->ls();
     $this->assertTrue(isset($lsData[$appendTestFile]));
     $this->writer->move_file($appendTestFile, $newName);
     //change the array and make sure it is approximately the same.
     $newLsData = $this->writer->ls();
     $tmp = $lsData[$appendTestFile];
     unset($lsData[$appendTestFile]);
     $lsData[$newName] = $tmp;
     $this->assertEquals($newLsData, $lsData);
     //now delete the files.
     $theList = $this->writer->ls();
     foreach ($theList as $file => $garbage) {
         $this->assertTrue(is_file($this->writer->realcwd . '/' . $file), "Not a file (" . $this->writer->realcwd . '/' . $file . ")... full list: " . ToolBox::debug_print(scandir($this->writer->realcwd), false));
         $this->assertTrue($this->writer->rm($file));
     }
 }
예제 #19
0
 protected function doUpdate($sid, $data, $uid = null)
 {
     $retval = null;
     $updateFields = array('session_data' => $data, 'session_id' => $sid);
     if (!is_null($uid) && strlen($uid)) {
         $updateFields['uid'] = $uid;
     } elseif (!is_null($uid) && !strlen($uid)) {
         // no data in UID; it was specifically supplied empty, make it null in DB
         $updateFields['uid'] = null;
     }
     if (is_null($data)) {
         // Avoids accidentally removing session data.
         unset($updateFields['session_data']);
     }
     $sql = 'UPDATE ' . self::tableName . ' SET num_checkins=(num_checkins+1), last_updated=NOW()';
     $addThis = $this->create_sql_update_string($updateFields, array('session_id' => 'varchar(40)'));
     if (strlen($addThis)) {
         $sql .= ', ' . $addThis;
     }
     $sql .= ' WHERE session_id=:session_id';
     try {
         $retval = $this->db->run_update($sql, $updateFields);
     } catch (Exception $e) {
         $message = $e->getMessage() . " --- SQL::: " . $sql . " -- PARAMETERS::: " . strip_tags(ToolBox::debug_print($updateFields, 0));
         $this->exception_handler($message);
         $retval = $message;
     }
     return $retval;
 }
예제 #20
0
 public function test_navigationAndLs()
 {
     $fs = new FileSystem(dirname(__FILE__));
     $thisFile = basename(__FILE__);
     $list = $fs->ls();
     $this->assertTrue(isset($thisFile, $list));
     $this->assertTrue(is_array($list[$thisFile]));
     $this->assertEquals($list[$thisFile]['type'], 'file');
     $this->assertTrue(isset($list['files']));
     $this->assertEquals($list['files']['type'], 'dir');
     $this->assertTrue((bool) $fs->cd('files'));
     $this->assertEquals($fs->cwd, '/files');
     $this->assertEquals($fs->realcwd, dirname(__FILE__) . '/files');
     $this->assertTrue($fs->cdup());
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     //this should fail, because it's higher than allowed.
     $this->assertFalse($fs->cdup());
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     $this->assertTrue((bool) $fs->cd('/'));
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     //make sure we can still find just this file.
     $fileInfo = $fs->ls(basename(__FILE__));
     $this->assertTrue(is_array($fileInfo));
     $this->assertEquals(count($fileInfo), 1, "too many files in the array...");
     $this->assertTrue(isset($fileInfo[basename(__FILE__)]));
     $this->assertTrue(isset($fileInfo[basename(__FILE__)]['type']), "malformed array, should ONLY contain info about this file::: " . ToolBox::debug_print($fileInfo, 0));
 }
예제 #21
0
 public function run_query($sql, array $params = null, array $driverOptions = array())
 {
     try {
         $this->sth = null;
         $this->sth = $this->dbh->prepare($sql, $driverOptions);
         if ($this->sth === false) {
             throw new \Exception(__METHOD__ . ": STH is false... " . ToolBox::debug_print($this->dbh->errorInfo(), 0));
         }
         // TODO: throw an exception on error (and possibly if there were no rows returned)
         $this->sth->execute($params);
         $this->numRows = $this->sth->rowCount();
     } catch (PDOException $px) {
         throw new \Exception(__METHOD__ . ": " . $px->getMessage());
     }
     return $this->numRows;
 }
예제 #22
0
 public function test_get_all()
 {
     $x = new AuthToken($this->dbObj);
     //TODO: test offset/limit
     $this->assertEquals(array(), $x->get_all());
     $x->create_token(__METHOD__, __METHOD__, null, null, 0, 0, 0);
     $x->create_token(__METHOD__, __METHOD__, null, null, 0, 1, 0);
     $x->create_token(__METHOD__, __METHOD__, null, null, 0, 1, 1);
     $firstData = $x->get_all(0);
     $firstKeys = array_keys($firstData);
     $this->assertEquals(2, count($firstData));
     //NOTE: if this fails, the ordering has probably changed.
     $this->assertEquals(0, $firstData[$firstKeys[1]]['uid']);
     $this->assertEquals(0, $firstData[$firstKeys[1]]['token_type_id'], ToolBox::debug_print($firstData));
     $secondData = $x->get_all(1);
     $secondKeys = array_keys($secondData);
     $this->assertEquals(1, count($secondData));
     $this->assertEquals(1, $secondData[$secondKeys[0]]['uid']);
     $this->assertEquals(1, $secondData[$secondKeys[0]]['token_type_id']);
     $this->assertEquals(3, count($x->get_all()));
     $this->assertEquals(2, count($x->get_all(null, 1)));
     $this->assertEquals(1, count($x->get_all(null, 0)));
 }
예제 #23
0
 public function test_create()
 {
     $x = new Skill();
     $x->characterId = $this->char->characterId;
     $a = new Ability();
     $a->characterId = $this->char->characterId;
     $a->create_defaults($this->dbObj);
     $cache = $a->get_all($this->dbObj, $this->char->id);
     $createdSkills = array();
     $this->assertEquals(6, count($cache));
     $this->assertTrue(is_array($this->autoSkills));
     $this->assertTrue(count($this->autoSkills) > 10);
     foreach ($this->autoSkills as $id => $theData) {
         $name = $theData[0];
         $attribute = $theData[1];
         $this->assertTrue(isset($cache[$attribute]), "missing attribute '" . $attribute . "' in cache... " . ToolBox::debug_print($cache, 0));
         $this->assertTrue(isset($cache[$attribute]['ability_id']));
         $insertData = array('character_id' => $x->characterId, 'ability_id' => $cache[$attribute]['ability_id'], 'skill_name' => $name);
         $id = $x->create($this->dbObj, $insertData);
         $this->assertTrue(is_numeric($id));
         $this->assertTrue($id > 0);
         $testData = $x->load($this->dbObj);
         $this->assertTrue(is_array($testData));
         $this->assertTrue(count($testData) > 0);
         foreach ($insertData as $k => $v) {
             $this->assertEquals($v, $testData[$k]);
         }
         $this->assertFalse(isset($createdSkills[$id]));
         $createdSkills[$id] = $testData;
     }
 }
예제 #24
0
 /** @codeCoverageIgnore
  */
 public static function debug_var_dump($data, $printItForMe = null, $removeHr = null)
 {
     ob_start();
     var_dump($data);
     $printThis = ob_get_contents();
     ob_end_clean();
     return ToolBox::debug_print($printThis, $printItForMe, $removeHr);
 }
 function send_activation_email($infoArr)
 {
     //setup the variables for sending the email...
     $to = $infoArr['email'];
     $subj = "New Account Activation [" . $infoArr['uid'] . "]";
     //read-in the contents of the email template.
     $page = new cs_genericPage(false, "content/registrationEmail.tmpl");
     //parse the template...
     foreach ($infoArr as $tmpl => $value) {
         $page->add_template_var($tmpl, $value);
     }
     #$body = mini_parser($tmpl, $infoArr, "{", "}");
     $body = $page->return_printed_page();
     $result = $this->send_single_email($to, $subj, $body);
     $this->debug[__METHOD__] = $result;
     $this->logger->log_by_class(ToolBox::debug_print($this->debug, 0), 'debug');
     return $result;
 }