3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
13 require_once(CONST_LibDir.'/DebugHtml.php');
15 class DebugTest extends \PHPUnit\Framework\TestCase
18 protected function setUp(): void
20 $this->oWithDebuginfo = $this->getMockBuilder(\GeococdeMock::class)
21 ->setMethods(array('debugInfo'))
23 $this->oWithDebuginfo->method('debugInfo')
24 ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'));
27 $this->oWithToString = $this->getMockBuilder(\SomeMock::class)
28 ->setMethods(array('__toString'))
30 $this->oWithToString->method('__toString')->willReturn('me as string');
33 public function testPrintVar()
35 $this->expectOutputString(<<<EOT
36 <pre><b>Var0:</b> </pre>
37 <pre><b>Var1:</b> <i>True</i></pre>
38 <pre><b>Var2:</b> <i>False</i></pre>
39 <pre><b>Var3:</b> 0</pre>
40 <pre><b>Var4:</b> 'String'</pre>
41 <pre><b>Var5:</b> 0 => 'one'
44 <pre><b>Var6:</b> 'key' => 'value'
45 'key2' => 'value2'</pre>
46 <pre><b>Var7:</b> me as string</pre>
47 <pre><b>Var8:</b> 'value', 'value2'</pre>
52 Debug::printVar('Var0', null);
53 Debug::printVar('Var1', true);
54 Debug::printVar('Var2', false);
55 Debug::printVar('Var3', 0);
56 Debug::printVar('Var4', 'String');
57 Debug::printVar('Var5', array('one', 'two', 'three'));
58 Debug::printVar('Var6', array('key' => 'value', 'key2' => 'value2'));
59 Debug::printVar('Var7', $this->oWithToString);
60 Debug::printVar('Var8', Debug::fmtArrayVals(array('key' => 'value', 'key2' => 'value2')));
64 public function testDebugArray()
66 $this->expectOutputString(<<<EOT
67 <pre><b>Arr0:</b> 'null'</pre>
68 <pre><b>Arr1:</b> 'key1' => 'val1'
70 'key3' => 'val3'</pre>
75 Debug::printDebugArray('Arr0', null);
76 Debug::printDebugArray('Arr1', $this->oWithDebuginfo);
80 public function testPrintDebugTable()
82 $this->expectOutputString(<<<EOT
92 <th><small>0</small></th>
93 <th><small>1</small></th>
96 <td><pre>'one'</pre></td>
97 <td><pre>'two'</pre></td>
100 <td><pre>'three'</pre></td>
101 <td><pre>'four'</pre></td>
107 <th><small>key1</small></th>
108 <th><small>key2</small></th>
109 <th><small>key3</small></th>
112 <td><pre>'val1'</pre></td>
113 <td><pre>'val2'</pre></td>
114 <td><pre>'val3'</pre></td>
121 Debug::printDebugTable('Table1', null);
123 Debug::printDebugTable('Table2', array());
126 Debug::printDebugTable('Table3', array(array('one', 'two'), array('three', 'four')));
129 Debug::printDebugTable('Table4', array($this->oWithDebuginfo));
132 public function testPrintGroupTable()
134 $this->expectOutputString(<<<EOT
144 <th><small>Group</small></th>
145 <th><small>key1</small></th>
146 <th><small>key2</small></th>
149 <td><pre>group1</pre></td>
150 <td><pre>'val1'</pre></td>
151 <td><pre>'val2'</pre></td>
154 <td><pre>group1</pre></td>
155 <td><pre>'one'</pre></td>
156 <td><pre>'two'</pre></td>
159 <td><pre>group2</pre></td>
160 <td><pre>'val1'</pre></td>
161 <td><pre>'val2'</pre></td>
167 <th><small>Group</small></th>
168 <th><small>key1</small></th>
169 <th><small>key2</small></th>
170 <th><small>key3</small></th>
173 <td><pre>group1</pre></td>
174 <td><pre>'val1'</pre></td>
175 <td><pre>'val2'</pre></td>
176 <td><pre>'val3'</pre></td>
179 <td><pre>group1</pre></td>
180 <td><pre>'val1'</pre></td>
181 <td><pre>'val2'</pre></td>
182 <td><pre>'val3'</pre></td>
189 Debug::printGroupTable('Table1', null);
190 Debug::printGroupTable('Table2', array());
192 // header are taken from first group item, thus no key3 gets printed
195 array('key1' => 'val1', 'key2' => 'val2'),
196 array('key1' => 'one', 'key2' => 'two', 'unknown' => 1),
199 array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'),
202 Debug::printGroupTable('Table3', $aGroups);
205 'group1' => array($this->oWithDebuginfo, $this->oWithDebuginfo),
207 Debug::printGroupTable('Table4', $aGroups);