Changeset 511
- Timestamp:
- 08/18/2010 03:38:16 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/test/core/parserTest.php
r381 r511 1 1 <?php 2 2 3 require_once 'PHPUnit/Framework.php'; 3 4 4 require_once dirname(__FILE__) .'/../../core/parser.php';5 require_once dirname(__FILE__) . '/../../core/parser.php'; 5 6 6 7 /** … … 9 10 */ 10 11 class parserTest extends PHPUnit_Framework_TestCase { 12 11 13 /** 12 14 * @var parser … … 37 39 */ 38 40 protected function tearDown() { 41 39 42 } 40 43 … … 159 162 } 160 163 164 function fetch_translation($original_text, $lang) { 165 echo "fetch for: <b>$original_text</b><br/>"; 166 logger('hoo'); 167 return array("z-$original_text-z", 0); 168 } 169 170 function rewrite($original_text) { 171 echo "rewrite for: <b>$original_text</b><br/>"; 172 return $original_text; 173 } 174 161 175 /** 162 176 * @todo Implement testFix_html(). … … 164 178 public function testFix_html() { 165 179 // Remove the following lines when you implement this test. 166 $this->markTestIncomplete( 167 'This test has not been implemented yet.' 168 ); 180 $parse = $this->object; 181 $parse->fetch_translate_func = array(&$this, 'fetch_translation'); 182 //$parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations'); 183 $parse->url_rewrite_func = array(&$this, 'rewrite'); 184 $parse->dir_rtl = true; 185 $parse->lang = 'he'; 186 $parse->default_lang = false; 187 $parse->is_edit_mode = false; 188 $parse->is_auto_translate = true; 189 $parse->allow_ad = false; 190 $this->assertEquals('<html dir="rtl" lang="he"></html>', $parse->fix_html('<html></html>')); 191 $this->assertEquals('<html dir="rtl" lang="he"></html>', $parse->fix_html('<html dir="rtl" lang="he"></html>')); 192 //$this->assertEquals('<html dir="rtl" lang="he"><body>z-hello-z, z-world-z</body></html>', $parse->fix_html('<html><body>hello, world</body></html>')); 193 $this->assertEquals('<html dir="rtl" lang="he"><body>z-hello-z, z-world-z, z-hello world-z</body></html>', $parse->fix_html('<html><body>hello, world, hello world</body></html>')); 194 $this->assertEquals('<html dir="rtl" lang="he"><body><a title="z-hello-z, z-world-z, z-hello world-z">z-hi-z</a></body></html>', $parse->fix_html('<html><body><a title="hello, world, hello world">hi</a></body></html>')); 195 196 $this->assertEquals('<html dir="rtl" lang="he"><body>z-hello, world-z</body></html>', $parse->fix_html('<html><body>&transposh;hello, world&transposh;</body></html>')); 197 198 199 $parse->is_edit_mode = true; 200 $this->assertEquals('<html dir="rtl" lang="he"><body><span class ="tr_" id="tr_0" data-token="aGVsbG8," data-source="0" data-orig="hello">z-hello-z</span>, <span class ="tr_" id="tr_1" data-token="d29ybGQ," data-source="0" data-orig="world">z-world-z</span>, <span class ="tr_" id="tr_2" data-token="aGVsbG8gd29ybGQ," data-source="0" data-orig="hello world">z-hello world-z</span></body></html>', $parse->fix_html('<html><body>hello, world, hello world</body></html>')); 201 //$this->assertEquals('<html dir="rtl" lang="he"><body><span class ="tr_" id="tr_2" data-token="aGVsbG8," data-source="0" data-orig="hello">z-hello-z</span>, <span class ="tr_" id="tr_1" data-token="d29ybGQ," data-source="0" data-orig="world">z-world-z</span>, <span class ="tr_" id="tr_0" data-token="aGVsbG8gd29ybGQ," data-source="0" data-orig="hello world">z-hello world-z</span></body></html>', $parse->fix_html('<html><body>hello, world, hello world</body></html>')); 202 $this->assertEquals('<html dir="rtl" lang="he"><body><span class ="tr_" id="tr_3" data-token="aGVsbG8," data-source="0" data-orig="hello">z-hello-z</span>, <span class ="tr_" id="tr_4" data-token="d29ybGQ," data-source="0" data-orig="world">z-world-z</span>,<a title="z-hi-z" href="b"><span class ="tr_" id="tr_5" data-token="aG8," data-source="0" data-orig="ho">z-ho-z</span></a><span class ="tr_" id="tr_7" data-token="aGk," data-source="0" data-orig="hi" data-hidden="y" data-trans="z-hi-z"></span> <span class ="tr_" id="tr_6" data-token="aGVsbG8gd29ybGQ," data-source="0" data-orig="hello world">z-hello world-z</span></body></html>', $parse->fix_html('<html><body>hello, world,<a title="hi" href="b">ho</a> hello world</body></html>')); 203 //$this->assertEquals('<html dir="rtl" lang="he"><body><span class ="tr_" id="tr_4" data-token="aGVsbG8," data-source="0" data-orig="hello">z-hello-z</span>, <span class ="tr_" id="tr_3" data-token="d29ybGQ," data-source="0" data-orig="world">z-world-z</span>,<a title="z-hi-z" href="b"><span class ="tr_" id="tr_5" data-token="aG8," data-source="0" data-orig="ho">z-ho-z</span></a><span class ="tr_" id="tr_7" data-token="aGk," data-source="0" data-orig="hi" data-hidden="y" data-trans="z-hi-z"></span> <span class ="tr_" id="tr_6" data-token="aGVsbG8gd29ybGQ," data-source="0" data-orig="hello world">z-hello world-z</span></body></html>', $parse->fix_html('<html><body>hello, world,<a title="hi" href="b">ho</a> hello world</body></html>')); 169 204 } 170 205 … … 180 215 181 216 private function anonArraytoKnown($array) { 182 foreach ($array as $key =>$value) {217 foreach ($array as $key => $value) { 183 218 $return[$value] = $value; 184 219 } … … 187 222 188 223 private function runtestCut($string, $array) { 189 $this->assertEquals($this->anonArraytoKnown($array),$this->object->get_phrases_list($string)); 190 } 224 $this->assertEquals($this->anonArraytoKnown($array), $this->object->get_phrases_list($string)); 225 } 226 191 227 /** 192 228 * @todo Implement testGet_phrases_list(). 193 229 */ 194 230 public function testParsing() { 195 $this->runtestCut("a, b", array('a' ,'b'));196 $this->runtestCut("hello , world", array('hello' ,'world'));197 $this->runtestCut("42nd, street", array('42nd' ,'street'));231 $this->runtestCut("a, b", array('a', 'b')); 232 $this->runtestCut("hello , world", array('hello', 'world')); 233 $this->runtestCut("42nd, street", array('42nd', 'street')); 198 234 $this->runtestCut("2b or not 2b", array('2b or not 2b')); 199 $this->runtestCut("again, again, and again", array('again', 'and again'));200 // $this->testCut("again, again again, again again, and again", array('again','again again','and again'));201 $this->runtestCut("there are 100 bottles of bear on the wall", array('there are', 'bottles of bear on the wall'));202 $this->runtestCut("there are 100.5 bottles of bear on the wall", array('there are', 'bottles of bear on the wall'));235 $this->runtestCut("again, again, and again", array('again', 'and again')); 236 // $this->testCut("again, again again, again again, and again", array('again','again again','and again')); 237 $this->runtestCut("there are 100 bottles of bear on the wall", array('there are', 'bottles of bear on the wall')); 238 $this->runtestCut("there are 100.5 bottles of bear on the wall", array('there are', 'bottles of bear on the wall')); 203 239 $this->runtestCut("1) do this", array('do this')); 204 240 $this->runtestCut("a $100", array('a')); … … 208 244 $this->runtestCut("a 1", array('a')); 209 245 $this->runtestCut("a (1920-30)", array('a')); 210 $this->runtestCut("some <b>html</b>is here,", array('some','html','is here')); 211 } 212 213 246 $this->runtestCut("some <b>html</b>is here,", array('some', 'html', 'is here')); 247 } 214 248 215 249 }
Note: See TracChangeset
for help on using the changeset viewer.
