5 require_once(CONST_BasePath.'/lib/DebugHtml.php');
 
   7 class DebugTest extends \PHPUnit\Framework\TestCase
 
  10     protected function setUp(): void
 
  12         $this->oWithDebuginfo = $this->getMockBuilder(\GeococdeMock::class)
 
  13                                     ->setMethods(array('debugInfo'))
 
  15         $this->oWithDebuginfo->method('debugInfo')
 
  16                   ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'));
 
  19         $this->oWithToString = $this->getMockBuilder(\SomeMock::class)
 
  20                                     ->setMethods(array('__toString'))
 
  22         $this->oWithToString->method('__toString')->willReturn('me as string');
 
  25     public function testPrintVar()
 
  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'
 
  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>
 
  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')));
 
  56     public function testDebugArray()
 
  58         $this->expectOutputString(<<<EOT
 
  59 <pre><b>Arr0:</b>  'null'</pre>
 
  60 <pre><b>Arr1:</b>  'key1' => 'val1'
 
  62        'key3' => 'val3'</pre>
 
  67         Debug::printDebugArray('Arr0', null);
 
  68         Debug::printDebugArray('Arr1', $this->oWithDebuginfo);
 
  72     public function testPrintDebugTable()
 
  74         $this->expectOutputString(<<<EOT
 
  84     <th><small>0</small></th>
 
  85     <th><small>1</small></th>
 
  88     <td><pre>'one'</pre></td>
 
  89     <td><pre>'two'</pre></td>
 
  92     <td><pre>'three'</pre></td>
 
  93     <td><pre>'four'</pre></td>
 
  99     <th><small>key1</small></th>
 
 100     <th><small>key2</small></th>
 
 101     <th><small>key3</small></th>
 
 104     <td><pre>'val1'</pre></td>
 
 105     <td><pre>'val2'</pre></td>
 
 106     <td><pre>'val3'</pre></td>
 
 113         Debug::printDebugTable('Table1', null);
 
 115         Debug::printDebugTable('Table2', array());
 
 118         Debug::printDebugTable('Table3', array(array('one', 'two'), array('three', 'four')));
 
 121         Debug::printDebugTable('Table4', array($this->oWithDebuginfo));
 
 124     public function testPrintGroupTable()
 
 126         $this->expectOutputString(<<<EOT
 
 136     <th><small>Group</small></th>
 
 137     <th><small>key1</small></th>
 
 138     <th><small>key2</small></th>
 
 141     <td><pre>group1</pre></td>
 
 142     <td><pre>'val1'</pre></td>
 
 143     <td><pre>'val2'</pre></td>
 
 146     <td><pre>group1</pre></td>
 
 147     <td><pre>'one'</pre></td>
 
 148     <td><pre>'two'</pre></td>
 
 151     <td><pre>group2</pre></td>
 
 152     <td><pre>'val1'</pre></td>
 
 153     <td><pre>'val2'</pre></td>
 
 159     <th><small>Group</small></th>
 
 160     <th><small>key1</small></th>
 
 161     <th><small>key2</small></th>
 
 162     <th><small>key3</small></th>
 
 165     <td><pre>group1</pre></td>
 
 166     <td><pre>'val1'</pre></td>
 
 167     <td><pre>'val2'</pre></td>
 
 168     <td><pre>'val3'</pre></td>
 
 171     <td><pre>group1</pre></td>
 
 172     <td><pre>'val1'</pre></td>
 
 173     <td><pre>'val2'</pre></td>
 
 174     <td><pre>'val3'</pre></td>
 
 181         Debug::printGroupTable('Table1', null);
 
 182         Debug::printGroupTable('Table2', array());
 
 184         // header are taken from first group item, thus no key3 gets printed
 
 187                                  array('key1' => 'val1', 'key2' => 'val2'),
 
 188                                  array('key1' => 'one', 'key2' => 'two', 'unknown' => 1),
 
 191                                  array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'),
 
 194         Debug::printGroupTable('Table3', $aGroups);
 
 197                     'group1' => array($this->oWithDebuginfo, $this->oWithDebuginfo),
 
 199         Debug::printGroupTable('Table4', $aGroups);