Exemplo n.º 1
0
 public function testSerializeXmlFormat()
 {
     $doc = new ezcDocumentDocbook();
     $doc->options->indentXml = true;
     $doc->loadFile(dirname(__FILE__) . '/files/xhtml_sample_basic.xml');
     $this->assertEquals(file_get_contents(dirname(__FILE__) . '/files/xhtml_sample_basic_indented.xml'), $doc->save());
 }
Exemplo n.º 2
0
 /**
  * @dataProvider getTestDocuments
  */
 public function testCreateFromDocbook($to, $from)
 {
     // Tested for correctness in converter tests!
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile($from);
     $document = new ezcDocumentOdt();
     $document->createFromDocbook($docbook);
     $this->assertNotNull($document->getDomDocument());
 }
Exemplo n.º 3
0
Arquivo: base.php Projeto: bmdevel/ezc
 /**
  * Test rendering of a full document
  *
  * Test the rendering of a given full document with an
  * additional set of user configured styles.
  *
  * @param string $file 
  * @param string $fileName 
  * @param array $styles 
  * @return void
  */
 protected function renderFullDocument($file, $fileName, array $styles = array())
 {
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile($file);
     $style = new ezcDocumentPcssStyleInferencer();
     $style->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('article'), array('font-family' => 'serif', 'line-height' => '1')), new ezcDocumentPcssLayoutDirective(array('title'), array('font-family' => 'sans-serif'))));
     $style->appendStyleDirectives($styles);
     $renderer = new ezcDocumentPdfMainRenderer(new ezcDocumentPdfSvgDriver(), $style, new ezcDocumentPdfOptions());
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
     file_put_contents($this->tempDir . $fileName, $pdf);
     $this->assertXmlFileEqualsXmlFile($this->basePath . 'renderer/' . $fileName, $this->tempDir . $fileName);
 }
Exemplo n.º 4
0
 public function testRenderCustomStyleAndAdditionalPdfParts()
 {
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/long_text.xml');
     $pdfDoc = new ezcDocumentPdf(new ezcDocumentPdfOptions(array('driver' => new ezcDocumentPdfSvgDriver())));
     $pdfDoc->loadStyles(dirname(__FILE__) . '/../files/pdf/custom.css');
     $pdfDoc->registerPdfPart(new ezcDocumentPdfHeaderPdfPart());
     $pdfDoc->createFromDocbook($docbook);
     $pdf = (string) $pdfDoc;
     file_put_contents($this->tempDir . ($fileName = __CLASS__ . '_' . __FUNCTION__ . '.svg'), $pdf);
     $this->assertXmlFileEqualsXmlFile($this->basePath . 'renderer/' . $fileName, $this->tempDir . $fileName);
 }
Exemplo n.º 5
0
 public function testWriteConfluenceDocument()
 {
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/files/wiki/confluence/s_002_inline_markup.xml');
     try {
         $wiki = new ezcDocumentConfluenceWiki();
         $wiki->createFromDocbook($docbook);
         $wiki->save();
         $this->fail('Expected ezcDocumentMissingVisitorException');
     } catch (ezcDocumentMissingVisitorException $e) {
         /* Expected */
     }
 }
Exemplo n.º 6
0
 /**
  * @dataProvider getTestDocuments
  */
 public function testStylerCalls()
 {
     $testDocs = self::getTestDocuments();
     if (count($testDocs) < 1) {
         throw new RuntimeException('Missing test documents.');
     }
     $doc = new ezcDocumentDocbook();
     $doc->loadFile($testDocs[0][0]);
     $stylerMock = new ezcDocumentOdtTestStyler();
     $converter = new ezcDocumentDocbookToOdtConverter(new ezcDocumentDocbookToOdtConverterOptions(array('styler' => $stylerMock)));
     $created = $converter->convert($doc);
     $this->assertTrue($stylerMock->odtDocument instanceof DOMDocument);
     $this->assertEquals(38, count($stylerMock->seenElements));
 }
 public function testCreateFromDocbook()
 {
     $from = dirname(__FILE__) . '/files/docbook/xhtml/s_001_empty.xml';
     $to = dirname(__FILE__) . '/files/docbook/xhtml/s_001_empty.html';
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile($from);
     $document = new ezcDocumentXhtml();
     $document->createFromDocbook($docbook);
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('docbook_xhtml_') . '/';
     file_put_contents($tempDir . basename($to), $xml = $document->save());
     $this->assertEquals(file_get_contents($to), $xml, 'Document not visited as expected.');
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
 public function testRenderBlockquote()
 {
     // Additional formatting
     $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord'));
     // Expectations
     $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(20, 1.0), $this->equalTo(21, 1.0), $this->equalTo("Some"));
     $mock->expects($this->at(2))->method('drawWord')->with($this->equalTo(35, 1.0), $this->equalTo(21, 1.0), $this->equalTo("random"));
     $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(20, 1.0), $this->equalTo(29.4, 1.0), $this->equalTo("which"));
     $mock->expects($this->at(13))->method('drawWord')->with($this->equalTo(25, 1.0), $this->equalTo(46.8, 1.0), $this->equalTo("Name"));
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/blockquote.xml');
     $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
 }
Exemplo n.º 9
0
 public function testRenderDefinitionListWrapped()
 {
     $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord'));
     // Expectations
     $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(18, 1.0), $this->equalTo("A"));
     $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(29.2, 1.0), $this->equalTo("is"));
     $mock->expects($this->at(10))->method('drawWord')->with($this->equalTo(15, 1.0), $this->equalTo(62.8, 1.0), $this->equalTo("The"));
     $mock->expects($this->at(20))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(21))->method('drawWord')->with($this->equalTo(15, 1.0), $this->equalTo(18, 1.0), $this->equalTo("to"));
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/variablelist_long.xml');
     $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
 }
Exemplo n.º 10
0
 public function testRenderLiterallayoutWrapped()
 {
     // Additional formatting
     $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord', 'drawPolygon', 'drawPolyline'));
     // Expectations
     $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(5))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(18, 1.0), $this->equalTo("1"));
     $mock->expects($this->at(13))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(85.2, 1.0), $this->equalTo("9"));
     $mock->expects($this->at(14))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(27))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(32))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(18, 1.0), $this->equalTo("9"));
     $mock->expects($this->at(33))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(26.4, 1.0), $this->equalTo("0"));
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/literallayout_long.xml');
     $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
 }
 /**
  * @dataProvider getTestDocuments
  */
 public function testLoadXmlDocumentFromFile($from, $to)
 {
     if (!is_file($to)) {
         $this->markTestSkipped("Comparision file '{$to}' not yet defined.");
     }
     $doc = new ezcDocumentDocbook();
     $doc->loadFile($from);
     $converter = new ezcDocumentDocbookToWikiConverter();
     $created = $converter->convert($doc);
     $this->assertTrue($created instanceof ezcDocumentWiki);
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('docbook_rst_') . '/';
     file_put_contents($tempDir . basename($to), $text = $created->save());
     $this->assertTrue(($errors = $created->validateString($text)) === true, is_array($errors) ? implode(PHP_EOL, $errors) : 'Expected true');
     $this->assertEquals(file_get_contents($to), $text);
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
 /**
  * @dataProvider getTestDocuments
  */
 public function testLoadXmlDocumentFromFile($from, $to)
 {
     if (!ezcBaseFeatures::hasExtensionSupport('xsl')) {
         $this->markTestSkipped('You need XSLT support for this test.');
     }
     if (!is_file($to)) {
         $this->markTestSkipped("Comparision file '{$to}' not yet defined.");
     }
     $doc = new ezcDocumentDocbook();
     $doc->loadFile($from);
     $converter = new ezcDocumentDocbookToHtmlXsltConverter();
     $created = $converter->convert($doc);
     $this->assertTrue($created instanceof ezcDocumentXhtml);
     // Replace creator string in generated document, as this may change too
     // often for proper testing.
     $dom = $created->getDomDocument();
     $domContent = $dom->saveXml();
     // Just test that some kind of HTML has been created - everything is up
     // to the used XSL and may change any time.
     $this->assertTrue(strpos($domContent, '<html') !== false);
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
Exemplo n.º 13
0
 public function testWithStylesheets()
 {
     $from = dirname(__FILE__) . '/files/docbook/xhtml/s_021_field_list.xml';
     $to = dirname(__FILE__) . '/files/docbook/xhtml/s_021_field_list_stylesheets.html';
     $doc = new ezcDocumentDocbook();
     $doc->loadFile($from);
     $converter = new ezcDocumentDocbookToHtmlConverter();
     $converter->options->formatOutput = true;
     $converter->options->dublinCoreMetadata = true;
     $converter->options->styleSheets = array('foo.css', 'http://example.org/bar.css');
     $created = $converter->convert($doc);
     $this->assertTrue($created instanceof ezcDocumentXhtml);
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('docbook_html_custom_') . '/';
     file_put_contents($tempDir . basename($to), $xml = $created->save());
     $this->assertEquals(file_get_contents($to), $xml);
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
Exemplo n.º 14
0
 public function testRenderCustomFont()
 {
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/wrapping.xml');
     $style = new ezcDocumentPcssStyleInferencer();
     $style->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('article'), array('font-family' => 'my-font')), new ezcDocumentPcssDeclarationDirective('@font-face', array('font-family' => 'my-font', 'src' => 'url( ' . dirname(__FILE__) . '/../files/fonts/font.ttf )'))));
     $renderer = new ezcDocumentPdfMainRenderer(new ezcDocumentPdfSvgDriver(), $style);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
     $this->assertPdfDocumentsSimilar($pdf, __CLASS__ . '_' . __FUNCTION__);
 }
Exemplo n.º 15
0
<?php

require 'tutorial_autoload.php';
$docbook = new ezcDocumentDocbook();
$docbook->loadFile('docbook.xml');
$odt = new ezcDocumentOdt();
$odt->createFromDocbook($docbook);
echo $odt->save();
Exemplo n.º 16
0
<?php

require 'tutorial_autoload.php';
$docbook = new ezcDocumentDocbook();
$docbook->loadFile('address.xml');
class myAddressElementHandler extends ezcDocumentDocbookToRstBaseHandler
{
    public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root)
    {
        $root .= $this->renderDirective('address', $node->textContent, array());
        return $root;
    }
}
$converter = new ezcDocumentDocbookToRstConverter();
$converter->setElementHandler('docbook', 'address', new myAddressElementHandler());
$rst = $converter->convert($docbook);
echo $rst->save();
Exemplo n.º 17
0
 public function testRenderParagraphSplittingWithBorderLastPage()
 {
     // Additional formatting
     $this->styles->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('para'), array('line-height' => '1', 'padding' => '5', 'margin' => '5', 'border' => '1mm solid #A00000', 'background-color' => '#eedbdb'))));
     $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('drawPolyline', 'drawPolygon', 'createPage', 'drawWord'));
     // Expectations for third page
     $mock->expects($this->at(38))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0));
     $mock->expects($this->at(39))->method('drawPolygon')->with($this->equalTo(array(array(15, 15), array(85, 15), array(85, 51), array(15, 51)), 1.0), $this->equalTo(array('red' => 0.93, 'green' => 0.86, 'blue' => 0.86, 'alpha' => 0), 0.01));
     $mock->expects($this->at(40))->method('drawPolyline')->with($this->equalTo(array(array(15.5, 15.5), array(15.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01));
     $mock->expects($this->at(41))->method('drawPolyline')->with($this->equalTo(array(array(84.5, 15.5), array(84.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01));
     $mock->expects($this->at(42))->method('drawPolyline')->with($this->equalTo(array(array(84.5, 50.5), array(15.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01));
     $mock->expects($this->at(43))->method('drawWord')->with($this->equalTo(21, 1.0), $this->equalTo(29, 1.0), $this->equalTo('be'));
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/wrapping.xml');
     $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
 }
Exemplo n.º 18
0
 /**
  * @dataProvider getItemizedListTypes
  */
 public function testRenderItemizedListTypes($type, array $items)
 {
     $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord'));
     // Expectations
     $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(18, 1.0), $this->equalTo($items[0]));
     $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(33, 1.0), $this->equalTo($items[1]));
     $docbook = new ezcDocumentDocbook();
     $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/bullet_list.xml');
     // Set numeration type in document
     $dom = $docbook->getDomDocument();
     $xpath = new DOMXPath($dom);
     $xpath->registerNamespace('doc', 'http://docbook.org/ns/docbook');
     $list = $xpath->evaluate('//doc:itemizedlist')->item(0);
     $list->setAttribute('mark', $type);
     $docbook->setDomDocument($dom);
     $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles);
     $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator());
 }