1<?php
2
3class TestOrphans extends GenericTest {
4  // No orphans at all
5  function testOrphans1() {
6    $media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
7                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
8    $tree = $this->runPipeline('
9<html>
10<head>
11<style type="text/css">
12body   { font-size: 10pt; line-height: 1; orphans:0; widows: 0; padding: 0; margin: 0; }
13#first { line-height: 1; height: 190pt; }
14#second { width: 3em; }
15</style>
16</head>
17<body>
18<div id="first">&nbsp;</div>
19<div id="second">
20LINE1<!--Page break should be here-->
21LINE2
22LINE3
23LINE4
24LINE5
25</div>
26</body>
27</html>
28', $media);
29
30    /**
31     * Calculate page heights
32     */
33    $page_heights = PageBreakLocator::getPages($tree,
34                                               mm2pt($media->real_height()),
35                                               mm2pt($media->height() - $media->margins['top']));
36
37    $first_div  = $tree->get_element_by_id('first');
38    $second_div = $tree->get_element_by_id('second');
39
40    $this->assertEqual(count($page_heights), 2,
41                       sprintf("Two pages expected, got %s",
42                               count($page_heights)));
43
44    $this->assertEqual($second_div->getCSSProperty(CSS_ORPHANS), 0);
45
46    $this->assertWithinMargin($page_heights[0],
47                              $first_div->get_full_height() + pt2pt(10),
48                              0.01);
49  }
50
51  // Default orphans value (2)
52  function testOrphans2() {
53    $media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
54                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
55    $tree = $this->runPipeline('
56<html>
57<head>
58<style type="text/css">
59body   { font-size: 10pt; line-height: 1; padding: 0; margin: 0; }
60#first { line-height: 1; height: 190pt; }
61#second { width: 3em; }
62</style>
63</head>
64<body>
65<div id="first">&nbsp;</div>
66<div id="second"><!--Page break should be here-->
67LINE1
68LINE2
69LINE3
70LINE4
71LINE5
72</div>
73</body>
74</html>
75', $media);
76
77    /**
78     * Calculate page heights
79     */
80    $page_heights = PageBreakLocator::getPages($tree,
81                                               mm2pt($media->real_height()),
82                                               mm2pt($media->height() - $media->margins['top']));
83
84    $first_div  = $tree->get_element_by_id('first');
85    $second_div = $tree->get_element_by_id('second');
86
87    $this->assertEqual(count($page_heights), 2,
88                       sprintf("Two pages expected, got %s",
89                               count($page_heights)));
90
91    $this->assertEqual($second_div->getCSSProperty(CSS_ORPHANS), 2);
92
93    $this->assertWithinMargin($page_heights[0],
94                              $first_div->get_full_height(),
95                              0.01);
96  }
97
98  // Increased orphans value (3)
99  function testOrphans3() {
100    $media = new Media(array('width' => 100, 'height' => 200/mm2pt(1)),
101                       array('top'=>0, 'bottom'=>0, 'left'=>0, 'right'=>0));
102    $tree = $this->runPipeline('
103<html>
104<head>
105<style type="text/css">
106body   { font-size: 10pt; line-height: 1; padding: 0; margin: 0; orphans: 3; }
107#first { line-height: 1; height: 180pt; }
108#second { width: 3em; }
109</style>
110</head>
111<body>
112<div id="first">&nbsp;</div>
113<div id="second"><!--Page break should be here-->
114LINE1
115LINE2
116LINE3
117LINE4
118LINE5
119</div>
120</body>
121</html>
122', $media);
123
124    /**
125     * Calculate page heights
126     */
127    $page_heights = PageBreakLocator::getPages($tree,
128                                               mm2pt($media->real_height()),
129                                               mm2pt($media->height() - $media->margins['top']));
130
131    $first_div  = $tree->get_element_by_id('first');
132    $second_div = $tree->get_element_by_id('second');
133
134    $this->assertEqual(count($page_heights), 2,
135                       sprintf("Two pages expected, got %s",
136                               count($page_heights)));
137
138    $this->assertEqual($second_div->getCSSProperty(CSS_ORPHANS), 3);
139
140    $this->assertWithinMargin($page_heights[0],
141                              $first_div->get_full_height(),
142                              0.01);
143  }
144}
145
146?>