From 1865a45b66775dd873b84457baa1d98df555d847 Mon Sep 17 00:00:00 2001 From: Slim Amamou Date: Tue, 5 Feb 2008 12:48:56 +0100 Subject: [PATCH] j'ai enleve les fichiers inutiles --- lib/mark.php | 213 ---------------------------------------------- lib/pagecopy.php | 80 ----------------- lib/pageselector.php | 45 ---------- lib/user.php | 28 ------ test/MarkTest.php | 160 ---------------------------------- test/PageCopyTest.php | 90 -------------------- test/PageSelectorTest.php | 72 ---------------- test/QueryTest.php | 80 ----------------- 8 files changed, 768 deletions(-) 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 test/MarkTest.php delete mode 100644 test/PageCopyTest.php delete mode 100644 test/PageSelectorTest.php delete mode 100644 test/QueryTest.php 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/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