/** * @covers Geissler\CSL\Rendering\Layout::__construct * @covers Geissler\CSL\Rendering\Layout::render */ public function testRender1() { $layout = '<layout delimiter="; "> <text macro="author" /> </layout>'; $json = '[ { "author": [ { "family": "Roe", "given": "Jane", "static-ordering": false } ], "id": "ITEM-1", "type": "book" }, { "author": [ { "family": "Doe", "given": "John", "static-ordering": false } ], "id": "ITEM-2", "type": "book" } ]'; $macro = '<macro name="author"> <names variable="author"> <name form="short" /> </names> </macro>'; $citation = '[ [ { "id": "ITEM-1" }, { "id": "ITEM-2" } ] ]'; Container::addMacro('author', new Macro(new \SimpleXMLElement($macro))); $this->initElement($layout, $json, $citation); $result = $this->object->render(''); $this->assertInternalType('array', $result); $this->assertContains('Roe; Doe', implode('', $result)); }
/** * Parses the style configuration from the SimpleXMLElement object. * * @param \SimpleXMLElement $xml * @return \Geissler\CSL\Style\Style */ public function readXml(\SimpleXMLElement $xml) { // store "global" configuration options in the context object Container::getContext()->addStyle('initializeWithHyphen', true); Container::getContext()->addStyle('demoteNonDroppingParticle', 'display-and-sort'); foreach ($xml->attributes() as $name => $value) { switch ($name) { case 'class': Container::getContext()->addStyle('class', (string) $value); break; case 'default-locale': $locale = Factory::locale(); $locale->readFile((string) $value); Container::setLocale($locale); break; } } // set global options and inheritable name options $options = new Options(); $options->set('style', $xml); foreach ($xml->children() as $child) { switch ($child->getName()) { case 'citation': Container::setCitation(new Citation($child)); break; case 'bibliography': Container::setBibliography(new Bibliography($child)); break; case 'macro': $macroName = ''; foreach ($child->attributes() as $name => $value) { if ($name == 'name') { $macroName = (string) $value; break; } } if ($macroName !== '') { Container::addMacro($macroName, new Macro($child)); } break; case 'locale': Container::getLocale()->addXml($child); break; } } return $this; }