1<?php
2
3class TestWhiteSpace extends GenericTest {
4  function testWhiteSpace1() {
5    $tree = $this->runPipeline(file_get_contents('test.white-space.1.html'));
6
7    $element =& $tree->get_element_by_id('div-normal');
8    $this->assertEqual($this->get_line_box_count($element),
9                       15,
10                       'Incorrect line box number in DIV with "white-space: normal" [%s]');
11
12    $element =& $tree->get_element_by_id('div-pre');
13    $this->assertEqual($this->get_line_box_count($element),
14                       10,
15                       'Incorrect line box number in DIV with "white-space: pre" [%s]');
16
17    $element =& $tree->get_element_by_id('div-pre2');
18    $this->assertEqual($this->get_line_box_count($element),
19                       9,
20                       'Incorrect line box number in DIV with "white-space: pre" without leading linefeeds [%s]');
21
22    $element =& $tree->get_element_by_id('div-pre3');
23    $this->assertEqual($this->get_line_box_count($element),
24                       11,
25                       'Incorrect line box number in DIV with "white-space: pre" with trailing empty line [%s]');
26
27    $element =& $tree->get_element_by_id('div-nowrap');
28    $this->assertEqual($this->get_line_box_count($element),
29                       2,
30                       'Incorrect line box number in DIV with "white-space: nowrap" [%s]');
31
32    $element =& $tree->get_element_by_id('div-pre-wrap');
33    $this->assertEqual($this->get_line_box_count($element),
34                       21,
35                       'Incorrect line box number in DIV with "white-space: pre-wrap" [%s]');
36
37    $element =& $tree->get_element_by_id('div-pre-wrap2');
38    $this->assertEqual($this->get_line_box_count($element),
39                       20,
40                       'Incorrect line box number in DIV with "white-space: pre-wrap" without leading linefeeds [%s]');
41
42    $element =& $tree->get_element_by_id('div-pre-line');
43    $this->assertEqual($this->get_line_box_count($element),
44                       19,
45                       'Incorrect line box number in DIV with "white-space: pre-line" with trailing empty line [%s]');
46  }
47
48  function testWhiteSpace2() {
49    $tree = $this->runPipeline(file_get_contents('test.white-space.2.html'));
50
51    $element =& $tree->get_element_by_id('div-normal');
52    $this->assertEqual($this->get_line_box_count($element),
53                       2,
54                       'Incorrect line box number in DIV with "white-space: normal" [%s]');
55
56    $element =& $tree->get_element_by_id('div-pre');
57    $this->assertEqual($this->get_line_box_count($element),
58                       4,
59                       'Incorrect line box number in DIV with "white-space: pre" [%s]');
60
61    $element =& $tree->get_element_by_id('div-pre2');
62    $this->assertEqual($this->get_line_box_count($element),
63                       3,
64                       'Incorrect line box number in DIV with "white-space: pre" without leading linefeeds [%s]');
65
66    $element =& $tree->get_element_by_id('div-pre3');
67    $this->assertEqual($this->get_line_box_count($element),
68                       4,
69                       'Incorrect line box number in DIV with "white-space: pre" with trailing empty line [%s]');
70
71    $element =& $tree->get_element_by_id('div-nowrap');
72    $this->assertEqual($this->get_line_box_count($element),
73                       1,
74                       'Incorrect line box number in DIV with "white-space: nowrap" [%s]');
75
76    $element =& $tree->get_element_by_id('div-pre-wrap');
77    $this->assertEqual($this->get_line_box_count($element),
78                       2,
79                       'Incorrect line box number in DIV with "white-space: pre-wrap" [%s]');
80
81    $element =& $tree->get_element_by_id('div-pre-wrap2');
82    $this->assertEqual($this->get_line_box_count($element),
83                       2,
84                       'Incorrect line box number in DIV with "white-space: pre-wrap" without leading linefeeds [%s]');
85
86    $element =& $tree->get_element_by_id('div-pre-line');
87    $this->assertEqual($this->get_line_box_count($element),
88                       2,
89                       'Incorrect line box number in DIV with "white-space: pre-line" with trailing empty line [%s]');
90  }
91
92  function get_line_box_count(&$box) {
93    $line_box_count = 0;
94    $prevous_br = false;
95    foreach ($box->content as $child) {
96      if (is_a($child, 'InlineBox')) {
97        $line_box_count += $child->get_line_box_count();
98
99        $last_box =& $child->get_last();
100        $previous_br = is_a($last_box, 'BRBox');
101      } elseif (is_a($child, 'BRBox')) {
102        if ($previous_br) {
103          $line_box_count++;
104        };
105        $previous_br = true;
106      } else {
107        $previous_br = false;
108      };
109    };
110    return $line_box_count;
111  }
112}
113
114?>