/**
  * @since  1.9
  *
  * @param ParserParameterProcessor $parameters
  *
  * @return string|null
  */
 public function parse(ParserParameterProcessor $parameters)
 {
     $count = 0;
     $template = '';
     $subject = $this->parserData->getSemanticData()->getSubject();
     $parametersToArray = $parameters->toArray();
     if (isset($parametersToArray['template'])) {
         $template = $parametersToArray['template'][0];
         unset($parametersToArray['template']);
     }
     foreach ($parametersToArray as $property => $values) {
         $last = count($values) - 1;
         // -1 because the key starts with 0
         foreach ($values as $key => $value) {
             $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject);
             if ($this->parserData->canModifySemanticData()) {
                 $this->parserData->addDataValue($dataValue);
             }
             $this->messageFormatter->addFromArray($dataValue->getErrors());
             $this->addFieldsToTemplate($template, $dataValue, $property, $value, $last == $key, $count);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml();
     return array($html, 'noparse' => $template === '', 'isHTML' => false);
 }
 /**
  * @since since 2.2
  *
  * @return string
  */
 public function render()
 {
     $wikiText = $this->wikitextTemplateRenderer->render();
     if ($wikiText === '') {
         return '';
     }
     return $this->parser->recursiveTagParse($wikiText);
 }
 public function testRenderTemplate()
 {
     $instance = new WikitextTemplateRenderer();
     $this->assertEmpty($instance->render());
     $instance->addField('property', 'Foo');
     $instance->addField('value', 42);
     $instance->packFieldsForTemplate('Bar');
     $instance->addField('property', 'Bar');
     $instance->addField('value', 'Foo');
     $instance->packFieldsForTemplate('Foobaz');
     $this->assertEquals('{{Bar|property=Foo|value=42}}{{Foobaz|property=Bar|value=Foo}}', $instance->render());
     $this->assertEmpty($instance->render());
 }