1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Unit\DataTable\Renderer;
use Piwik\DataTable\Manager;
use Piwik\DataTable;
use Piwik\DataTable\Renderer\Console;
use Piwik\DataTable\Row;
/**
* @group DataTableTest
*/
class DataTable_Renderer_ConsoleTest extends \PHPUnit\Framework\TestCase
{
public function setUp(): void
{
parent::setUp();
Manager::getInstance()->deleteAll();
}
/**
* test with a row without child
* a row with a child that has a child
* a row with w child
*
* @group Core
*/
public function testConsole2SubLevelAnd2Different()
{
$table = new DataTable;
$table->addRowFromArray(array(Row::COLUMNS => array('visits' => 245, 'visitors' => 245),
Row::METADATA => array('logo' => 'test.png'),)
);
$subsubtable = new DataTable;
$idsubsubtable = $subsubtable->getId();
$subsubtable->addRowFromArray(array(Row::COLUMNS => array('visits' => 2)));
$subtable = new DataTable;
$idsubtable1 = $subtable->getId();
$subtable->addRowFromArray(array(Row::COLUMNS => array('visits' => 1),
Row::DATATABLE_ASSOCIATED => $subsubtable));
$table->addRowFromArray(array(Row::COLUMNS => array('visits' => 3),
Row::DATATABLE_ASSOCIATED => $subtable)
);
$subtable2 = new DataTable;
$idsubtable2 = $subtable2->getId();
$subtable2->addRowFromArray(array(Row::COLUMNS => array('visits' => 5),));
$table->addRowFromArray(array(Row::COLUMNS => array('visits' => 9),
Row::DATATABLE_ASSOCIATED => $subtable2)
);
$expected = "- 1 ['visits' => 245, 'visitors' => 245] ['logo' => 'test.png'] [idsubtable = ]<br />\n- 2 ['visits' => 3] [] [idsubtable = $idsubtable1]<br />\n*- 1 ['visits' => 1] [] [idsubtable = $idsubsubtable]<br />\n**- 1 ['visits' => 2] [] [idsubtable = ]<br />\n- 3 ['visits' => 9] [] [idsubtable = $idsubtable2]<br />\n*- 1 ['visits' => 5] [] [idsubtable = ]<br />\n";
$render = new Console();
$render->setTable($table);
$render->setPrefixRow('*');
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
}
/**
* test with a row without child
*
* @group Core
*/
public function testConsoleSimple()
{
$table = new DataTable;
$table->addRowFromArray(array(Row::COLUMNS => array('visits' => 245, 'visitors' => 245),
Row::METADATA => array('logo' => 'test.png'),)
);
$expected = "- 1 ['visits' => 245, 'visitors' => 245] ['logo' => 'test.png'] [idsubtable = ]<br />\n";
$render = new Console();
$render->setTable($table);
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
}
public function testRenderArray1()
{
$data = array();
$render = new Console();
$render->setTable($data);
$expected = 'Empty table<br />
';
$this->assertEquals($expected, $render->render());
}
public function testRenderArray2()
{
$data = array('a', 'b', 'c');
$render = new Console();
$render->setTable($data);
$expected = "- 1 ['0' => 'a'] [] [idsubtable = ]<br />
- 2 ['0' => 'b'] [] [idsubtable = ]<br />
- 3 ['0' => 'c'] [] [idsubtable = ]<br />
";
$this->assertEquals($expected, $render->render());
}
public function testRenderArray3()
{
$data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
$render = new Console();
$render->setTable($data);
$expected = "- 1 ['a' => 'b', 'c' => 'd', 'e' => 'f', '5' => 'g'] [] [idsubtable = ]<br />
";
$this->assertEquals($expected, $render->render());
}
public function testRenderArray4()
{
$data = array('a' => 'b');
$render = new Console();
$render->setTable($data);
$expected = "- 1 ['0' => 'b'] [] [idsubtable = ]<br />
";
$this->assertEquals($expected, $render->render());
}
}
|