Example #1
0
 public function test_inheritance()
 {
     $_main = new Template(__DIR__ . '/files/templates/inheritance_main.tmpl');
     $_sub = new Template(__DIR__ . '/files/templates/inheritance_sub.tmpl');
     $mainVars = array('inheritance' => "Loads of money", 'separate' => "ONLY FOR MAIN");
     $recordSet = array(0 => array('separate' => 'first'), 1 => array('separate' => 'second'), 2 => array('separate' => 'third'));
     $rows = $_sub->renderRows($recordSet);
     $_main->addVarList($mainVars);
     $_main->addVar('subTemplate', $rows, false);
     $rendered = $_main->render(false);
     $this->assertEquals(0, count(Template::getTemplateVarDefinitions($rendered)));
     $this->assertEquals(1, preg_match('/first||/', $rendered));
     $this->assertEquals(1, preg_match('/second||/', $rendered));
     $this->assertEquals(1, preg_match('/third||/', $rendered));
     $matches = array();
     $this->assertEquals(4, preg_match_all('/Loads of money/', $rendered, $matches), "inheritance failed: " . ToolBox::debug_print($matches, 0));
     $this->assertEquals(4, count($matches[0]), "inheritance failed, not all variables were filled in: " . ToolBox::debug_print($matches) . "\n\n" . ToolBox::debug_print($rendered));
 }