Пример #1
0
 /**
  * Tests that the engine generates the right command
  */
 public function testGetCommand()
 {
     $class = new \ReflectionClass('CakePdf\\Pdf\\Engine\\WkHtmlToPdfEngine');
     $method = $class->getMethod('_getCommand');
     $method->setAccessible(true);
     $Pdf = new CakePdf(['engine' => ['className' => 'CakePdf.WkHtmlToPdf', 'options' => ['quiet' => false, 'encoding' => 'ISO-8859-1']], 'title' => 'CakePdf rules']);
     $result = $method->invokeArgs($Pdf->engine(), []);
     $expected = "/usr/bin/wkhtmltopdf --print-media-type --orientation 'portrait' --page-size 'A4' --encoding 'ISO-8859-1' --title 'CakePdf rules' - -";
     $this->assertEquals($expected, $result);
     $Pdf = new CakePdf(['engine' => ['className' => 'CakePdf.WkHtmlToPdf', 'options' => ['boolean' => true, 'string' => 'value', 'integer' => 42]]]);
     $result = $method->invokeArgs($Pdf->engine(), []);
     $expected = "/usr/bin/wkhtmltopdf --quiet --print-media-type --orientation 'portrait' --page-size 'A4' --encoding 'UTF-8' --boolean --string 'value' --integer '42' - -";
     $this->assertEquals($expected, $result);
 }
Пример #2
0
 /**
  * Tests that the engine generates the right command
  */
 public function testGetCommand()
 {
     $class = new \ReflectionClass('CakePdf\\Pdf\\Engine\\TexToPdfEngine');
     $method = $class->getMethod('_getCommand');
     $method->setAccessible(true);
     $Pdf = new CakePdf(['engine' => ['className' => 'CakePdf.TexToPdf']]);
     $result = $method->invokeArgs($Pdf->engine(), []);
     if (DS === '\\') {
         $expected = '/usr/bin/latexpdf --output-directory "' . TMP . 'pdf"';
     } else {
         $expected = '/usr/bin/latexpdf --output-directory \'' . TMP . 'pdf\'';
     }
     $this->assertEquals($expected, $result);
 }
Пример #3
0
 /**
  * Tests that the Dompdf instance is being processed as expected.
  */
 public function testDompdfControlFlow()
 {
     $engineClass = $this->getMockClass('\\CakePdf\\Pdf\\Engine\\DomPdfEngine', ['_createInstance']);
     $Pdf = new CakePdf(['engine' => '\\' . $engineClass]);
     $Pdf->engine()->expects($this->once())->method('_createInstance')->will($this->returnCallback(function ($options) {
         $Dompdf = $this->getMock('\\Dompdf\\Dompdf', ['setPaper', 'loadHtml', 'render', 'output'], [$options]);
         $Dompdf->expects($this->at(0))->method('setPaper')->with('A4', 'portrait');
         $Dompdf->expects($this->at(1))->method('loadHtml')->with(null);
         $Dompdf->expects($this->at(2))->method('render');
         $Dompdf->expects($this->at(3))->method('output');
         return $Dompdf;
     }));
     $Pdf->engine()->output();
 }
Пример #4
0
 /**
  *
  * @dataProvider provider
  */
 public function testMargin($config)
 {
     $pdf = new CakePdf($config);
     $pdf->margin(15, 20, 25, 30);
     $expected = ['bottom' => 15, 'left' => 20, 'right' => 25, 'top' => 30];
     $this->assertEquals($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(75);
     $expected = ['bottom' => 75, 'left' => 75, 'right' => 75, 'top' => 75];
     $this->assertEquals($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(20, 50);
     $expected = ['bottom' => 20, 'left' => 50, 'right' => 50, 'top' => 20];
     $this->assertEquals($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(['left' => 120, 'right' => 30, 'top' => 34, 'bottom' => 15]);
     $expected = ['bottom' => 15, 'left' => 120, 'right' => 30, 'top' => 34];
     $this->assertEquals($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $expected = ['bottom' => 15, 'left' => 50, 'right' => 30, 'top' => 45];
     $this->assertEquals($expected, $pdf->margin());
 }
Пример #5
0
 /**
  * Renders the Dompdf instance.
  *
  * @param CakePdf $Pdf The CakePdf instance that supplies the content to render.
  * @param Dompdf $DomPDF The Dompdf instance to render.
  * @return Dompdf
  */
 protected function _render($Pdf, $DomPDF)
 {
     $DomPDF->loadHtml($Pdf->html());
     $DomPDF->render();
     return $DomPDF;
 }
Пример #6
0
 /**
  *
  * @dataProvider provider
  */
 public function testConfigRead($config)
 {
     Configure::write('CakePdf', $config);
     $pdf = new CakePdf();
     $this->assertEquals($config['margin'], $pdf->margin());
     $this->assertEquals($config['orientation'], $pdf->orientation());
 }