| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Id: admin_gettext_test_base.php 245971 2007-11-10 00:02:50Z quipo $
|
|
|
3 |
|
|
|
4 |
require_once 'admin_db_test_base.php';
|
|
|
5 |
|
|
|
6 |
class TestOfAdminContainerGettextPO extends TestOfAdminContainerDB {
|
|
|
7 |
var $options = array(
|
|
|
8 |
'prefetch' => false,
|
|
|
9 |
'langs_avail_file' => 'gettext_langs.ini',
|
|
|
10 |
'domains_path_file' => 'gettext_domains.ini',
|
|
|
11 |
'default_domain' => 'messages',
|
|
|
12 |
'file_type' => 'po',
|
|
|
13 |
'carriage_return' => "\n",
|
|
|
14 |
);
|
|
|
15 |
var $domains = array(
|
|
|
16 |
'calendar' => 'locale/',
|
|
|
17 |
'alone' => 'locale/',
|
|
|
18 |
'admin' => 'locale/',
|
|
|
19 |
'small page' => 'locale/',
|
|
|
20 |
'messages' => 'locale/',
|
|
|
21 |
'in_page' => 'locale/',
|
|
|
22 |
);
|
|
|
23 |
function TestOfAdminContainerGettextPO($name='Test of Admin Container Gettext PO') {
|
|
|
24 |
$this->UnitTestCase($name);
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
function init() {
|
|
|
28 |
$langs = array(
|
|
|
29 |
'it' => array(
|
|
|
30 |
'name' => 'italiano',
|
|
|
31 |
'meta' => 'charset: iso-8859-1',
|
|
|
32 |
'error_text' => 'non disponibile in Italiano',
|
|
|
33 |
'encoding' => 'iso-8859-1',
|
|
|
34 |
),
|
|
|
35 |
'en' => array(
|
|
|
36 |
'name' => 'english',
|
|
|
37 |
'meta' => 'my meta info',
|
|
|
38 |
'error_text' => 'not available in English',
|
|
|
39 |
'encoding' => 'iso-8859-1',
|
|
|
40 |
),
|
|
|
41 |
'de' => array(
|
|
|
42 |
'name' => 'deutsch',
|
|
|
43 |
'meta' => 'charset: iso-8859-1',
|
|
|
44 |
'error_text' => 'kein Text auf Deutsch verfügbar',
|
|
|
45 |
'encoding' => 'iso-8859-1',
|
|
|
46 |
),
|
|
|
47 |
);
|
|
|
48 |
$this->write_ini_file($langs, $this->options['langs_avail_file'], true);
|
|
|
49 |
$this->write_ini_file($this->domains, $this->options['domains_path_file'], false);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
function setUp() {
|
|
|
53 |
$this->init();
|
|
|
54 |
$driver = 'gettext';
|
|
|
55 |
$this->tr = Translation2_Admin::factory($driver, $this->options);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* This function writes an array to a INI file,
|
|
|
60 |
* pretty much like parse_ini_file(), only in reverse.
|
|
|
61 |
*
|
|
|
62 |
* @param array $array Data to write
|
|
|
63 |
* @param string $filename Destination file name
|
|
|
64 |
* @param boolean $process_sections The source array is bidimensional,
|
|
|
65 |
* and the first keys are the section names
|
|
|
66 |
*/
|
|
|
67 |
function write_ini_file($array, $filename, $process_sections = false)
|
|
|
68 |
{
|
|
|
69 |
if (!is_resource($f = fopen($filename, 'w'))) {
|
|
|
70 |
die('Ops... cannot write "'.$filename.'" file');
|
|
|
71 |
}
|
|
|
72 |
$CRLF = $this->options['carriage_return'];
|
|
|
73 |
|
|
|
74 |
@flock($f, LOCK_EX);
|
|
|
75 |
|
|
|
76 |
if ($process_sections) {
|
|
|
77 |
foreach ($array as $id => $data) {
|
|
|
78 |
fwrite($f, '['. $id .']'. $CRLF);
|
|
|
79 |
foreach ($data as $k => $v) {
|
|
|
80 |
fwrite($f, $k . ' = ' . $v . $CRLF);
|
|
|
81 |
}
|
|
|
82 |
fwrite($f, $CRLF);
|
|
|
83 |
}
|
|
|
84 |
} else {
|
|
|
85 |
foreach ($array as $id => $data) {
|
|
|
86 |
fwrite($f, $id . ' = ' . $data . $CRLF);
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@flock($f, LOCK_UN);
|
|
|
91 |
fclose($f);
|
|
|
92 |
}
|
|
|
93 |
function testAddUpdateRemove() {
|
|
|
94 |
$stringID = 'sample';
|
|
|
95 |
$pageID = 'new page';
|
|
|
96 |
$stringArray = array(
|
|
|
97 |
'en' => 'sample',
|
|
|
98 |
'it' => 'esempio',
|
|
|
99 |
'de' => 'Beispiel',
|
|
|
100 |
);
|
|
|
101 |
//add
|
|
|
102 |
$this->assertTrue($this->tr->add($stringID, $pageID, $stringArray));
|
|
|
103 |
$this->assertEqual($stringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
|
|
|
104 |
$this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
|
|
|
105 |
$this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
|
|
|
106 |
|
|
|
107 |
//update
|
|
|
108 |
$newStringArray = array('en' => 'example');
|
|
|
109 |
$this->assertTrue($this->tr->update($stringID, $pageID, $newStringArray));
|
|
|
110 |
$this->assertEqual($newStringArray['en'], $this->tr->get($stringID, $pageID, 'en'));
|
|
|
111 |
$this->assertEqual($stringArray['it'], $this->tr->get($stringID, $pageID, 'it'));
|
|
|
112 |
$this->assertEqual($stringArray['de'], $this->tr->get($stringID, $pageID, 'de'));
|
|
|
113 |
|
|
|
114 |
//remove
|
|
|
115 |
$this->assertTrue($this->tr->remove($stringID, $pageID));
|
|
|
116 |
//with gettext, empty strings are replaced by the stringID
|
|
|
117 |
$this->assertEqual('sample', $this->tr->get($stringID, $pageID, 'en'));
|
|
|
118 |
}
|
|
|
119 |
function testGetPageNames() {
|
|
|
120 |
$expected = array_keys($this->domains);
|
|
|
121 |
sort($expected);
|
|
|
122 |
$actual = $this->tr->getPageNames();
|
|
|
123 |
sort($actual);
|
|
|
124 |
$this->assertEqual($expected, $actual);
|
|
|
125 |
}
|
|
|
126 |
function testRemovePage() {
|
|
|
127 |
$this->testGetPageNames();
|
|
|
128 |
$stringArray = array(
|
|
|
129 |
'en' => 'sample',
|
|
|
130 |
'it' => 'esempio',
|
|
|
131 |
'de' => 'Beispiel',
|
|
|
132 |
);
|
|
|
133 |
|
|
|
134 |
//add new page
|
|
|
135 |
$newpage = 'new page';
|
|
|
136 |
$this->assertTrue($this->tr->add('sample', $newpage, $stringArray));
|
|
|
137 |
|
|
|
138 |
$actual = $this->tr->getPageNames();
|
|
|
139 |
$this->assertTrue(in_array($newpage, $this->tr->getPageNames()));
|
|
|
140 |
|
|
|
141 |
//check if the page name was written in the .ini file
|
|
|
142 |
$this->assertTrue($this->inifileHasDomain($newpage));
|
|
|
143 |
|
|
|
144 |
//delete the page
|
|
|
145 |
$this->assertTrue($this->tr->removePage($newpage));
|
|
|
146 |
|
|
|
147 |
$this->testGetPageNames();
|
|
|
148 |
|
|
|
149 |
//check if the page name was written in the .ini file
|
|
|
150 |
$this->assertFalse($this->inifileHasDomain($newpage));
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
function inifileHasDomain($domain) {
|
|
|
154 |
$inifile = parse_ini_file($this->options['domains_path_file']);
|
|
|
155 |
return in_array($domain, array_keys($inifile));
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
?>
|