j'ai corrigé un bug qui empechait le schema browser de fonctionner avec les noms...
[bazdig.git] / test / MarkTest.php
blob89c107bade13c06449305d73b673063764c8d70b
1 <?php
3 require_once('simpletest/unit_tester.php');
4 require_once('simpletest/reporter.php');
6 class MarkTest extends UnitTestCase {
8 var $WaraqService;
10 function setUp()
12 global $waraq;
14 define('WARAQ_ROOT', '..');
15 require_once WARAQ_ROOT .'/ini.php';
16 require_once '../lib/mark.php';
17 $this->Mark =& new Mark("testid");
18 $this->Mark2 =& new Mark("testid2");
19 $this->Mark2->pageUrl = "http://localhost/test2";
20 $this->Mark2->text = "test text2";
21 $this->Mark3 =& new Mark("testid3");
22 $this->Mark4 =& new Mark("testid4");
23 $this->Mark4->pageUrl = "http://localhost/test?s=55555";
24 $this->db =& new PDO("sqlite2:markkit-test.db");
27 function tearDown()
29 unset($this->Mark);
30 $tableName = Mark::get_table_name();
31 $this->db->query("delete from $tableName where id='testid2'");
34 function testtoSQLinsert()
36 $result = $this->Mark->toSQLinsert();
37 $expected = "/insert/i";
38 $this->assertWantedPattern($expected, $result);
39 $expected = "/'testid'/";
40 $this->assertWantedPattern($expected, $result);
41 $result = $this->Mark2->toSQLinsert();
42 $expected = "/insert/i";
43 $this->assertWantedPattern($expected, $result);
44 $expected = "/'testid2'/";
45 $this->assertWantedPattern($expected, $result);
46 $expected = "/'http:\/\/localhost\/test2'/";
47 $this->assertWantedPattern($expected, $result);
50 function testtoSQLselect()
52 $result = $this->Mark->toSQLselect();
53 $expected = "/select/i";
54 $this->assertWantedPattern($expected, $result);
55 $expected = "/id='testid'/";
56 $this->assertWantedPattern($expected, $result);
59 function testsql_select()
61 $options = array('owner' => "testuser", 'pageUrl' => "http://localhost/dokuwiki/");
62 $result = Mark::sql_select($options);
63 $expected = "/owner='testuser'/i";
64 $this->assertWantedPattern($expected, $result);
65 $expected = "/pageUrl LIKE 'http:\/\/localhost\/dokuwiki\/%'/i";
66 $this->assertWantedPattern($expected, $result);
69 function testselect()
71 $this->Mark->creationDate = "1189807200";
72 $this->Mark->pageUrl = "http://localhost/dokuwiki/";
73 $this->Mark->text = "test text";
74 $this->Mark->owner = "testuser";
75 $this->Mark->startNodePath = array(1,2,3);
76 $this->Mark->startOffset = '0';
77 $this->Mark->endNodePath = array(4,5,6);
78 $this->Mark->endOffset = '0';
79 $this->Mark3->creationDate = "1189807200";
80 $this->Mark3->pageUrl = "http://localhost/dokuwiki/x";
81 $this->Mark3->text = "test text";
82 $this->Mark3->owner = "testuser";
83 $this->Mark3->startNodePath = array(1,2,3);
84 $this->Mark3->startOffset = '0';
85 $this->Mark3->endNodePath = array(4,5,6);
86 $this->Mark3->endOffset = '0';
87 $options = array('id' => 'testid');
88 $result = Mark::select($options, $this->db);
89 $expected = array($this->Mark);
90 $this->assertEqual($expected, $result);
91 Mark::set_db($this->db);
92 $result = Mark::select($options);
93 $this->assertEqual($expected, $result);
94 Mark::set_db("sqlite2:markkit-test.db");
95 $result = Mark::select($options);
96 $this->assertEqual($expected, $result);
97 $options = array('pageUrl' => "http://localhost/dokuwiki/");
98 $result = Mark::select($options);
99 $expected = array($this->Mark, $this->Mark3);
100 $this->assertEqual($expected, $result);
103 function testcount()
105 $result = $this->Mark->count();
106 $expected = 3;
107 $this->assertEqual($expected, $result);
110 function testsave()
112 $this->Mark2->save($this->db);
113 $result = $this->db->query("select * from marks where id='testid2'");
114 $expected = '00000';
115 $this->assertEqual($expected, $result->errorCode());
116 $result = $result->fetch();
117 $expected = 'http://localhost/test2';
118 $this->assertEqual($expected, $result['pageUrl']);
119 $expected = 'test text2';
120 $this->assertEqual($expected, $result['text']);
123 function testload()
125 $result = $this->Mark->load($this->db);
126 $expected = "testuser";
127 $this->assertEqual($expected, $result->owner);
130 function testset_db()
132 global $waraq;
134 $result = Mark::set_db("mysql:host=localhost;dbname=markkit", "root", "");
135 $expected = "mysql";
136 $this->assertEqual($expected, $result->getAttribute(PDO::ATTR_DRIVER_NAME));
137 $result = Mark::set_db("sqlite2:markkit-test.db");
138 $expected = "sqlite2";
139 $this->assertEqual($expected, $result->getAttribute(PDO::ATTR_DRIVER_NAME));
142 function test_toHTMLanchor()
144 $result = $this->Mark2->toHTMLanchor();
145 $expected = "<a href='http://localhost/test2' >test text2</a>";
146 $this->assertEqual($expected, $result);
149 function test_strip_http_get_params()
151 $result = strip_http_get_params("http://localhost/test?s=55555");
152 $expected = "http://localhost/test";
153 $this->assertEqual($expected, $result);
157 // Running the test.
158 $test =& new MarkTest;
159 $test->run(new HtmlReporter());