Changeset 511


Ignore:
Timestamp:
08/18/2010 03:38:16 AM (18 months ago)
Author:
ofer
Message:

Many fix_html tests for parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/test/core/parserTest.php

    r381 r511  
    11<?php 
     2 
    23require_once 'PHPUnit/Framework.php'; 
    34 
    4 require_once dirname(__FILE__).'/../../core/parser.php'; 
     5require_once dirname(__FILE__) . '/../../core/parser.php'; 
    56 
    67/** 
     
    910 */ 
    1011class parserTest extends PHPUnit_Framework_TestCase { 
     12 
    1113    /** 
    1214     * @var    parser 
     
    3739     */ 
    3840    protected function tearDown() { 
     41 
    3942    } 
    4043 
     
    159162    } 
    160163 
     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 
    161175    /** 
    162176     * @todo Implement testFix_html(). 
     
    164178    public function testFix_html() { 
    165179        // 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>')); 
    169204    } 
    170205 
     
    180215 
    181216    private function anonArraytoKnown($array) { 
    182         foreach ($array as $key=>$value) { 
     217        foreach ($array as $key => $value) { 
    183218            $return[$value] = $value; 
    184219        } 
     
    187222 
    188223    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 
    191227    /** 
    192228     * @todo Implement testGet_phrases_list(). 
    193229     */ 
    194230    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')); 
    198234        $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')); 
    203239        $this->runtestCut("1) do this", array('do this')); 
    204240        $this->runtestCut("a $100", array('a')); 
     
    208244        $this->runtestCut("a 1", array('a')); 
    209245        $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    } 
    214248 
    215249} 
Note: See TracChangeset for help on using the changeset viewer.