setTime() public method

Would be better if PHP allowed setting the script clock, but this is the simplest way of overriding it
public setTime ( $time )
コード例 #1
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;
 }
コード例 #2
0
ファイル: CacheTest.php プロジェクト: level-2/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);
    }
コード例 #3
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>'));
    }