Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
class TestPagebreak extends GenericTest {
4
  // Page break between text lines
5
  function testPagebreakText1() {
6
    $media = new Media(array('width' => 100, 'height' => 100),
7
                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
8
    $tree = $this->runPipeline(file_get_contents('test.pagebreak.text.1.html'), $media);
9
 
10
    /**
11
     * Calculate page heights
12
     */
13
    $page_heights = PageBreakLocator::getPages($tree,
14
                                               mm2pt($media->real_height()),
15
                                               mm2pt($media->height() - $media->margins['top']));
16
 
17
    $first_div  = $tree->get_element_by_id('first');
18
    $second_div = $tree->get_element_by_id('second');
19
 
20
    $this->assertEqual(count($page_heights), 2,
21
                       sprintf("Two pages expected, got %s",
22
                               count($page_heights)));
23
 
24
    $this->assertTrue($page_heights[0] <= mm2pt($media->real_height()),
25
                      sprintf("Page height (%s) is greater than media height (%s)",
26
                              $page_heights[0],
27
                              mm2pt($media->real_height())));
28
 
29
    $this->assertEqual($page_heights[1],
30
                       mm2pt($media->real_height()),
31
                       sprintf("Second page height (%s) should be equal to media height (%s)",
32
                               $page_heights[1],
33
                               mm2pt($media->real_height())));
34
 
35
    $this->assertWithinMargin($page_heights[0],
36
                              $first_div->get_full_height(),
37
                              0.01,
38
                              sprintf("First page (height %s) should contain 'first' DIV (height %s); media height is %s",
39
                                      $page_heights[0],
40
                                      $first_div->get_full_height(),
41
                                      mm2pt($media->real_height())));
42
 
43
    $this->assertEqual($page_heights[1] >= $second_div->get_full_height(),
44
                       sprintf("Second page (height %s) should contain 'second' DIV (height %s)",
45
                               $page_heights[1],
46
                               $second_div->get_full_height()));
47
  }
48
 
49
  // page-break-inside: avoid
50
  function testPagebreakText2() {
51
    $media = new Media(array('width' => 100, 'height' => 300),
52
                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
53
    $tree = $this->runPipeline(file_get_contents('test.pagebreak.text.2.html'), $media);
54
 
55
    /**
56
     * Calculate page heights
57
     */
58
    $page_heights = PageBreakLocator::getPages($tree,
59
                                               mm2pt($media->real_height()),
60
                                               mm2pt($media->height() - $media->margins['top']));
61
 
62
    $first_div  = $tree->get_element_by_id('first');
63
    $second_div = $tree->get_element_by_id('second');
64
    $third_div  = $tree->get_element_by_id('third');
65
 
66
    $this->assertEqual(count($page_heights), 2,
67
                       sprintf("2 pages expected, got %s",
68
                               count($page_heights)));
69
 
70
    $this->assertWithinMargin($page_heights[0],
71
                              $first_div->get_full_height(),
72
                              0.01,
73
                              sprintf("First page (height %s) should contain only 'first' DIV (height %s); media height is %s",
74
                                      $page_heights[0],
75
                                      $first_div->get_full_height(),
76
                                      mm2pt($media->real_height())));
77
  }
78
 
79
  // page-break-after: avoid
80
  function testPagebreakText3() {
81
    $media = new Media(array('width' => 100, 'height' => 300),
82
                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
83
    $tree = $this->runPipeline('
84
<html>
85
<head>
86
<style type="text/css">
87
body    { font-size: 20mm; line-height: 1; width: 4em;  padding: 0; margin: 0; orphans: 0; widows: 0; }
88
#wrap   { width: 2em; }
89
#first  { line-height: 1; page-break-after: avoid; }
90
#second { line-height: 1; page-break-inside: avoid; }
91
#third  { line-height: 1; }
92
</style>
93
</head>
94
<body>
95
<div id="wrap">
96
<div id="first">
97
LINE1
98
LINE2
99
LINE3
100
LINE4
101
LINE5
102
LINE6
103
LINE7
104
LINE8
105
LINE9
106
LINE10
107
LINE11
108
LINE12
109
LINE13
110
</div><!--Page break should be here-->
111
<div id="second">
112
LINE1
113
LINE2
114
LINE3
115
</div>
116
<div id="third">
117
LINE1
118
LINE2
119
LINE3
120
</div>
121
</div>
122
</body>
123
</html>
124
', $media);
125
 
126
    /**
127
     * Calculate page heights
128
     */
129
    $page_heights = PageBreakLocator::getPages($tree,
130
                                               mm2pt($media->real_height()),
131
                                               mm2pt($media->height() - $media->margins['top']));
132
 
133
    $first_div  = $tree->get_element_by_id('first');
134
    $second_div = $tree->get_element_by_id('second');
135
    $third_div  = $tree->get_element_by_id('third');
136
 
137
    $this->assertEqual(count($page_heights), 2,
138
                       sprintf("2 pages expected, got %s",
139
                               count($page_heights)));
140
 
141
    $this->assertWithinMargin($page_heights[0],
142
                              $first_div->get_full_height() - mm2pt(20),
143
                              0.01);
144
  }
145
 
146
  // page-break-before: avoid
147
  function testPagebreakText4() {
148
    $media = new Media(array('width' => 100, 'height' => 300),
149
                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
150
    $tree = $this->runPipeline('
151
<html>
152
<head>
153
<style type="text/css">
154
body    { font-size: 20mm; line-height: 1; padding: 0; margin: 0; orphans: 0; widows: 0; }
155
#wrap   { width: 2em; }
156
#first  { line-height: 1; }
157
#second { line-height: 1; page-break-before: avoid; page-break-inside: avoid; }
158
#third  { line-height: 1; }
159
</style>
160
</head>
161
<body>
162
<div id="wrap">
163
<div id="first">
164
LINE1
165
LINE2
166
LINE3
167
LINE4
168
LINE5
169
LINE6
170
LINE7
171
LINE8
172
LINE9
173
LINE10
174
LINE11
175
LINE12
176
LINE13
177
</div><!--Page break should be here-->
178
<div id="second">
179
LINE1
180
LINE2
181
LINE3
182
</div>
183
<div id="third">
184
LINE1
185
LINE2
186
LINE3
187
</div>
188
</div>
189
</body>
190
</html>
191
', $media);
192
 
193
    /**
194
     * Calculate page heights
195
     */
196
    $page_heights = PageBreakLocator::getPages($tree,
197
                                               mm2pt($media->real_height()),
198
                                               mm2pt($media->height() - $media->margins['top']));
199
 
200
    $first_div  = $tree->get_element_by_id('first');
201
    $second_div = $tree->get_element_by_id('second');
202
    $third_div  = $tree->get_element_by_id('third');
203
 
204
    $this->assertEqual(count($page_heights), 2,
205
                       sprintf("2 pages expected, got %s",
206
                               count($page_heights)));
207
 
208
    $this->assertWithinMargin($page_heights[0],
209
                              $first_div->get_full_height() - mm2pt(20),
210
                              0.01);
211
  }
212
}
213
 
214
?>