function testIt()
 {
     $tpl = $this->newPHPTAL('input/talesphpwithreplace.01.html');
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/talesphpwithreplace.01.html');
     $this->assertEquals($exp, $res);
 }
示例#2
0
 function testDoesEscapeHTMLContent()
 {
     $tpl = $this->newPHPTAL('input/escape.html');
     $exp = normalize_html_file('output/escape.html');
     $res = normalize_html($tpl->execute());
     $this->assertEquals($exp, $res);
 }
示例#3
0
 public function news($id)
 {
     $this->load->library('curl');
     $this->curl->referer('m.detik.com/kanal/70/');
     $this->curl->userAgent('midp 2.0');
     $id = decode_href($id);
     $html = $this->curl->openGet("http://m.detik.com/read/" . $id);
     $this->load->helper('dom');
     $dom = str_get_html($html);
     $content = $dom->find('div[id=content]', 0);
     if ($title = $content->find('h1', 0)) {
         $title = $title->innertext;
     }
     if ($needle = $content->find('p', 0)) {
         $strong = $needle->find('strong', 0);
         $name = $strong->innertext;
         $strong->outertext = '';
         $img = $needle->find('img', 0);
         $img->outertext = '';
         //echo $needle;
         //die();
         $description = trim($needle->innertext);
         $name = normalize_html($name);
         $description = normalize_html($description);
     }
     $elements = array(array('name' => $name, 'description' => $description));
     $this->load->library('rafa');
     $this->rafa->addHeading('detikbola');
     $this->rafa->addList('news', $elements, $title);
     $this->rafa->endRafa();
 }
示例#4
0
 function testInheritedMacroSlots()
 {
     $tpl = $this->newPHPTAL('input/metal-macro.07.html');
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/metal-macro.07.html');
     $this->assertEquals($exp, $res);
 }
示例#5
0
 function testWithCondition()
 {
     $tpl = $this->newPHPTAL('input/tal-omit-tag.02.html');
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/tal-omit-tag.02.html');
     $this->assertEquals($exp, $res);
 }
示例#6
0
 function testMultilineInTemplate()
 {
     $tpl = $this->newPHPTAL('input/tal-comment.02.html');
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/tal-comment.02.html');
     $this->assertEquals($exp, $res);
 }
示例#7
0
 public function testFlickrStyles()
 {
     Pagination\Pager::style('flickr');
     $actual = Pagination\Pager::links(100);
     $expected = '<style>.flickr_pagination{margin:10px 0;text-align:center;padding:.3em;cursor:default}.flickr_pagination a,.flickr_pagination em,.flickr_pagination span{padding:.2em .5em}.flickr_pagination .disabled{color:#aaa}.flickr_pagination .current{font-style:normal;font-weight:700;color:#ff0084}.flickr_pagination a{border:1px solid #ddd;color:#0063dc;text-decoration:none}.flickr_pagination a:focus,.flickr_pagination a:hover{border-color:#036;background:#0063dc;color:#fff}.flickr_pagination .page_info{color:#aaa;padding-top:.8em}.flickr_pagination .next_page,.flickr_pagination .previous_page{border-width:2px}.flickr_pagination .previous_page{margin-right:1em}.flickr_pagination .next_page{margin-left:1em}.flickr_pagination .page-count{margin-top:10px}.flickr_pagination .page-count,.flickr_pagination .page-display{font-size:11px;text-align:center;color:#bbb}</style><div class="flickr_pagination"><em class="current">1</em><a href="http://mysite.com/index.php?page=something&offset=25" >2</a><a href="http://mysite.com/index.php?page=something&offset=50" >3</a><a href="http://mysite.com/index.php?page=something&offset=25" >Next &raquo;</a><a href="http://mysite.com/index.php?page=something&offset=75" >Last</a><div class="page-count">Page 1 of 4</div><div class="page-display">Displaying records 1 thru 25 of 100</div></div>';
     $this->assertEquals(normalize_html($actual), normalize_html($expected));
 }
示例#8
0
 public function news($id)
 {
     $this->load->library('curl');
     $this->curl->referer('www.goal.com/id-ID/news/');
     $this->curl->userAgent('midp 2.0');
     // Harus terdapat parameter terakhir tetapi terserah
     $id = decode_href($id);
     $url = "http://www.goal.com/id-ID/news/" . $id;
     $html = $this->curl->openGet($url);
     $this->load->helper('dom');
     $dom = str_get_html($html);
     $title = $dom->find('h1', 0)->innertext;
     $name = $dom->find('h4', 0)->innertext;
     if ($needle = $dom->find('span[id=divAdnetKeyword]', 0)) {
         // Hapus text yg tidak penting
         foreach ($needle->children() as $child) {
             $tag = strtolower($child->tag);
             if ($tag != 'br' && $tag != 'em') {
                 $child->outertext = '';
             }
         }
         $description = trim($needle->innertext);
         $description = normalize_html($description);
     }
     $elements = array(array('name' => $name, 'description' => $description));
     $this->load->library('rafa');
     $this->rafa->addHeading('goal');
     $this->rafa->addList('news', $elements, $title);
     $this->rafa->endRafa();
 }
示例#9
0
 function test()
 {
     $tpl = $this->newPHPTAL('input/overloading-01.html');
     $tpl->object = new OverloadTestClass();
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/overloading-01.html');
     $this->assertEquals($exp, $res);
 }
示例#10
0
 /**
  * this is pretty crazy case of PHPTAL being reused while template is still being executed
  */
 function testClearedOnNestedReexecution()
 {
     $tpl = $this->newPHPTAL();
     $tpl->tpl = $tpl;
     $tpl->setSource('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <hack tal:define="hack php:tpl.setSource(&quot;&lt;hacked/&gt;&quot;)" tal:content="structure hack/execute"/>');
     $this->assertEquals(normalize_html('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hack><hacked></hacked></hack>'), normalize_html($tpl->execute()));
 }
示例#11
0
 function testTrue()
 {
     $tpl = $this->newPHPTAL('input/tales-true.html');
     $tpl->isNotTrue = false;
     $tpl->isTrue = true;
     $res = $tpl->execute();
     $this->assertEquals(normalize_html_file('output/tales-true.html'), normalize_html($res));
 }
示例#12
0
 function testInContent()
 {
     $tpl = $this->newPHPTAL('input/php-mode.02.xml');
     $res = $tpl->execute();
     $exp = normalize_html_file('output/php-mode.02.xml');
     $res = normalize_html($res);
     $this->assertEquals($exp, $res);
 }
 function testSimple()
 {
     $tpl = $this->newPHPTAL('input/content-encoding.xml');
     $res = $tpl->execute();
     $exp = normalize_html_file('output/content-encoding.xml');
     $res = normalize_html($res);
     $this->assertEquals($exp, $res);
 }
示例#14
0
 function testNamespaceAware()
 {
     $t = $this->newPHPTAL();
     $t->addPreFilter(new PHPTAL_PreFilter_StripComments());
     $t->setSource('<script xmlns="http://example.com/foo">//<!--
     alert("1990s called"); /* && */
     //--></script>');
     $this->assertEquals(normalize_html('<script xmlns="http://example.com/foo">//</script>'), normalize_html($t->execute()));
 }
示例#15
0
 function testRedefineBuiltinNamespace()
 {
     $tpl = $this->newPHPTAL();
     $tpl->setSource('<metal:block xmlns:metal="non-zope">
                        <foo:block xmlns="x" xmlns:foo="http://xml.zope.org/namespaces/tal" content="string:works" />
                        <metal:block xmlns="http://xml.zope.org/namespaces/i18n" xmlns:metal="http://xml.zope.org/namespaces/tal" metal:content="string:properly" />
                      </metal:block>');
     $this->assertEquals(normalize_html('<metal:block xmlns:metal="non-zope"> works properly </metal:block>'), normalize_html($tpl->execute()));
 }
示例#16
0
 function testMix()
 {
     $tpl = $this->newPHPTAL('input/php.html');
     $tpl->real = 'real value';
     $tpl->foo = 'real';
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/php.html');
     $this->assertEquals($exp, $res);
 }
示例#17
0
 function testCache2()
 {
     $tpl = $this->newPHPTAL('input/prefilter.03.html');
     $tpl->execute();
     // prepare version without prefilter
     $tpl->setPreFilter(new OldMyPreFilter2());
     $res = normalize_html($tpl->execute());
     $exp = normalize_html('<root>filtered</root>');
     $this->assertEquals($exp, $res);
 }
示例#18
0
 function testZeroValues()
 {
     $tpl = $this->newPHPTAL('input/tal-attributes.07.html');
     $tpl->href1 = 0;
     $tpl->href2 = 0;
     $tpl->href3 = 0;
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/tal-attributes.07.html');
     $this->assertEquals($exp, $res);
 }
示例#19
0
 public function testAllowGtAndLtInTextNodes()
 {
     $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8');
     $parser->parseFile($builder = new MyDocumentBuilder(), 'input/xml.03.xml')->getResult();
     $this->assertEquals(normalize_html_file('output/xml.03.xml'), normalize_html($builder->result));
     $this->assertEquals(3, $builder->elementStarts);
     $this->assertEquals(3, $builder->elementCloses);
     // a '<' character withing some text data make the parser call 2 times
     // the onElementData() method
     $this->assertEquals(7, $builder->datas);
 }
示例#20
0
 function testMacro()
 {
     $tpl = $this->newPHPTAL();
     $tpl->setPostFilter(new MyPostFilter2());
     $tpl->setSource('<x><y metal:define-macro="macro">test2</y>
     test1
     <z metal:use-macro="macro" />
     </x>
     ');
     $this->assertEquals(normalize_html('<x>test-filtered1<y>test-filtered2</y></x>'), normalize_html($tpl->execute()));
 }
示例#21
0
 function testStructure()
 {
     $tpl = $this->newPHPTAL();
     $tpl->setSource('<p>
         ${string:&lt;foo/&gt;}
         ${structure string:&lt;foo/&gt;}
         <x y="${string:&lt;foo/&gt;}" tal:content="string:&lt;foo/&gt;" />
         <x y="${structure string:&lt;foo/&gt;}" tal:content="structure string:&lt;foo/&gt;" />
     </p>');
     $this->assertEquals(normalize_html('<p>&lt;foo/&gt;<foo/><x y="&lt;foo/&gt;">&lt;foo/&gt;</x><x y="<foo/>"><foo/></x></p>'), normalize_html($tpl->execute()));
 }
示例#22
0
 function testNamespace()
 {
     $tpl = $this->newPHPTAL('input/i18n-name-06.html');
     $tpl->username = '******';
     $tpl->mails = 100;
     $tpl->setTranslator(new DummyTranslator());
     $res = $tpl->execute();
     $res = normalize_html($res);
     $exp = normalize_html_file('output/i18n-name-06.html');
     $this->assertEquals($exp, $res);
 }
示例#23
0
 function testLevel2()
 {
     $o = new stdClass();
     $o->foo = 1;
     $tpl = $this->newPHPTAL('input/tales-exist-02.html');
     $tpl->o = $o;
     $res = $tpl->execute();
     $res = normalize_html($res);
     $exp = normalize_html_file('output/tales-exist-02.html');
     $this->assertEquals($exp, $res);
 }
示例#24
0
 function testReplaceStructure()
 {
     $tpl = $this->newPHPTAL('input/tal-on-error.03.html');
     $tpl->dummy = new OnErrorDummyObject();
     $res = normalize_html($tpl->execute());
     $exp = normalize_html_file('output/tal-on-error.03.html');
     $errors = $tpl->getErrors();
     $this->assertEquals(1, count($errors));
     $this->assertEquals('error thrown', $errors[0]->getMessage());
     $this->assertEquals($exp, $res);
 }
示例#25
0
 function testEchoExecuteDeclsMacro()
 {
     try {
         $tpl = $this->newPHPTAL();
         $tpl->setSource('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello><m metal:define-macro="test">test</m><x metal:use-macro="test"/></hello>');
         $this->assertEquals(normalize_html('<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><hello><m>test</m></hello>'), $this->echoExecute($tpl));
     } catch (PHPTAL_ConfigurationException $e) {
         // this is fine. Combination of macros and echoExecute is not supported yet (if it were, the test above is valid)
         $this->assertContains("echoExecute", $e->getMessage());
     }
 }
示例#26
0
 function testIt()
 {
     $arr = new MyArray();
     for ($i = 0; $i < 20; $i++) {
         $val = new stdClass();
         $val->foo = "foo value {$i}";
         $arr->push($val);
     }
     $tpl = $this->newPHPTAL('input/array-overload.01.html');
     $tpl->myobject = $arr;
     $res = $tpl->execute();
     $exp = normalize_html_file('output/array-overload.01.html');
     $res = normalize_html($res);
     $this->assertEquals($exp, $res);
 }
示例#27
0
 function test01()
 {
     $trigger = new MyTrigger();
     $exp = normalize_html_file('output/phptal.id.01.html');
     $tpl = $this->newPHPTAL('input/phptal.id.01.html');
     $tpl->addTrigger('myTable', $trigger);
     $tpl->result = range(0, 3);
     $res = $tpl->execute();
     $res = normalize_html($res);
     $this->assertEquals($exp, $res);
     $this->assertEquals(false, $trigger->useCache);
     $res = $tpl->execute();
     $res = normalize_html($res);
     $this->assertEquals($exp, $res);
     $this->assertEquals(true, $trigger->useCache);
 }
示例#28
0
 public function news($id)
 {
     $url = 'http://sekar.or.id/xampp/index.php?option=com_content&task=view&id=' . $id . '&Itemid=53';
     $this->load->library('curl');
     $html = $this->curl->openGet($url);
     $this->load->helper('dom');
     $dom = str_get_html($html);
     $title = $dom->find('td[class=contentheading]', 0)->innertext;
     $title = trim($title);
     $table = $dom->find('table[class=contentpaneopen]', 2);
     $desc = '';
     $arr_p = $table->find('p');
     for ($i = 3; $i < count($arr_p) - 4; $i++) {
         $token = $arr_p[$i]->plaintext;
         $token = trim($token);
         $desc .= $token;
     }
     $desc = normalize_html($desc);
     $this->load->library('rafa');
     $this->rafa->addHeading('sekar');
     $elements = array(array('name' => $title, 'description' => $desc));
     $this->rafa->addList('news', $elements);
     $this->rafa->endRafa();
 }
示例#29
0
 /**
  * @param string $str
  */
 private function decodeNumericEntities($str)
 {
     return normalize_html(preg_replace_callback('/&#x?[a-f0-9]+;/i', function (array $entities) {
         return htmlspecialchars(html_entity_decode($entities[0]));
     }, $str));
 }
示例#30
-1
 public function news($id)
 {
     $this->load->library('curl');
     $this->curl->referer('m.vivanews.com');
     $this->curl->userAgent('midp 2.0');
     $html = $this->curl->openGet("http://m.vivanews.com/news/read/" . $id);
     // normalize web information
     $html = str_replace('&quot;', '"', $html);
     $html = str_replace('&nbsp;', ' ', $html);
     $this->load->helper('dom');
     $dom = str_get_html($html);
     $content = $dom->find('div[class=content]', 0);
     $title = $content->find('span[class=judul]', 0)->innertext;
     $title = trim($title);
     $i = 1;
     $description = '';
     foreach ($content->find('p') as $p) {
         if ($i == 2) {
             $strong = $p->find('strong', 0);
             $name = trim($strong->innertext);
             $strong->outertext = '';
             $description .= trim($p->innertext);
         } else {
             if ($i > 2) {
                 $description .= trim($p->plaintext);
             }
         }
         $i++;
     }
     $elements = array(array('name' => normalize_html($name), 'description' => normalize_html($description)));
     $this->load->library('rafa');
     $this->rafa->addHeading('vivanews');
     $this->rafa->addList('news', $elements, $title);
     $this->rafa->endRafa();
 }