| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Id: admin_db_test_base.php 245971 2007-11-10 00:02:50Z quipo $
|
|
|
3 |
|
|
|
4 |
require_once 'simple_include.php';
|
|
|
5 |
require_once 'translation2_admin_include.php';
|
|
|
6 |
require_once 'dbms.php';
|
|
|
7 |
|
|
|
8 |
class TestOfAdminContainerDB extends UnitTestCase {
|
|
|
9 |
var $tr;
|
|
|
10 |
function TestOfAdminContainerDB($name='Test of Admin Container DB') {
|
|
|
11 |
$this->UnitTestCase($name);
|
|
|
12 |
}
|
|
|
13 |
function setUp() {
|
|
|
14 |
$driver = 'DB';
|
|
|
15 |
$this->tr = Translation2_Admin::factory($driver, dbms::getDbInfo(), dbms::getParams());
|
|
|
16 |
}
|
|
|
17 |
function tearDown() {
|
|
|
18 |
unset($this->tr);
|
|
|
19 |
}
|
|
|
20 |
function testFactory() {
|
|
|
21 |
if (PEAR::isError($this->tr)) {
|
|
|
22 |
var_dump($this->tr->getUserInfo());
|
|
|
23 |
var_dump($this->tr->getMessage());
|
|
|
24 |
//var_dump(debug_backtrace());
|
|
|
25 |
exit;
|
|
|
26 |
}
|
|
|
27 |
$this->assertTrue(!PEAR::isError($this->tr));
|
|
|
28 |
}
|
|
|
29 |
function testAddLang() {
|
|
|
30 |
$langData = array(
|
|
|
31 |
'lang_id' => 'fr',
|
|
|
32 |
'table_name' => 'i18n',
|
|
|
33 |
'name' => 'français',
|
|
|
34 |
'meta' => '123 abc',
|
|
|
35 |
'error_text' => 'non disponible',
|
|
|
36 |
'encoding' => 'iso-8859-1',
|
|
|
37 |
);
|
|
|
38 |
$pre = $this->tr->getLangs('array');
|
|
|
39 |
// create a new language
|
|
|
40 |
$this->tr->addLang($langData);
|
|
|
41 |
$post = $this->tr->getLangs('array');
|
|
|
42 |
$expected = array(
|
|
|
43 |
'id' => 'fr',
|
|
|
44 |
'lang_id' => 'fr',
|
|
|
45 |
'name' => 'français',
|
|
|
46 |
'meta' => '123 abc',
|
|
|
47 |
'error_text' => 'non disponible',
|
|
|
48 |
'encoding' => 'iso-8859-1',
|
|
|
49 |
);
|
|
|
50 |
$this->assertEqual($expected, array_pop(array_diff_assoc($post, $pre)));
|
|
|
51 |
// remove the new language
|
|
|
52 |
$this->assertTrue($this->tr->removeLang('fr'));
|
|
|
53 |
$this->assertEqual($pre, $this->tr->getLangs('array'));
|
|
|
54 |
}
|
|
|
55 |
function testUpdateLang() {
|
|
|
56 |
$original = array(
|
|
|
57 |
'id' => 'en',
|
|
|
58 |
'lang_id' => 'en',
|
|
|
59 |
'name' => 'english',
|
|
|
60 |
'meta' => 'my meta info',
|
|
|
61 |
'error_text' => 'not available in English',
|
|
|
62 |
'encoding' => 'iso-8859-1',
|
|
|
63 |
);
|
|
|
64 |
$restore = array(
|
|
|
65 |
'lang_id' => 'en',
|
|
|
66 |
'name' => 'english',
|
|
|
67 |
'meta' => 'my meta info',
|
|
|
68 |
'error_text' => 'not available in English',
|
|
|
69 |
'encoding' => 'iso-8859-1',
|
|
|
70 |
);
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
$newLangData = array(
|
|
|
74 |
'lang_id' => 'en',
|
|
|
75 |
'name' => 'english2',
|
|
|
76 |
'meta' => 'my other meta info',
|
|
|
77 |
'error_text' => 'not available in English2',
|
|
|
78 |
'encoding' => 'iso-8859-15',
|
|
|
79 |
);
|
|
|
80 |
$expected = array(
|
|
|
81 |
'id' => 'en',
|
|
|
82 |
'lang_id' => 'en',
|
|
|
83 |
'name' => 'english2',
|
|
|
84 |
'meta' => 'my other meta info',
|
|
|
85 |
'error_text' => 'not available in English2',
|
|
|
86 |
'encoding' => 'iso-8859-15',
|
|
|
87 |
);
|
|
|
88 |
|
|
|
89 |
$this->assertTrue($this->tr->updateLang($newLangData));
|
|
|
90 |
$this->tr->setLang('en');
|
|
|
91 |
$this->assertEqual($expected, $this->tr->getLang('en', 'array'));
|
|
|
92 |
|
|
|
93 |
$this->assertTrue($this->tr->updateLang($restore));
|
|
|
94 |
$this->assertEqual($original, $this->tr->getLang('en', 'array'));
|
|
|
95 |
}
|
|
|
96 |
function testAddUpdateRemove() {
|
|
|
97 |
$stringID = 'sample';
|
|
|
98 |
$pageID = 'new page';
|
|
|
99 |
$stringArray = array(
|
|
|
100 |
'en' => 'sample',
|
|
|
101 |
'it' => 'esempio',
|
|
|
102 |
'de' => 'Beispiel',
|
|
|
103 |
);
|
|
|
104 |
//add
|
|
|
105 |
$this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
|
|
|
106 |
$this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
|
|
|
107 |
$this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
|
|
|
108 |
$this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
|
|
|
109 |
|
|
|
110 |
//update
|
|
|
111 |
$newStringArray = array('en' => 'example');
|
|
|
112 |
$this->assertTrue($this->tr->update($stringID, $pageID, $newStringArray));
|
|
|
113 |
$this->assertEqual($newStringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
|
|
|
114 |
$this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
|
|
|
115 |
$this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
|
|
|
116 |
|
|
|
117 |
//remove
|
|
|
118 |
$this->assertTrue($this->tr->remove($stringID, $pageID));
|
|
|
119 |
$this->assertEqual('', $this->tr->get($stringID, $pageID, 'en'));
|
|
|
120 |
}
|
|
|
121 |
function testGetPageNames() {
|
|
|
122 |
$expected = array(
|
|
|
123 |
null,
|
|
|
124 |
'',
|
|
|
125 |
'alone',
|
|
|
126 |
'bbcode',
|
|
|
127 |
'calendar',
|
|
|
128 |
'de',
|
|
|
129 |
'in_page',
|
|
|
130 |
'samplePage',
|
|
|
131 |
'small page',
|
|
|
132 |
);
|
|
|
133 |
sort($expected);
|
|
|
134 |
$actual = $this->tr->getPageNames();
|
|
|
135 |
sort($actual);
|
|
|
136 |
$this->assertEqual($expected, $actual);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
function testRemovePage() {
|
|
|
140 |
$stringID = 'sample';
|
|
|
141 |
$pageID = 'new page';
|
|
|
142 |
|
|
|
143 |
$this->assertFalse(in_array($pageID, $this->tr->getPageNames()));
|
|
|
144 |
|
|
|
145 |
$stringArray = array(
|
|
|
146 |
'en' => 'sample',
|
|
|
147 |
'it' => 'esempio',
|
|
|
148 |
'de' => 'Beispiel',
|
|
|
149 |
);
|
|
|
150 |
//add new page
|
|
|
151 |
$this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
|
|
|
152 |
|
|
|
153 |
$this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
|
|
|
154 |
$this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
|
|
|
155 |
$this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
|
|
|
156 |
|
|
|
157 |
$actual = $this->tr->getPageNames();
|
|
|
158 |
$this->assertTrue(in_array($pageID, $this->tr->getPageNames()));
|
|
|
159 |
|
|
|
160 |
//delete the page
|
|
|
161 |
$this->assertTrue($this->tr->removePage($pageID));
|
|
|
162 |
|
|
|
163 |
$this->assertEqual('', $this->tr->get($stringID, $pageID, 'en'));
|
|
|
164 |
|
|
|
165 |
$this->assertFalse(in_array($pageID, $this->tr->getPageNames()));
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
?>
|