]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/DebugTest.php
09860914af4830fb348dba8422d8d0262b0e2d59
[nominatim.git] / test / php / Nominatim / DebugTest.php
1 <?php
2
3 namespace Nominatim;
4
5 require_once(CONST_LibDir.'/DebugHtml.php');
6
7 class DebugTest extends \PHPUnit\Framework\TestCase
8 {
9
10     protected function setUp(): void
11     {
12         $this->oWithDebuginfo = $this->getMockBuilder(\GeococdeMock::class)
13                                     ->setMethods(array('debugInfo'))
14                                     ->getMock();
15         $this->oWithDebuginfo->method('debugInfo')
16                   ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'));
17
18
19         $this->oWithToString = $this->getMockBuilder(\SomeMock::class)
20                                     ->setMethods(array('__toString'))
21                                     ->getMock();
22         $this->oWithToString->method('__toString')->willReturn('me as string');
23     }
24
25     public function testPrintVar()
26     {
27         $this->expectOutputString(<<<EOT
28 <pre><b>Var0:</b>  </pre>
29 <pre><b>Var1:</b>  <i>True</i></pre>
30 <pre><b>Var2:</b>  <i>False</i></pre>
31 <pre><b>Var3:</b>  0</pre>
32 <pre><b>Var4:</b>  'String'</pre>
33 <pre><b>Var5:</b>  0 => 'one'
34        1 => 'two'
35        2 => 'three'</pre>
36 <pre><b>Var6:</b>  'key' => 'value'
37        'key2' => 'value2'</pre>
38 <pre><b>Var7:</b>  me as string</pre>
39 <pre><b>Var8:</b>  'value', 'value2'</pre>
40
41 EOT
42         );
43     
44         Debug::printVar('Var0', null);
45         Debug::printVar('Var1', true);
46         Debug::printVar('Var2', false);
47         Debug::printVar('Var3', 0);
48         Debug::printVar('Var4', 'String');
49         Debug::printVar('Var5', array('one', 'two', 'three'));
50         Debug::printVar('Var6', array('key' => 'value', 'key2' => 'value2'));
51         Debug::printVar('Var7', $this->oWithToString);
52         Debug::printVar('Var8', Debug::fmtArrayVals(array('key' => 'value', 'key2' => 'value2')));
53     }
54
55
56     public function testDebugArray()
57     {
58         $this->expectOutputString(<<<EOT
59 <pre><b>Arr0:</b>  'null'</pre>
60 <pre><b>Arr1:</b>  'key1' => 'val1'
61        'key2' => 'val2'
62        'key3' => 'val3'</pre>
63
64 EOT
65         );
66     
67         Debug::printDebugArray('Arr0', null);
68         Debug::printDebugArray('Arr1', $this->oWithDebuginfo);
69     }
70
71
72     public function testPrintDebugTable()
73     {
74         $this->expectOutputString(<<<EOT
75 <b>Table1:</b>
76 <table border='1'>
77 </table>
78 <b>Table2:</b>
79 <table border='1'>
80 </table>
81 <b>Table3:</b>
82 <table border='1'>
83   <tr>
84     <th><small>0</small></th>
85     <th><small>1</small></th>
86   </tr>
87   <tr>
88     <td><pre>'one'</pre></td>
89     <td><pre>'two'</pre></td>
90   </tr>
91   <tr>
92     <td><pre>'three'</pre></td>
93     <td><pre>'four'</pre></td>
94   </tr>
95 </table>
96 <b>Table4:</b>
97 <table border='1'>
98   <tr>
99     <th><small>key1</small></th>
100     <th><small>key2</small></th>
101     <th><small>key3</small></th>
102   </tr>
103   <tr>
104     <td><pre>'val1'</pre></td>
105     <td><pre>'val2'</pre></td>
106     <td><pre>'val3'</pre></td>
107   </tr>
108 </table>
109
110 EOT
111         );
112     
113         Debug::printDebugTable('Table1', null);
114
115         Debug::printDebugTable('Table2', array());
116
117         // Numeric headers
118         Debug::printDebugTable('Table3', array(array('one', 'two'), array('three', 'four')));
119
120         // Associate array
121         Debug::printDebugTable('Table4', array($this->oWithDebuginfo));
122     }
123
124     public function testPrintGroupTable()
125     {
126         $this->expectOutputString(<<<EOT
127 <b>Table1:</b>
128 <table border='1'>
129 </table>
130 <b>Table2:</b>
131 <table border='1'>
132 </table>
133 <b>Table3:</b>
134 <table border='1'>
135   <tr>
136     <th><small>Group</small></th>
137     <th><small>key1</small></th>
138     <th><small>key2</small></th>
139   </tr>
140   <tr>
141     <td><pre>group1</pre></td>
142     <td><pre>'val1'</pre></td>
143     <td><pre>'val2'</pre></td>
144   </tr>
145   <tr>
146     <td><pre>group1</pre></td>
147     <td><pre>'one'</pre></td>
148     <td><pre>'two'</pre></td>
149   </tr>
150   <tr>
151     <td><pre>group2</pre></td>
152     <td><pre>'val1'</pre></td>
153     <td><pre>'val2'</pre></td>
154   </tr>
155 </table>
156 <b>Table4:</b>
157 <table border='1'>
158   <tr>
159     <th><small>Group</small></th>
160     <th><small>key1</small></th>
161     <th><small>key2</small></th>
162     <th><small>key3</small></th>
163   </tr>
164   <tr>
165     <td><pre>group1</pre></td>
166     <td><pre>'val1'</pre></td>
167     <td><pre>'val2'</pre></td>
168     <td><pre>'val3'</pre></td>
169   </tr>
170   <tr>
171     <td><pre>group1</pre></td>
172     <td><pre>'val1'</pre></td>
173     <td><pre>'val2'</pre></td>
174     <td><pre>'val3'</pre></td>
175   </tr>
176 </table>
177
178 EOT
179         );
180     
181         Debug::printGroupTable('Table1', null);
182         Debug::printGroupTable('Table2', array());
183
184         // header are taken from first group item, thus no key3 gets printed
185         $aGroups = array(
186                     'group1' => array(
187                                  array('key1' => 'val1', 'key2' => 'val2'),
188                                  array('key1' => 'one', 'key2' => 'two', 'unknown' => 1),
189                                 ),
190                     'group2' => array(
191                                  array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'),
192                                 )
193                    );
194         Debug::printGroupTable('Table3', $aGroups);
195
196         $aGroups = array(
197                     'group1' => array($this->oWithDebuginfo, $this->oWithDebuginfo),
198                    );
199         Debug::printGroupTable('Table4', $aGroups);
200     }
201 }