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