/** * @dataProvider replaceExternalStylesheetsWithStyleProvider */ public function testReplaceExternalStylesheetsWithStyle($input, $style, $expected) { // Assert $this->assertXmlStringEqualsXmlString($expected, DomHandler::replaceExternalStylesheetsWithStyle($input, $style)); }
/** * Export the newsletter in HTML with or without inline CSS * * @param Symfony\Component\HttpFoundation\Request $request * @param int $newsletterId * @param int $inline * * @return Symfony\Component\HttpFoundation\Response */ public function exportAction(Request $request, $newsletterId, $inline) { $newsletter = $this->getService("em")->find("RZ\\Roadiz\\Core\\Entities\\Newsletter", $newsletterId); $filename = $newsletter->getNode()->getNodeName(); $content = $this->getNewsletterHTML($request, $newsletter); // Get all css link in the newsletter $cssContent = DomHandler::getExternalStyles($content); if ((bool) $inline === true) { // inline newsletter html with css $htmldoc = new InlineStyle($content); $htmldoc->applyStylesheet($cssContent); $htmldoc = $htmldoc->getHtml(); $filename .= "-inlined"; $content = $htmldoc; } // Remove all link element and add style balise with all css file content $htmldoc = DomHandler::replaceExternalStylesheetsWithStyle($content, $cssContent); // Generate response $response = new Response(); // Set headers $response->headers->set('Content-type', "text/html"); $response->headers->set('Content-Disposition', 'attachment; filename= "' . $filename . '.html";'); $response->setContent($htmldoc); return $response; }