From 8c67b79e00db69d33f46bfd6a4332a7e6e7da369 Mon Sep 17 00:00:00 2001 From: Slim Amamou Date: Fri, 8 Feb 2008 09:09:56 +0100 Subject: [PATCH] =?utf8?q?Revert=20"j'ai=20corrig=C3=A9=20un=20bug=20qui?= =?utf8?q?=20empechait=20le=20schema=20browser=20de=20fonctionner=20avec?= =?utf8?q?=20les=20noms=20de=20tables=20bizarres.=20tels=20que=20ceux=20de?= =?utf8?q?=20joomla."?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts commit c4e2c8c1a22d74e854a74fd55d8cf8099826f500. Conflicts: ini.php --- bazdig/bazdig.db | Bin 4096 -> 4096 bytes bazdig/db/set/index.php | 8 +- bazdig/history/index.php | 4 +- index.php | 3 + ini.php | 26 +++--- lib/database.php | 9 +- lib/localresource.php | 24 +++--- lib/mark.php | 213 ---------------------------------------------- lib/pagecopy.php | 80 ----------------- lib/pageselector.php | 45 ---------- lib/user.php | 28 ------ real.ini.php | 12 --- test/MarkTest.php | 160 ---------------------------------- test/PageCopyTest.php | 90 -------------------- test/PageSelectorTest.php | 72 ---------------- test/QueryTest.php | 80 ----------------- 16 files changed, 43 insertions(+), 811 deletions(-) create mode 100644 index.php delete mode 100755 lib/mark.php delete mode 100755 lib/pagecopy.php delete mode 100644 lib/pageselector.php delete mode 100755 lib/user.php delete mode 100644 real.ini.php delete mode 100644 test/MarkTest.php delete mode 100644 test/PageCopyTest.php delete mode 100644 test/PageSelectorTest.php delete mode 100644 test/QueryTest.php diff --git a/bazdig/bazdig.db b/bazdig/bazdig.db index 440128add8b674e989d4c8d911b3806222da3c52..1215223c0e6d4a2dae8eddc9184d78e81fd29c15 100644 GIT binary patch delta 175 zcwTEzXi%6S%{X(T%nN2VM&`8)%xgCbax^nfY*2^|WMm1|wa-m4wK6s|PE9dLF*Zmu zwMel{OENJvNHk1Ivam2VHL|di1Fo!Y{W5?$I+>9&$Vlgg{ delta 441 zcwUWAJ5Iwu5Vbu^V-gf%ml^FH%tmUxLD&&=oT@Ev-{Y7AEJMyZ(ps&Jvs_kaGj@qkYz-2 zKTs$|Q6dv9Vk%s>Z@Vt8^h_u9O);PA64%9Dg=f0Lc~nlTJ>R!m0lvgp zS>!E2Jx{tGajBRP77#z+k;kU~Rw)tlget('/console')->url ); diff --git a/bazdig/history/index.php b/bazdig/history/index.php index 258b3bd..e56de50 100644 --- a/bazdig/history/index.php +++ b/bazdig/history/index.php @@ -5,9 +5,9 @@ require "code.php"; - $dbFile = $bazdig->get("/bazdig.db"); + $dbFile = $bazdig->getparam("db")->file; $console = $bazdig->get("/console"); - SqlCode::set_db("sqlite:". $dbFile->get_file()); + SqlCode::set_db("sqlite:". $dbFile); if ($_GET['q']) { $queries = SqlCode::search($_GET['q']); diff --git a/index.php b/index.php new file mode 100644 index 0000000..dfc90db --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ +get(WARAQ_ROOT . '/bazdig'); + + $GLOBALS['bazdig'] = new WaraqService($bazdigService->url, $bazdigService->file); $bazdig =& $GLOBALS['bazdig']; - $bazdig->setparam("db", $bazdig->get('/bazdig.db')); + $bazdig->setparam("db", $bazdig->get('bazdig.db')); -function columnNames($row) -{ - $names = array(); - if (is_array($row)) $names = array_keys($row); - return $names; +function firstWord($string) + $string = trim($string); + return str_trunkate($string, ' '); } -function firstWord($string) +function str_trunkate($haystack, $needle) { - $string = trim($string); - if (!$pos = strpos($string, ' ')) return $string; - return substr($string, 0, $pos); + if (!$pos = strpos($haystack, $needle)) return $haystack; + return substr($haystack, 0, $pos); } diff --git a/lib/database.php b/lib/database.php index ae8ca42..87648d3 100755 --- a/lib/database.php +++ b/lib/database.php @@ -84,7 +84,7 @@ $createQuery = new SqlCode($row['sql']); $this->columns = $createQuery->extractColumns(); } else { - $query = "show columns from `$table`"; + $query = "show columns from $table"; $result = $db->query($query); foreach ($result as $column) { $this->columns []= new Column($column['Field'], $column['Type']); @@ -107,3 +107,10 @@ $this->type = $type; } } + +function columnNames($row) + $names = array(); + if (is_array($row)) $names = array_keys($row); + return $names; +} + diff --git a/lib/localresource.php b/lib/localresource.php index 96751fc..37b01bb 100755 --- a/lib/localresource.php +++ b/lib/localresource.php @@ -6,19 +6,20 @@ function __construct($url, $file) { - $this->url = $url; - $this->file = $file; - } - - function LocalResource($url, $file) - { - $this->__construct($url, $file); + $this->url = absolutize($url); + $this->file = absolutize($file); } function get($path) { - $u = absolutize($this->url .'/'. $path); - $f = absolutize($this->file .'/'. $path); + $f = $this->file .'/'. $path; + if (strpos($this->url, '?')) { + $u = str_replace('?', "/$path?", $this->url ); + } else if (strpos($this->url, '#')) { + $u = str_replace('#', "/$path#", $this->url ); + } else { + $u = $this->url .'/'. $path; + } $r = new LocalResource($u, $f); return $r; } @@ -37,10 +38,7 @@ function absolutize($path) { $path = ereg_replace('/\./', '/', $path); - while (ereg('/[^/.]+/\.\./', $path)) { - $path = ereg_replace('/[^/.]+/\.\./', '/', $path); - } + $path = ereg_replace('/[^/.]+/+\.\./', '/', $path); return $path; } -?> diff --git a/lib/mark.php b/lib/mark.php deleted file mode 100755 index e0a1641..0000000 --- a/lib/mark.php +++ /dev/null @@ -1,213 +0,0 @@ -creationDate = time(); - if ($id) { - $this->id = $id; - } - } - - static function get_table_name() - { - return "marks"; - } - - static function sql_select($wildcards = NULL) - { - $tableName = self::get_table_name(); - - $order = ' order by creationDate desc, pageUrl '; - if (array_key_exists('order', $wildcards)) { - $order = " order by ". $wildcards['order']; - unset($wildcards['order']); - } - - $limit = ''; - if (array_key_exists('limit', $wildcards)) { - $limit = " limit ". $wildcards['limit']; - unset($wildcards['limit']); - } - - if (empty($wildcards)) { - return "SELECT id, creationDate, pageUrl, text, owner, startNodePath, startOffset, endNodePath, endOffset from $tableName $order $limit;"; - } - - $tuples = array(); - if (array_key_exists('pageUrl', $wildcards)) { - $tuples []= " pageUrl LIKE '". $wildcards['pageUrl'] ."%'"; - unset($wildcards['pageUrl']); - } - - foreach ($wildcards as $key => $value) { - $tuples []= "$key='$value'"; - } - - $conditions = implode(' and ', $tuples); - - $query = "SELECT id, creationDate, pageUrl, text, owner, startNodePath, startOffset, endNodePath, endOffset from $tableName where $conditions $order $limit;"; - - return $query; - } - - function toHTMLanchor() - { - $anchor = "". $this->text .""; - return $anchor; - } - - function toSQLinsert() - { - $id = $this->id; - $creationDate = date('c', $this->creationDate); - $pageUrl = $this->pageUrl; - $text = $this->text; - $owner = $this->owner; - $startNodePath = $this->startNodePath; - $startOffset = $this->startOffset; - $endNodePath = $this->endNodePath; - $endOffset = $this->endOffset; - - $tableName = Mark::get_table_name(); - return "INSERT into $tableName (id, creationDate, pageUrl, text, owner, startNodePath, startOffset, endNodePath, endOffset) values ('$id', '$creationDate', '$pageUrl', '$text', '$owner', '$startNodePath', '$startOffset', '$endNodePath', '$endOffset');"; - } - - function toSQLselect() - { - return "SELECT creationDate, pageUrl, text, owner, startNodePath, startOffset, endNodePath, endOffset from marks where id='". $this->id ."';"; - } - - static function set_db($db, $user = "", $password = "") - { - if ($db instanceof PDO) { - self::$db =& $db; - } else { - if (empty($user)) { - self::$db =& new PDO($db); - } else { - self::$db =& new PDO($db, $user, $password); - } - } - - return self::$db; - } - - static function count($wildcards = NULL, $db = NULL) - { - if ($db == NULL) { - $db = self::$db; - } - if (! $db instanceof PDO) { - throw new Exception("Not a Data Base"); - } - - $tableName = Mark::get_table_name(); - $query = "select count(*) from $tableName"; - if ($result = $db->query($query)) { - $result = $result->fetchAll(); - } else { - echo "Query error"; - print_r($db->errorInfo()); - throw new Exception("Query error"); - } - - return $result[0][0]; - } - - static function select($wildcards = NULL, $db = NULL) - { - if ($db == NULL) { - $db = self::$db; - } - if (! $db instanceof PDO) { - throw new Exception("Not a Data Base"); - } - $marks = array(); - $query = self::sql_select($wildcards); - if ($result = $db->query($query)) { - $result = $result->fetchAll(); - } else { - echo "Query error"; - print_r($db->errorInfo()); - throw new Exception("Query error"); - } - foreach ($result as $r) { - $mark = new Mark($r['id']); - $mark->creationDate = strtotime($r['creationDate']); - $mark->pageUrl = strip_http_get_params($r['pageUrl']); - $mark->text = $r['text']; - $mark->owner = $r['owner']; - $mark->startNodePath = json_decode($r['startNodePath']); - $mark->startOffset = $r['startOffset']; - $mark->endNodePath = json_decode($r['endNodePath']); - $mark->endOffset = $r['endOffset']; - array_push( $marks, $mark); - } - - return $marks; - } - - function save($db = NULL) - { - if ($db == NULL) { - $db = self::$db; - } - $query = $this->toSQLinsert(); - - $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $statement = $db->query($query); - - return $statement; - } - - function load($db = NULL) - { - if ($db == NULL) { - $db = self::$db; - } - if (is_string($db)) { - $db = new PDO($db, $user, $pass); - } - $query = $this->toSQLselect(); - if ($result = $db->query($query)) { - $result = $result->fetch(); - } else { - throw new Exception("Query error"); - } - - $this->creationDate = strtotime($result['creationDate']); - $this->pageUrl = $result['pageUrl']; - $this->text = $result['text']; - $this->owner = $result['owner']; - $this->startNodePath = $result['startNodePath']; - $this->startOffset = $result['startOffset']; - $this->endNodePath = $result['endNodePath']; - $this->endOffset = $result['endOffset']; - - return $this; - } - - function __toString() - { - return json_encode($this); - } - } - -function strip_http_get_params($url) -{ - if (!$urlBaseLength = strpos($url, '?')) return $url; - return substr($url, 0, $urlBaseLength); -} diff --git a/lib/pagecopy.php b/lib/pagecopy.php deleted file mode 100755 index 6a7d397..0000000 --- a/lib/pagecopy.php +++ /dev/null @@ -1,80 +0,0 @@ -date = date("c"); - $this->origin = $origin; - $c = $root->get($name); - $this->file = $c->get_file(); - $this->url = $c->get_url(); - } - - function update() - { - $ch = curl_init(); - $timeout = 5; // set to zero for no timeout - curl_setopt ($ch, CURLOPT_URL, $this->origin); - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); - $file_contents = curl_exec($ch); - curl_close($ch); - - if ($content = $file_contents) { - - if (eregi("", $content)) { - $content = eregi_replace("", "". $this->startOfHEAD , $content); - } else { - $content = eregi_replace("^", "". $this->startOfHEAD , $content); - } - if (eregi("", $content)) { - $content = eregi_replace("", $this->endOfHEAD . "", $content); - } else { - $content = eregi_replace("^", $this->endOfHEAD . "", $content); - } - if (eregi("", $content)) { - $content = eregi_replace("", $this->endOfHTML . "", $content); - } else { - $content = eregi_replace("$", $this->endOfHTML . "", $content); - } - $copy = fopen($this->file, "w"); - if (! fwrite($copy, $content)) { - throw new Exception("Err: Ecriture"); - } - } - } - - function add_to_html($s) - { - $this->endOfHTML .= $s; - } - - function add_to_head($s) - { - $this->endOfHEAD .= $s; - } - - function add_to_head_start($s) - { - $this->startOfHEAD .= $s; - } - } - - function url2fileName($url) - { - $fileName = $url; - $forbidden = array('/',':','?','=','&','+','%'); - $fileName = ereg_replace('^http://', '', $fileName); //remove http:// - $fileName = ereg_replace('#.*$', '', $fileName); //remove fragment id - $fileName = str_replace($forbidden, '_', $fileName); - - return $fileName; - } diff --git a/lib/pageselector.php b/lib/pageselector.php deleted file mode 100644 index 1afd77b..0000000 --- a/lib/pageselector.php +++ /dev/null @@ -1,45 +0,0 @@ -pageCount , "integer"); - settype($itemsCount, "integer"); - settype($itemsPerPage, "integer"); - - $this->baseUrl = $baseUrl; - $this->pageCount = $itemsCount / $itemsPerPage; - } - - function getLinks($page_number) - { - settype($page_number, "integer"); - settype($p, "integer"); - settype($first, "integer"); - settype($last, "integer"); - - $links = array(); - $first = $page_number - (MAX_SELECTABLE_PAGES / 2); - $first = $first > 0 ? $first : 1 ; - $last = $first + MAX_SELECTABLE_PAGES; - $last = $last < $this->pageCount ? $last : $this->pageCount; - - if ($page_number > 1) { - $links['previous'] = $this->baseUrl . ($page_number - 1); - } - for ($p=$first; $p <= $last; $p++) { - if ($p == $page_number) { - $links[$p] = '#'; - } else { - $links[$p] = $this->baseUrl . $p; - } - } - if ($page_number < $this->pageCount) { - $links['next'] = $this->baseUrl . ($page_number + 1); - } - - return $links; - } -} diff --git a/lib/user.php b/lib/user.php deleted file mode 100755 index 556bb7c..0000000 --- a/lib/user.php +++ /dev/null @@ -1,28 +0,0 @@ -select("id")->from("users"); - $rightQuery->where(array('id' => $this->id, 'password' => $this->password)); - } - } diff --git a/real.ini.php b/real.ini.php deleted file mode 100644 index 31eb21d..0000000 --- a/real.ini.php +++ /dev/null @@ -1,12 +0,0 @@ -setparam("db", "mysql:host=localhost;dbname=bazdig"); - $bazdig->setparam("db/user", "root"); - $bazdig->setparam("db/password", ""); -?> diff --git a/test/MarkTest.php b/test/MarkTest.php deleted file mode 100644 index 89c107b..0000000 --- a/test/MarkTest.php +++ /dev/null @@ -1,160 +0,0 @@ -Mark =& new Mark("testid"); - $this->Mark2 =& new Mark("testid2"); - $this->Mark2->pageUrl = "http://localhost/test2"; - $this->Mark2->text = "test text2"; - $this->Mark3 =& new Mark("testid3"); - $this->Mark4 =& new Mark("testid4"); - $this->Mark4->pageUrl = "http://localhost/test?s=55555"; - $this->db =& new PDO("sqlite2:markkit-test.db"); - } - - function tearDown() - { - unset($this->Mark); - $tableName = Mark::get_table_name(); - $this->db->query("delete from $tableName where id='testid2'"); - } - - function testtoSQLinsert() - { - $result = $this->Mark->toSQLinsert(); - $expected = "/insert/i"; - $this->assertWantedPattern($expected, $result); - $expected = "/'testid'/"; - $this->assertWantedPattern($expected, $result); - $result = $this->Mark2->toSQLinsert(); - $expected = "/insert/i"; - $this->assertWantedPattern($expected, $result); - $expected = "/'testid2'/"; - $this->assertWantedPattern($expected, $result); - $expected = "/'http:\/\/localhost\/test2'/"; - $this->assertWantedPattern($expected, $result); - } - - function testtoSQLselect() - { - $result = $this->Mark->toSQLselect(); - $expected = "/select/i"; - $this->assertWantedPattern($expected, $result); - $expected = "/id='testid'/"; - $this->assertWantedPattern($expected, $result); - } - - function testsql_select() - { - $options = array('owner' => "testuser", 'pageUrl' => "http://localhost/dokuwiki/"); - $result = Mark::sql_select($options); - $expected = "/owner='testuser'/i"; - $this->assertWantedPattern($expected, $result); - $expected = "/pageUrl LIKE 'http:\/\/localhost\/dokuwiki\/%'/i"; - $this->assertWantedPattern($expected, $result); - } - - function testselect() - { - $this->Mark->creationDate = "1189807200"; - $this->Mark->pageUrl = "http://localhost/dokuwiki/"; - $this->Mark->text = "test text"; - $this->Mark->owner = "testuser"; - $this->Mark->startNodePath = array(1,2,3); - $this->Mark->startOffset = '0'; - $this->Mark->endNodePath = array(4,5,6); - $this->Mark->endOffset = '0'; - $this->Mark3->creationDate = "1189807200"; - $this->Mark3->pageUrl = "http://localhost/dokuwiki/x"; - $this->Mark3->text = "test text"; - $this->Mark3->owner = "testuser"; - $this->Mark3->startNodePath = array(1,2,3); - $this->Mark3->startOffset = '0'; - $this->Mark3->endNodePath = array(4,5,6); - $this->Mark3->endOffset = '0'; - $options = array('id' => 'testid'); - $result = Mark::select($options, $this->db); - $expected = array($this->Mark); - $this->assertEqual($expected, $result); - Mark::set_db($this->db); - $result = Mark::select($options); - $this->assertEqual($expected, $result); - Mark::set_db("sqlite2:markkit-test.db"); - $result = Mark::select($options); - $this->assertEqual($expected, $result); - $options = array('pageUrl' => "http://localhost/dokuwiki/"); - $result = Mark::select($options); - $expected = array($this->Mark, $this->Mark3); - $this->assertEqual($expected, $result); - } - - function testcount() - { - $result = $this->Mark->count(); - $expected = 3; - $this->assertEqual($expected, $result); - } - - function testsave() - { - $this->Mark2->save($this->db); - $result = $this->db->query("select * from marks where id='testid2'"); - $expected = '00000'; - $this->assertEqual($expected, $result->errorCode()); - $result = $result->fetch(); - $expected = 'http://localhost/test2'; - $this->assertEqual($expected, $result['pageUrl']); - $expected = 'test text2'; - $this->assertEqual($expected, $result['text']); - } - - function testload() - { - $result = $this->Mark->load($this->db); - $expected = "testuser"; - $this->assertEqual($expected, $result->owner); - } - - function testset_db() - { - global $waraq; - - $result = Mark::set_db("mysql:host=localhost;dbname=markkit", "root", ""); - $expected = "mysql"; - $this->assertEqual($expected, $result->getAttribute(PDO::ATTR_DRIVER_NAME)); - $result = Mark::set_db("sqlite2:markkit-test.db"); - $expected = "sqlite2"; - $this->assertEqual($expected, $result->getAttribute(PDO::ATTR_DRIVER_NAME)); - } - - function test_toHTMLanchor() - { - $result = $this->Mark2->toHTMLanchor(); - $expected = "test text2"; - $this->assertEqual($expected, $result); - } - - function test_strip_http_get_params() - { - $result = strip_http_get_params("http://localhost/test?s=55555"); - $expected = "http://localhost/test"; - $this->assertEqual($expected, $result); - } - -} -// Running the test. -$test =& new MarkTest; -$test->run(new HtmlReporter()); -?> diff --git a/test/PageCopyTest.php b/test/PageCopyTest.php deleted file mode 100644 index c50a278..0000000 --- a/test/PageCopyTest.php +++ /dev/null @@ -1,90 +0,0 @@ -PHPUnit_TestCase($name); - } - - function setUp() - { - require_once '../lib/pagecopy.php'; - $url = "http://localhost/slim/markkit/test"; - $file = "/home/slim/markkit-glassjoe/markkit/test"; - $copydir = new LocalResource($url, $file); - $test_url_wf = "$url/test_page_well_formed.html"; - $test_url_ts = "$url/test_page_tag_soup.html"; - $this->PageCopy =& new PageCopy("testcopy.html",$test_url_wf, $copydir); - $this->PageCopyTS =& new PageCopy("testcopy_ts.html",$test_url_ts, $copydir); - } - - function tearDown() - { - unset($this->PageCopy); - unset($this->PageCopyTS); - unlink("testcopy.html"); - @unlink("testcopy_ts.html"); - } - - function testupdate() - { - $this->PageCopy->update(); - $this->assertTrue(is_file("testcopy.html")); - } - - function testadd_to_html() - { - $this->PageCopy->add_to_html("
"); - $this->PageCopy->update(); - $c = file_get_contents("testcopy.html"); - $this->assertTrue(ereg("id='testaddtohtml' />\s*", $c)); - $this->assertFalse(ereg("id='testaddtohtml'.*id='testaddtohtml'", $c)); - $this->PageCopyTS->add_to_html("
"); - $this->PageCopyTS->update(); - $c = file_get_contents("testcopy_ts.html"); - $this->assertTrue(ereg("id='testaddtohtml' />", $c)); - } - - function testadd_to_head() - { - $this->PageCopy->add_to_head("
"); - $this->PageCopy->update(); - $c = file_get_contents("testcopy.html"); - $this->assertTrue(ereg("id='testaddtohtml' />\s*", $c)); - $this->assertFalse(ereg("id='testaddtohtml'.*id='testaddtohtml'", $c)); - $this->PageCopyTS->add_to_head("
"); - $this->PageCopyTS->update(); - $c = file_get_contents("testcopy_ts.html"); - $this->assertTrue(ereg("id='testaddtohtml' />", $c)); - } - - function testadd_to_head_start() - { - $this->PageCopy->add_to_head_start("
"); - $this->PageCopy->update(); - $c = file_get_contents("testcopy.html"); - $this->assertTrue(ereg("\s*
", $c)); - $this->assertFalse(ereg("id='testaddtohtml'.*id='testaddtohtml'", $c)); - $this->PageCopyTS->add_to_head_start("
"); - $this->PageCopyTS->update(); - $c = file_get_contents("testcopy_ts.html"); - $this->assertTrue(ereg("
", $c)); - } -} -// Running the test. -$suite = new PHPUnit_TestSuite('PageCopyTest'); -$result = PHPUnit::run($suite); -echo $result->toString(); -?> diff --git a/test/PageSelectorTest.php b/test/PageSelectorTest.php deleted file mode 100644 index 9faaa7d..0000000 --- a/test/PageSelectorTest.php +++ /dev/null @@ -1,72 +0,0 @@ -PageSelector =& new PageSelector("http://localhost/?p=", 2, 10); - $this->PageSelector2 =& new PageSelector("http://localhost/?p=", 2, 30); - } - - function test_getLinks() { - $result = $this->PageSelector->getLinks(4); - $expected = array('previous' => 'http://localhost/?p=3', - '1' => 'http://localhost/?p=1', - '2' => 'http://localhost/?p=2', - '3' => 'http://localhost/?p=3', - '4' => '#', - '5' => 'http://localhost/?p=5', - 'next' => 'http://localhost/?p=5'); - $this->assertEqual( $expected, $result ); - $result = $this->PageSelector2->getLinks(10); - $expected = array('previous' => 'http://localhost/?p=9', - '5' => 'http://localhost/?p=5', - '6' => 'http://localhost/?p=6', - '7' => 'http://localhost/?p=7', - '8' => 'http://localhost/?p=8', - '9' => 'http://localhost/?p=9', - '10' => '#', - '11' => 'http://localhost/?p=11', - '12' => 'http://localhost/?p=12', - '13' => 'http://localhost/?p=13', - '14' => 'http://localhost/?p=14', - '15' => 'http://localhost/?p=15', - 'next' => 'http://localhost/?p=11'); - $this->assertEqual( $expected, $result ); - $result = $this->PageSelector2->getLinks(3); - $expected = array('previous' => 'http://localhost/?p=2', - '1' => 'http://localhost/?p=1', - '2' => 'http://localhost/?p=2', - '3' => '#', - '4' => 'http://localhost/?p=4', - '5' => 'http://localhost/?p=5', - '6' => 'http://localhost/?p=6', - '7' => 'http://localhost/?p=7', - '8' => 'http://localhost/?p=8', - '9' => 'http://localhost/?p=9', - '10' => 'http://localhost/?p=10', - '11' => 'http://localhost/?p=11', - 'next' => 'http://localhost/?p=4'); - $this->assertEqual( $expected, $result ); - $result = $this->PageSelector2->getLinks(14); - $expected = array('previous' => 'http://localhost/?p=13', - '5' => 'http://localhost/?p=5', - '6' => 'http://localhost/?p=6', - '7' => 'http://localhost/?p=7', - '8' => 'http://localhost/?p=8', - '9' => 'http://localhost/?p=9', - '10' => 'http://localhost/?p=10', - '11' => 'http://localhost/?p=11', - '12' => 'http://localhost/?p=12', - '13' => 'http://localhost/?p=13', - '14' => '#', - '15' => 'http://localhost/?p=15', - 'next' => 'http://localhost/?p=15'); - $this->assertEqual( $expected, $result ); - } -} -// Running the test. -$test = &new PageSelectorTest; -$test->run(new HtmlReporter()); diff --git a/test/QueryTest.php b/test/QueryTest.php deleted file mode 100644 index c9533ca..0000000 --- a/test/QueryTest.php +++ /dev/null @@ -1,80 +0,0 @@ -PHPUnit_TestCase($name); - } - - function setUp() - { - require_once '../lib/database.php'; - $this->Query =& new Query(); - $this->DataBase =& new DataBase("sqlite://home/slim/waraq/test/database.db"); - } - - function tearDown() - { - unset($this->Query); - } - - function testdb() - { - $result = $this->Query->db(PARAM); - $expected = EXPECTED_VAL; - $this->assertEquals($expected, $result); - } - - function testinsert() - { - $addItemQuery = new Query; - //$addItemQuery->insert("item")->set("p1='test'")->then("p2='test'"); - - $addItemQuery->string(); - - - - $p1 = $getItemQuery->db(); - $this->assertEquals($expected, $result); - - } - - function testselect() - { - $result = $this->Query->select("p1")->from("item")->where("p2='test'")->string(); - $expected = "select p1 from item where p2='test'"; - $this->assertEquals($expected, $result); - } - - function testfrom() - { - $result = $this->Query->from(PARAM); - $expected = EXPECTED_VAL; - $this->assertEquals($expected, $result); - } - - function testwhere() - { - $result = $this->Query->where(PARAM); - $expected = EXPECTED_VAL; - $this->assertEquals($expected, $result); - } - -} -// Running the test. -$suite = new PHPUnit_TestSuite('QueryTest'); -$result = PHPUnit::run($suite); -echo $result->toString(); -?> -- 2.11.4.GIT