1 | <?php
|
---|
2 | /**
|
---|
3 | * Html2Pdf Library - Tests
|
---|
4 | *
|
---|
5 | * HTML => PDF converter
|
---|
6 | * distributed under the OSL-3.0 License
|
---|
7 | *
|
---|
8 | * @package Html2pdf
|
---|
9 | * @author Laurent MINGUET <webmaster@html2pdf.fr>
|
---|
10 | * @copyright 2017 Laurent MINGUET
|
---|
11 | */
|
---|
12 |
|
---|
13 | namespace Spipu\Html2Pdf\Tests\Exception;
|
---|
14 |
|
---|
15 | use Spipu\Html2Pdf\Exception\ExceptionFormatter;
|
---|
16 | use Spipu\Html2Pdf\Exception\Html2PdfException;
|
---|
17 | use Spipu\Html2Pdf\Exception\HtmlParsingException;
|
---|
18 | use Spipu\Html2Pdf\Exception\ImageException;
|
---|
19 | use Spipu\Html2Pdf\Exception\LongSentenceException;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Class ExceptionFormaterTest
|
---|
23 | */
|
---|
24 | class ExceptionFormatterTest extends \PHPUnit_Framework_TestCase
|
---|
25 | {
|
---|
26 | /**
|
---|
27 | * Test the formatter / generic exception
|
---|
28 | */
|
---|
29 | public function testGeneric()
|
---|
30 | {
|
---|
31 | $exception = new Html2PdfException('My Message');
|
---|
32 | $formatter = new ExceptionFormatter($exception);
|
---|
33 |
|
---|
34 | $messages = [
|
---|
35 | $formatter->getMessage(),
|
---|
36 | $formatter->getHtmlMessage()
|
---|
37 | ];
|
---|
38 |
|
---|
39 | foreach ($messages as $message) {
|
---|
40 | $this->assertContains('Html2Pdf Error ['.Html2PdfException::ERROR_CODE.']', $message);
|
---|
41 | $this->assertContains('My Message', $message);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Test the formatter / parsing exception
|
---|
47 | */
|
---|
48 | public function testParsing()
|
---|
49 | {
|
---|
50 | $exception = new HtmlParsingException('My Message');
|
---|
51 | $exception->setInvalidTag('my_tag');
|
---|
52 | $exception->setHtmlLine(42);
|
---|
53 |
|
---|
54 | $formatter = new ExceptionFormatter($exception);
|
---|
55 |
|
---|
56 | $messages = [
|
---|
57 | $formatter->getMessage(),
|
---|
58 | $formatter->getHtmlMessage()
|
---|
59 | ];
|
---|
60 |
|
---|
61 | foreach ($messages as $message) {
|
---|
62 | $this->assertContains('Html2Pdf Error ['.HtmlParsingException::ERROR_CODE.']', $message);
|
---|
63 | $this->assertContains('My Message', $message);
|
---|
64 | $this->assertContains('my_tag', $message);
|
---|
65 | $this->assertContains('42', $message);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Test the formatter / image exception
|
---|
71 | */
|
---|
72 | public function testImage()
|
---|
73 | {
|
---|
74 | $exception = new ImageException('My Message');
|
---|
75 | $exception->setImage('my_image.png');
|
---|
76 |
|
---|
77 | $formatter = new ExceptionFormatter($exception);
|
---|
78 |
|
---|
79 | $messages = [
|
---|
80 | $formatter->getMessage(),
|
---|
81 | $formatter->getHtmlMessage()
|
---|
82 | ];
|
---|
83 |
|
---|
84 | foreach ($messages as $message) {
|
---|
85 | $this->assertContains('Html2Pdf Error ['.ImageException::ERROR_CODE.']', $message);
|
---|
86 | $this->assertContains('My Message', $message);
|
---|
87 | $this->assertContains('my_image.png', $message);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Test the formatter / long sentence exception
|
---|
93 | */
|
---|
94 | public function testLongSentence()
|
---|
95 | {
|
---|
96 | $exception = new LongSentenceException('My Message');
|
---|
97 | $exception->setSentence('my sentence');
|
---|
98 | $exception->setLength(142);
|
---|
99 | $exception->setWidthBox(242);
|
---|
100 |
|
---|
101 | $formatter = new ExceptionFormatter($exception);
|
---|
102 |
|
---|
103 | $messages = [
|
---|
104 | $formatter->getMessage(),
|
---|
105 | $formatter->getHtmlMessage()
|
---|
106 | ];
|
---|
107 |
|
---|
108 | foreach ($messages as $message) {
|
---|
109 | $this->assertContains('Html2Pdf Error ['.LongSentenceException::ERROR_CODE.']', $message);
|
---|
110 | $this->assertContains('My Message', $message);
|
---|
111 | $this->assertContains('my sentence', $message);
|
---|
112 | $this->assertContains('142', $message);
|
---|
113 | $this->assertContains('242', $message);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|