Пример #1
0
 public function testHtmlEntitiesBuiltin()
 {
     $view = new View();
     $view->loadString('<test><span fig:text="htmlentities(/data)"/></test>');
     $view->mount('data', '<TAG>');
     $this->assertEquals('<test><span>&lt;TAG&gt;</span></test>', $view->render());
 }
Пример #2
0
    public function testScriptTagWithoutContentIsNotForcedAutoClose()
    {
        $template = <<<TEMPLATE
<bob:template xmlns:bob="http://figdice.org">
  <link href="/assets/style.css" rel="stylesheet" />
  <script src="/assets/require.js"></script>
</bob:template>
TEMPLATE;
        $view = new View();
        $view->loadString($template);
        $output = $view->render();
        $expected = <<<EXPECTED
  <link href="/assets/style.css" rel="stylesheet" />
  <script src="/assets/require.js"></script>
EXPECTED;
        $this->assertEquals(trim($expected), trim($output));
        // Now try without xmlns
        $template = <<<TEMPLATE
<fig:template>
  <link href="/assets/style.css" rel="stylesheet" />
  <script src="/assets/require.js"></script>
</fig:template>
TEMPLATE;
        $view = new View();
        $view->loadString($template);
        $output = $view->render();
        $this->assertEquals(trim($expected), trim($output));
    }
Пример #3
0
    public function testPlugExecutesInLocalContext()
    {
        $template = <<<ENDTEMPLATE

<fig:template>
  <!-- define a slot -->
  <slot fig:slot="myslot">Default Slot Content</slot>

  <!-- create some contextual data -->
  <fig:mount target="someData" value="1" />

  <!-- execute the plug in the current context -->
  <title fig:mute="true" fig:plug="myslot" fig:text="/someData"/>

  <!-- modify the data that the plug refers to.
       Prior to version 2.3, the plug contents would render using the ending global context,
       but since 2.3 the plug is executed in its local context. -->
  <fig:mount target="someData" value="2" />
</fig:template>

ENDTEMPLATE;
        $view = new View([View::GLOBAL_PLUGS]);
        $view->loadString(trim($template));
        $rendered = $view->render();
        $this->assertEquals(2, trim($rendered));
        $view = new View();
        $view->loadString(trim($template));
        $rendered = $view->render();
        $this->assertEquals(1, trim($rendered));
    }
Пример #4
0
    public function testRangeFunc()
    {
        $source = <<<ENDXML
<li fig:walk="range(5)" fig:text="."></li>
ENDXML;
        $this->view->loadString($source);
        $this->assertEquals('<li>1</li><li>2</li><li>3</li><li>4</li><li>5</li>', $this->view->render());
    }
Пример #5
0
 public function testRelativePathDisambiguation()
 {
     //Check that heading dot is understated.
     $view = new View();
     $view->loadString(trim('<fig:template>' . '<fig:mute fig:text="data"/>:' . '<fig:mute fig:walk="lines" fig:text="data"/>:' . '<fig:mute fig:walk="lines" fig:text="./data"/>' . '</fig:template>'));
     $view->mount('data', 12);
     $view->mount('lines', [['data' => 13], ['data' => 14]]);
     $this->assertEquals('12:1314:1314', $view->render());
 }
Пример #6
0
    public function testFunctionXmlWithRootUsesSpecified()
    {
        $xml = <<<TEMPLATE
<fig:template>
  <fig:mount target="myXml">
    <myroot>
      <node1>value1</node1>
      <node2>value2</node2>
    </myroot>
  </fig:mount>
  <fig:mute fig:text="xpath(xml(/myXml), '/myroot/node1')"/>
</fig:template>
TEMPLATE;
        $view = new View();
        $view->loadString($xml);
        $output = trim($view->render());
        $this->assertEquals('value1', $output);
    }
Пример #7
0
 /**
  * @expectedException \figdice\exceptions\RenderingException
  */
 public function testAttributeEvalsToArrayException()
 {
     $source = '<xml attr="{myArray}"></xml>';
     $view = new View();
     $view->loadString($source);
     $view->mount('myArray', array(4, 5, 6));
     $this->assertEquals('dummy', $view->render());
 }
Пример #8
0
    /**
     * @expectedException \figdice\exceptions\DictionaryEntryNotFoundException
     */
    public function testAnonTransWithoutLoadedDicRaisesError()
    {
        $view = new View();
        $str = <<<ENDTEMPLATE
<fig:template>
  <fig:trans key="somekey"/>
</fig:template>
ENDTEMPLATE;
        $view->loadString($str);
        $view->setLanguage('en');
        vfsStream::setup('root');
        $view->setTranslationPath(vfsStream::url('root'));
        $view->render();
    }
Пример #9
0
 /**
  * Renders template from string to the ResponseInterface stream.
  *
  * @param ResponseInterface $response
  * @param $templateString
  * @param array $data
  * @return ResponseInterface
  */
 public function renderFromString(ResponseInterface $response, $templateString, array $data = array())
 {
     $this->view->loadString($templateString);
     $this->renderWithData($response, $data);
     return $response;
 }
Пример #10
0
    public function testNestedLoops()
    {
        $template = <<<ENDTEMPLATE
<fig:mute fig:walk="/outer">
  <fig:mute fig:walk="inner">
    <fig:mute fig:text="../page"/>-<fig:mute fig:text="x"/>
  </fig:mute>
</fig:mute>
ENDTEMPLATE;
        $data = [];
        for ($i = 1; $i <= 5; ++$i) {
            $inner = [];
            for ($j = 0; $j < 3; ++$j) {
                $inner[] = ['x' => $j];
            }
            $data[] = ['page' => 10 * $i, 'inner' => $inner];
        }
        $view = new View();
        $view->loadString($template);
        $view->mount('outer', $data);
        $result = preg_replace('# +#', ' ', str_replace("\n", ' ', trim($view->render())));
        $this->assertEquals('10-0 10-1 10-2 20-0 20-1 20-2 30-0 30-1 30-2 40-0 40-1 40-2 50-0 50-1 50-2', $result);
    }
Пример #11
0
    public function testDoctypeOnNonRootNodeReplacesExisting()
    {
        $view = new View();
        $templateSource = <<<ENDXML
<fig:template>
<html fig:doctype="html">
  <head fig:doctype="dummy"></head>
</html>
</fig:template>
ENDXML;
        $view->loadString($templateSource);
        $expected = <<<EXPECTED
<!doctype dummy>
<html>
  <head></head>
</html>

EXPECTED;
        $rendered = $view->render();
        $this->assertEquals($expected, $rendered);
    }
Пример #12
0
 public function testAdHocEval()
 {
     $view = new View();
     $view->loadString('<xml attr="some {adhoc} here"></xml>');
     $view->mount('adhoc', 'test');
     $this->assertEquals('<xml attr="some test here"></xml>', $view->render());
 }
Пример #13
0
    public function testXmlnsFigIsNotRendered()
    {
        $template = <<<ENDTEMPLATE
<html xmlns:fig="http://figdice.org/">
</html>
ENDTEMPLATE;
        $view = new View();
        $view->loadString($template);
        $actual = $view->render();
        $expected = "<html>\n</html>";
        $this->assertEquals($expected, $actual);
    }