-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More or less working version of fkDataJson + tests
- Loading branch information
Showing
3 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* | ||
* | ||
* @package Folkso | ||
* @subpackage | ||
* @author Joseph Fahey | ||
* @copyright 2009 Gnu Public Licence (GPL) | ||
*/ | ||
|
||
/** | ||
* @package Folkso | ||
*/ | ||
class folksoDataJson extends folksoDataDisplay { | ||
public $datastyles = array(); | ||
public $type; | ||
public $lineformat; | ||
public $argsperline; | ||
public $titleformat; | ||
public $start; | ||
public $end; | ||
private $linetemplate; | ||
private $linecount; | ||
|
||
/** | ||
* @param $linetemplate Array List of field names to be used with line(). | ||
*/ | ||
public function __construct($linetemplate){ | ||
$this->linetemplate = $linetemplate; | ||
} | ||
|
||
public function activate_style ($type) {} | ||
public function check_display($arr) {} | ||
|
||
public function line ($firstarg) { | ||
$args = func_get_args(); | ||
|
||
if (count($args) > count($this->linetemplate)) { | ||
trigger_error('Argument mismatch (JSON): not enough args.', | ||
E_USER_WARNING); | ||
$useargs = array_slice($args, 0, count($linetemplate)); | ||
$usetemplate = $this->linetemplate; | ||
} | ||
elseif (count($this->linetemplate) > count($args)) { | ||
$usetemplate = array_slice($this->linetemplate, 0, count($args)); | ||
$useargs = $args; | ||
} | ||
else { | ||
$usetemplate = $this->linetemplate; | ||
$useargs = $args; | ||
} | ||
$ret = json_encode(array_combine($usetemplate, $useargs)); | ||
if (is_null($ret)) { | ||
trigger_error('Array mismatch (JSON)', E_USER_ERROR); | ||
} | ||
/** | ||
* We keep track of the lines so that commas get added between lines. | ||
*/ | ||
if ($this->linecount > 0) { | ||
$ret = ',' . $ret; | ||
} | ||
++$this->linecount; | ||
return $ret; | ||
} | ||
|
||
public function startform () { | ||
$this->linecount = 0; | ||
return "["; | ||
} | ||
public function endform () { | ||
$this->linecount = 0; | ||
return "]"; | ||
} | ||
public function title ($arg) { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
require_once('unit_tester.php'); | ||
require_once('reporter.php'); | ||
require_once('folksoTags.php'); | ||
require('folksoDataJson.php'); | ||
require('dbinit.inc'); | ||
|
||
class testOffolksoDataJson extends UnitTestCase { | ||
|
||
function setUp() { | ||
test_db_init(); | ||
/** not using teardown because this function does a truncate | ||
before starting. **/ | ||
$this->dbc = new folksoDBconnect('localhost', 'tester_dude', | ||
'testy', 'testostonomie'); | ||
} | ||
|
||
function testBasic () { | ||
$dj = new folksoDataJson(array('this', 'that')); | ||
$this->assertIsA($dj, folksoDataJson, | ||
'object creation failed'); | ||
$this->assertIsA($dj, folksoDataDisplay, | ||
'inheritance failing'); | ||
|
||
$line = $dj->line('Hiii', 'Haaa'); | ||
$this->assertEqual($line, | ||
'{"this":"Hiii","that":"Haaa"}', | ||
'Line not what it should be: ' . $line); | ||
$total = $dj->startform(); | ||
$total .= $line . ','; | ||
$total .= $dj->line('Zook', 'Zonk'); | ||
$total .= $dj->endform(); | ||
$dec = json_decode($total); | ||
$this->assertTrue($dec, | ||
'Decoded json should not be false'); | ||
|
||
$this->assertEqual($dec[0]->this, | ||
'Hiii', | ||
'Not getting first value back from json: ' | ||
. $total . "\n" | ||
. var_dump($dec)); | ||
$nat = json_encode(array( array('hoop' => 'Hoo', | ||
'hork' => 'Zorp'), | ||
array('hoop' => 'Honk', | ||
'hork' => 'Zoupe') | ||
)); | ||
print $nat; | ||
|
||
|
||
} | ||
}//end class | ||
|
||
$test = &new testOffolksoDataJson(); | ||
$test->run(new HtmlReporter()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
require_once('unit_tester.php'); | ||
require_once('reporter.php'); | ||
require_once('folksoTags.php'); | ||
require_once('folksoUserQuery.php'); | ||
require_once('dbinit.inc'); | ||
|
||
class testOffolksoUserQuery extends UnitTestCase { | ||
|
||
function setUp() { | ||
test_db_init(); | ||
/** not using teardown because this function does a truncate | ||
before starting. **/ | ||
$this->dbc = new folksoDBconnect('localhost', 'tester_dude', | ||
'testy', 'testostonomie'); | ||
} | ||
|
||
function testUserQuery () { | ||
$uq = new folksoUserQuery(); | ||
$this->assertIsA($uq, folksoUserQuery, | ||
'object creation failed'); | ||
|
||
$sql = $uq->resourcesByTag('emacs', 'downhome-2009-001'); | ||
$this->assertTrue(is_string($sql), | ||
'resourceByTag did not return string'); | ||
$this->assertTrue((strlen($sql) > 50), | ||
'resourcesByTag returned a suspiciously short string'); | ||
$this->assertPattern('/downhome/', $sql, | ||
'userid not inserted into sql query by resourcesByTag. '.$sql); | ||
$this->assertPattern('/normalize_tag/', $sql, | ||
'conditional query building not working with alphabetical tag'); | ||
|
||
} | ||
}//end class | ||
|
||
$test = &new testOffolksoUserQuery(); | ||
$test->run(new HtmlReporter()); |