1
|
|
|
<?php |
2
|
|
|
use PHPUnit\Framework\TestCase; |
3
|
|
|
|
4
|
|
|
class TableTest extends TestCase |
5
|
|
|
{ |
6
|
|
|
/*public function testProducerFirst() |
7
|
|
|
{ |
8
|
|
|
$this->assertTrue(true); |
9
|
|
|
//die(dirname(__DIR__)); |
10
|
|
|
return 'first'; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function testProducerSecond() |
14
|
|
|
{ |
15
|
|
|
$this->assertTrue(true); |
16
|
|
|
return 'second'; |
17
|
|
|
} |
18
|
|
|
*/ |
19
|
|
|
/** |
20
|
|
|
* @depends testProducerFirst |
21
|
|
|
* @depends testProducerSecond |
22
|
|
|
*/ |
23
|
|
|
/*public function testConsumer($a, $b) |
24
|
|
|
{ |
25
|
|
|
$this->assertSame('first', $a); |
26
|
|
|
$this->assertSame('second', $b); |
27
|
|
|
}*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @covers Table::prepare |
31
|
|
|
* @covers Table::confirmValue |
32
|
|
|
*/ |
33
|
|
|
public function testprepare(){ |
34
|
|
|
$_SERVER['REQUEST_URI'] = 'test.json'; |
35
|
|
|
|
36
|
|
|
//Table::prepare(true); |
37
|
|
|
|
38
|
|
|
Table::prepare(); |
39
|
|
|
$this->assertSame(Table::confirmValue('t.slug', 'test.json'), true); |
40
|
|
|
$this->assertSame(Table::$pageExt, 'json'); |
41
|
|
|
|
42
|
|
|
$_SERVER['REQUEST_URI'] = null; |
43
|
|
|
|
44
|
|
|
Table::prepare(); |
45
|
|
|
$this->assertSame(Table::confirmValue('t.slug', ''), true); |
46
|
|
|
$this->assertSame(Table::$pageExt, ''); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers Table::prepare |
51
|
|
|
* @covers Table::create |
52
|
|
|
* @covers Table::error |
53
|
|
|
* @covers Table::config |
54
|
|
|
*/ |
55
|
|
|
public function testcreate(){ |
56
|
|
|
$_SERVER['REQUEST_URI'] = 'test/users'; |
57
|
|
|
|
58
|
|
|
Table::prepare(); |
59
|
|
|
|
60
|
|
|
$this->assertSame(Table::confirmValue('t.page', 1), true); |
61
|
|
|
$this->assertSame(Table::confirmValue('t.tables', []), true); |
62
|
|
|
|
63
|
|
|
$items = 'users'; |
64
|
|
|
$orderBy = 'id'; |
65
|
|
|
|
66
|
|
|
Table::create($items, $orderBy, 'a'); |
67
|
|
|
$this->assertSame(Table::confirmValue('t.items', $items), true); |
68
|
|
|
$this->assertSame(Table::confirmValue('t.order.col', $orderBy), true); |
69
|
|
|
$err = Table::confirmValue('errors.0','Invalid orderDir (Asc/Desc): a'); |
70
|
|
|
$this->assertSame($err,true); |
71
|
|
|
|
72
|
|
|
Table::create($items, $orderBy, 'asc', 2); |
73
|
|
|
$this->assertSame(Table::confirmValue('t.items', $items), true); |
74
|
|
|
$this->assertSame(Table::confirmValue('t.order.col', $orderBy), true); |
75
|
|
|
$this->assertSame(Table::confirmValue('t.order.dir', 'asc'), true); |
76
|
|
|
$err1 = Table::confirmValue('errors.∞','Invalid paging (<10): 2'); |
77
|
|
|
$this->assertSame($err1, true); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @covers Table::execute |
82
|
|
|
* @covers Table::request |
83
|
|
|
* @covers Table::filter |
84
|
|
|
* @covers Table::filterByAll |
85
|
|
|
* @covers Table::orderCol |
86
|
|
|
* @covers Table::orderDir |
87
|
|
|
* @covers Table::setExport |
88
|
|
|
* @covers Table::page |
89
|
|
|
*/ |
90
|
|
|
public function testexecute() |
91
|
|
|
{ |
92
|
|
|
$_SERVER['REQUEST_URI'] = 'test/users'; |
93
|
|
|
|
94
|
|
|
Table::prepare(); |
95
|
|
|
|
96
|
|
|
$items = 'users'; |
97
|
|
|
$orderBy = 'id'; |
98
|
|
|
Table::create($items, $orderBy); |
99
|
|
|
|
100
|
|
|
$query = 'SELECT `id` FROM `table`'; |
101
|
|
|
Table::execute($query); |
102
|
|
|
$this->assertSame(Table::$export, false); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @covers Table::load |
107
|
|
|
* @covers Thead::load |
108
|
|
|
* @covers Thead::filterValues |
109
|
|
|
* @covers Thead::tagAttributes |
110
|
|
|
* @covers Thead::ths |
111
|
|
|
* @covers Thead::thAttributes |
112
|
|
|
* @covers Thead::thTag |
113
|
|
|
*/ |
114
|
|
|
public function testload() |
115
|
|
|
{ |
116
|
|
|
$_SERVER['REQUEST_URI'] = 'test/articles'; |
117
|
|
|
|
118
|
|
|
Table::prepare(); |
119
|
|
|
|
120
|
|
|
$items = 'articles'; |
121
|
|
|
$orderBy = 'id'; |
122
|
|
|
Table::create($items, $orderBy); |
123
|
|
|
Table::$cols = [['id']]; |
124
|
|
|
$query = 'SELECT `id` FROM `articles`'; |
125
|
|
|
Table::execute($query); |
126
|
|
|
|
127
|
|
|
Table::load(); |
128
|
|
|
$regex = '/(.*)$/m'; |
129
|
|
|
$this->expectOutputRegex($regex); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
static function prepare($classMethod, $setOrCheck = false){ |
|
|
|
|
134
|
|
|
self::$pageExtension = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_EXTENSION)?:null; |
135
|
|
|
$continuePreparation = $setOrCheck === false; |
136
|
|
|
if($setOrCheck === true){ |
137
|
|
|
if(!in_array($classMethod, self::$preparePassed) && empty(self::$pageExtension)){ |
138
|
|
|
die("ERROR (in a ".__CLASS__." call): Please call the ".$classMethod."(); method before the page headers sent."); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
} else if(!empty($setOrCheck)) { |
141
|
|
|
self::$pageExtension = $setOrCheck; |
142
|
|
|
} |
143
|
|
|
if(!in_array($classMethod, self::$preparePassed)){ |
144
|
|
|
self::$preparePassed[] = $classMethod; |
145
|
|
|
} |
146
|
|
|
return $continuePreparation; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
static $rustart, $pageExtension, $preparePassed = []; |
150
|
|
|
public function setUp(): void |
151
|
|
|
{ |
152
|
|
|
Table::$helperClass = __CLASS__; |
153
|
|
|
parent::setUp(); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.