Neos\Fusion\TypoScriptObjects\TagImplementation::evaluate PHP Method

evaluate() public method

Return a tag
public evaluate ( ) : mixed
return mixed
    public function evaluate()
    {
        $tagName = $this->getTagName();
        $omitClosingTag = $this->getOmitClosingTag();
        $selfClosingTag = $this->isSelfClosingTag($tagName);
        $content = '';
        if (!$omitClosingTag && !$selfClosingTag) {
            $content = $this->tsValue('content');
        }
        return '<' . $tagName . $this->tsValue('attributes') . ($selfClosingTag ? ' /' : '') . '>' . (!$omitClosingTag && !$selfClosingTag ? $content . '</' . $tagName . '>' : '');
    }

Usage Example

 /**
  * @test
  * @dataProvider tagExamples
  */
 public function evaluateTests($properties, $attributes, $content, $expectedOutput)
 {
     $path = 'tag/test';
     $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) use($properties, $path, $attributes, $content) {
         $relativePath = str_replace($path . '/', '', $evaluatePath);
         switch ($relativePath) {
             case 'attributes':
                 return $attributes;
             case 'content':
                 return $content;
         }
         return isset($properties[$relativePath]) ? $properties[$relativePath] : null;
     }));
     $typoScriptObjectName = 'Neos.Fusion:Tag';
     $renderer = new TagImplementation($this->mockTsRuntime, $path, $typoScriptObjectName);
     $result = $renderer->evaluate();
     $this->assertEquals($expectedOutput, $result);
 }