-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataTableTest.php
170 lines (136 loc) · 4.56 KB
/
DataTableTest.php
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Import the class that is needed in this bunch of testing.
*
*/
use app\controllers\dataTableTestController;
class DataTableTest extends TestCase {
/**
* Use a string to demostrate the life cycle of TestCase.
*
* At each stage, append an identified string to it.
*
* Print it at all thing is finished.(i.e. tearDownAfterClass())
*/
protected static $temp;
/**
* This method will be call before the entire test starting.
*
*/
public static function setUpBeforeClass(){
print_r(__METHOD__."\n");
DataTableTest::$temp="";
}
/**
* This method will be call after the entire test finishing.
*
*/
public static function tearDownAfterClass(){
print_r(DataTableTest::$temp."\n");
print_r(__METHOD__."\n");
}
/**
* This method will be call before each testing method starting.
*
* The method, $this->getName(), could retrieve the test method name,
* following by this setUp() invoking.
*
* NOTE: Be sure to call the 'parent::setUp()' at the beginning,
* There is something to do by laravel testunit.
*/
public function setUp(){
parent::setUp();
if($this->getName() == "testLoadDataTable"){
DataTableTest::$temp=DataTableTest::$temp."\ntestLoadDataTable_setUp ";
}else if($this->getName() == "testLoadDataTable2"){
DataTableTest::$temp=DataTableTest::$temp."\ntestLoadDataTable2_setUp ";
}else if($this->getName() == "testNextExamine"){
DataTableTest::$temp=DataTableTest::$temp."\ntestNextExamine_setUp ";
}
}
/**
* This method will be call after each testing method finishing.
*
* The method, $this->getName(), could retrieve the test method name,
* before this tearDown() invoking.
*
*/
public function tearDown(){
if($this->getName() == "testLoadDataTable"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable_tearDown ";
}else if($this->getName() == "testLoadDataTable2"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable2_tearDown ";
}else if($this->getName() == "testNextExamine"){
DataTableTest::$temp=DataTableTest::$temp."testNextExamine_tearDown ";
}
}
/**
* This method will be invoked after setUp().
*
*/
protected function assertPreConditions(){
if($this->getName() == "testLoadDataTable"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable_assertPre ";
}else if($this->getName() == "testLoadDataTable2"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable2_assertPre ";
}else if($this->getName() == "testNextExamine"){
DataTableTest::$temp=DataTableTest::$temp."testNextExamine_assertPre ";
}
}
/**
* This method will be invoked before tearDown().
*
* NOTE: If an error or an assertion faild, this method would not be called.
*/
protected function assertPostConditions(){
if($this->getName() == "testLoadDataTable"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable_assertPost ";
}else if($this->getName() == "testLoadDataTable2"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable2_assertPost ";
}else if($this->getName() == "testNextExamine"){
DataTableTest::$temp=DataTableTest::$temp."testNextExamine_assertPost ";
}
}
/**
* This method will be invoked after tearDown() when the testing is failed or an error.
*
*/
protected function onNotSuccessfulTest(Exception $e){
if($this->getName() == "testLoadDataTable"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable_NotSuccess ";
}else if($this->getName() == "testLoadDataTable2"){
DataTableTest::$temp=DataTableTest::$temp."testLoadDataTable2_NotSuccess ";
}else if($this->getName() == "testNextExamine"){
DataTableTest::$temp=DataTableTest::$temp."testNextExamine_NotSuccess ";
}
throw $e;
}
/**
* This test method will pass the testing.
*/
public function testLoadDataTable(){
DataTableTest::$temp=DataTableTest::$temp.__METHOD__." ";
$response = $this->call('GET', 'dataTableTest');
$this->assertTrue(true);
}
/**
* This test method will cause a testing error.
*/
public function testLoadDataTable2(){
DataTableTest::$temp=DataTableTest::$temp.__METHOD__." ";
$response = $this->call('GET','dataTableTest');
print_r($aa); // this line will cause an testing error, there is no variable $aa.
$this->assertResponseStatus(403);
}
/**
* This test method will cause a testing failure.
*/
public function testNextExamine(){
DataTableTest::$temp=DataTableTest::$temp.__METHOD__." ";
$response = $this->call('POST',
'api/v1/next',
array('id' => '6160020')
);
$this->assertEquals('15', $response->getContent());
}
}