コード例 #1
0
    public function testOverrideBefore()
    {
        $xml = '<div>
			<span>Test</span>
		</div>';
        $includeFile = __DIR__ . DIRECTORY_SEPARATOR . 'include.xml';
        $tss = "div:before {content: 'foo' }\n\t\tdiv:before {content: 'bar';}\n\t\t";
        $template = new \Transphporm\Builder($xml, $tss);
        $this->assertEquals('<div>bar<span>Test</span></div>', $this->stripTabs($template->output()->body));
    }
コード例 #2
0
ファイル: CacheTest.php プロジェクト: level-2/transphporm
 private function buildTemplate($frequency, $cache, $time = null)
 {
     list($xml, $css) = $this->createFiles($frequency);
     $template = new Builder($xml, $css);
     if ($time) {
         $template->setTime($time);
     }
     $template->setCache($cache);
     return $template;
 }
コード例 #3
0
    public function testContentSimple()
    {
        $template = '
				<ul><li>TEST1</li></ul>
		';
        $css = 'ul li {content: data(user);}';
        $data = new \stdclass();
        $data->user = '******';
        $template = new Builder($template, $css);
        $this->assertEquals('<ul><li>tom</li></ul>', $template->output($data)->body);
    }
コード例 #4
0
    public function testIterationKey()
    {
        $xml = '<ul>
			<li>
				<span>key</span>
				<p>value</p>
			</li>
		</ul>';
        $data = ['One' => '1', 'Two' => '2', 'Three' => '3'];
        $tss = 'li {repeat: data(); }
		li span {content: key();}
		li p {content: iteration();}
		';
        $template = new \Transphporm\Builder($xml, $tss);
        $output = $template->output($data)->body;
        $this->assertEquals($this->stripTabs($output), $this->stripTabs('<ul>
			<li>
				<span>One</span>
				<p>1</p>
			</li>
			<li>
				<span>Two</span>
				<p>2</p>
			</li>
			<li>
				<span>Three</span>
				<p>3</p>
			</li>
		</ul>'));
    }
コード例 #5
0
 public function testNl2brBasicFromData()
 {
     $xml = "\n        <div></div>\n        ";
     $tss = "\n        div { content: data(); format: nl2br; }\n        ";
     $data = "Test Line 1 \n Test Line 2";
     $transphporm = new Builder($xml, $tss);
     $this->assertEquals($this->stripTabs('<div>Test Line 1 <br /> Test Line 2</div>'), $this->stripTabs($transphporm->output($data)->body));
 }
コード例 #6
0
    public function testFormatDateCustom()
    {
        $template = '
			<div>test</div>
		';
        $tss = 'div {content: "2015-10-05"; format: date "jS M"}';
        $template = new \Transphporm\Builder($template, $tss);
        $this->assertEquals($this->stripTabs('<div>5th Oct</div>'), $this->stripTabs($template->output()->body));
    }
コード例 #7
0
ファイル: CacheTest.php プロジェクト: level-2/transphporm
 public function testCacheImport()
 {
     $xml = $this->makeXml('<div></div>');
     $tss = $this->makeTss('div { content: "foo"; }');
     $cache = new \ArrayObject();
     $template = new \Transphporm\Builder($xml, __DIR__ . DIRECTORY_SEPARATOR . "cacheImport.tss");
     $template->setCache($cache);
     $this->assertEquals($this->stripTabs($template->output()->body), $this->stripTabs("<div>foo</div>"));
     sleep(1);
     // Have to sleep in order to have the timestamps be different
     $this->makeTss('div { content: "test"; }');
     $template = new \Transphporm\Builder($xml, __DIR__ . DIRECTORY_SEPARATOR . "cacheImport.tss");
     $template->setCache($cache);
     $this->assertEquals($this->stripTabs($template->output()->body), $this->stripTabs("<div>test</div>"));
 }
コード例 #8
0
 public function testXmlCommentInTemplate2()
 {
     $xml = "<div></div>";
     $tss = "div { content: template('" . str_replace('\\', '/', __DIR__) . "/xmlComment2.xml'); }";
     $template = new \Transphporm\Builder($xml, $tss);
     $this->assertEquals('<div><p></p><!-- Comment --></div>', $this->stripTabs($template->output()->body));
 }
コード例 #9
0
ファイル: CacheTest.php プロジェクト: cxj/Transphporm
    public function testCacheRepeat()
    {
        $data = ['One', 'Two', 'Three'];
        $tss = $this->makeTss('li { repeat: data(); content: iteration(); update-frequency: 10m}');
        $xml = $this->makeXml('<ul>
			<li>List item</li>
		</ul>');
        $cache = new \ArrayObject();
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        $expectedOutput = $this->stripTabs('<ul>
			<li>One</li>
			<li>Two</li>
			<li>Three</li>
		</ul>');
        $this->assertEquals($this->stripTabs($template->output($data)->body), $expectedOutput);
        //Now update the data:
        $data = ['Four', 'Five', 'Six'];
        //And rebuild the template
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        //The template should be cached and the new data not shown
        $this->assertEquals($this->stripTabs($template->output($data)->body), $expectedOutput);
        //Tick the clock so the cache expires
        $date = new \DateTime();
        $date->modify('+11 minutes');
        //And rebuild the template
        //Now update the data:
        $data = ['Four', 'Five', 'Six'];
        //And rebuild the template
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        $template->setTime($date->format('U'));
        //The output should now reflect the new data
        $expectedOutput = $this->stripTabs('<ul>
			<li>Four</li>
			<li>Five</li>
			<li>Six</li>
		</ul>');
        $this->assertEquals($this->stripTabs($template->output($data)->body), $expectedOutput);
    }
コード例 #10
0
    public function testCacheDisplay()
    {
        $xml = $this->makeXml('<div>
			<span>Test</span>
			</div>');
        $tss = $this->makeTss('
			span {display: block; update-frequency: 10m}
			span:data[show=false] { display:none; update-frequency: 10m }');
        $cache = new \ArrayObject();
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        //Hide the span
        $o1 = $template->output(['show' => false])->body;
        $this->assertFalse(strpos($o1, '<span>'));
        //The span should still be hidden even if the data has changed due to the cache
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        $o1 = $template->output(['show' => true])->body;
        $this->assertFalse(strpos($o1, '<span>'));
        //Expire the cache by advancing time 10 mintes
        $date = new \DateTime();
        $date->modify('+11 minutes');
        $template = new \Transphporm\Builder($xml, $tss);
        $template->setCache($cache);
        $template->setTime($date->format('U'));
        $o1 = $template->output(['show' => true])->body;
        //This time the span should be visible
        $this->assertTrue((bool) strpos($o1, '<span>'));
    }
コード例 #11
0
    public function testBindFormObject()
    {
        $tss = 'form {bind: data(object); }
				form input[name]:attr(value) {content: data(attr(name))}';
        $xml = '<form><input type="text" name="f1" /><input type="text" name="f2" /></form>';
        $obj = new stdclass();
        $obj->f1 = 'v1';
        $obj->f2 = 'v2';
        $data = ['object' => $obj];
        $template = new \Transphporm\Builder($xml, $tss);
        $this->assertEquals($this->stripTabs('<form><input type="text" name="f1" value="v1" /><input type="text" name="f2" value="v2" /></form>'), $this->stripTabs($template->output($data)->body));
    }
コード例 #12
0
    public function testHTMLFormat()
    {
        $template = '
			<div>test</div>
		';
        $tss = 'div {content: "<span>foobar</span>"; format: html}';
        $template = new \Transphporm\Builder($template, $tss);
        $this->assertEquals($this->stripTabs('<div><span>foobar</span></div>'), $this->stripTabs($template->output()->body));
    }
コード例 #13
0
ファイル: TransphpormTest.php プロジェクト: cxj/Transphporm
    public function testRuleOneComment()
    {
        $xml = '<div></div>';
        $tss = 'div {
			//Foo
		 }';
        $template = new \Transphporm\Builder($xml, $tss);
        $this->assertEquals('<div></div>', $template->output()->body);
    }