Exemple #1
0
 function testSetters()
 {
     $templateXML = simplexml_load_string($this->fullTemplateString, "SimpleXMLElement");
     $template = new TemplateDef($templateXML);
     // test param merger
     $this->assertEquals(5, count($template->getParams()));
     $template->addParam("newKey", "newValue");
     $this->assertEquals(6, count($template->getParams()));
     $this->assertEquals("newValue", $template->getParam("newKey"));
     // test original path
     $this->assertEquals("templates/default.php", $template->getPath());
     $template->setPath("templates/minimal.php");
     // should not change due to already being set
     $this->assertEquals("templates/default.php", $template->getPath());
     // test override when nothing orginally set
     $templateXML = simplexml_load_string($this->noPathTemplateString, "SimpleXMLElement");
     $template = new TemplateDef($templateXML);
     $this->assertEquals("", $template->getPath());
     $template->setPath("templates/minimal.php");
     $this->assertEquals("templates/minimal.php", $template->getPath());
 }
Exemple #2
0
 /**
  * Get the TemplateDef for the given template name.
  *
  * @param string $templateName Name of the template you're looking for.
  *
  * @return class The template definition associated with the given name
  * or null if not found.
  *
  * @todo Improve error messages such that the path resolution is more clear.
  */
 public function getTemplate($templateName)
 {
     $returnTemplate = null;
     foreach ($this->templates as $template) {
         if ((string) $template['name'] == $templateName) {
             $templateDef = new TemplateDef($template);
             // if extends other template, use that path
             if (!is_null($template['extends'])) {
                 $extendedTemplate = $this->getTemplate($template['extends']);
                 // merge defs
                 $templateDef->setPath($extendedTemplate->getPath());
                 foreach ($extendedTemplate->getParams() as $name => $value) {
                     $templateDef->addParam($name, $value);
                 }
             }
             return $templateDef;
         }
     }
     return null;
 }