1<?php 2 3class 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"> 87body { 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"> 97LINE1 98LINE2 99LINE3 100LINE4 101LINE5 102LINE6 103LINE7 104LINE8 105LINE9 106LINE10 107LINE11 108LINE12 109LINE13 110</div><!--Page break should be here--> 111<div id="second"> 112LINE1 113LINE2 114LINE3 115</div> 116<div id="third"> 117LINE1 118LINE2 119LINE3 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"> 154body { 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"> 164LINE1 165LINE2 166LINE3 167LINE4 168LINE5 169LINE6 170LINE7 171LINE8 172LINE9 173LINE10 174LINE11 175LINE12 176LINE13 177</div><!--Page break should be here--> 178<div id="second"> 179LINE1 180LINE2 181LINE3 182</div> 183<div id="third"> 184LINE1 185LINE2 186LINE3 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?>