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