Newer
Older
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
namespace MaarchTest;
use PHPUnit\Framework\TestCase;
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
{
public function testPrepareStorage()
{
$action = new \Core\Controllers\ResController();
$data = [];
array_push(
$data,
array(
'column' => 'custom_t1',
'value' => 'TEST',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'custom_t10',
'value' => 'lgi@maarch.org',
'type' => 'string',
)
);
$aArgs = [
'data' => $data,
'docserverId' => 'FASTHD_MAN',
'status' => 'new',
'fileFormat' => 'pdf',
];
$response = $action->prepareStorage($aArgs);
$this->assertArrayHasKey('column', $response[0]);
}
public function testStoreResource()
{
$action = new \Core\Controllers\ResController();
$path = $_SESSION['config']['tmppath'] . '/test/';
if (!is_dir($path)) {
if (file_exists($path . $fileSource)) {
unlink($path . $fileSource);
}
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
$fp = fopen($path . $fileSource, 'a');
fwrite($fp, 'a unit test');
fclose($fp);
$fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
$encodedFile = base64_encode($fileContent);
$data = [];
array_push(
$data,
array(
'column' => 'subject',
'value' => 'UNIT TEST',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'type_id',
'value' => 110,
'type' => 'integer',
)
);
array_push(
$data,
array(
'column' => 'custom_t1',
'value' => 'TEST',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'custom_t10',
'value' => 'lgi@maarch.org',
'type' => 'string',
)
);
$aArgs = [
'encodedFile' => $encodedFile,
'data' => $data,
'collId' => 'letterbox_coll',
'table' => 'res_letterbox',
'fileFormat' => 'txt',
'status' => 'new',
];
$response = $action->storeResource($aArgs);
$this->assertGreaterThanOrEqual(0, $response[0]);
public function testDelete()
{
$action = new \Core\Controllers\ResController();
$environment = \Slim\Http\Environment::mock(
[
'REQUEST_METHOD' => 'DELETE',
]
);
$resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
$aArgs = [
'id'=> $resId[0]['res_id']
];
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = new \Slim\Http\Response();
$response = $action->delete($request, $response, $aArgs);
$this->assertSame((string)$response->getBody(), '[true]');
}
public function testCreate()
{
$action = new \Core\Controllers\ResController();
$environment = \Slim\Http\Environment::mock(
[
'REQUEST_METHOD' => 'POST',
]
);
$path = $_SESSION['config']['tmppath'] . '/test/';
if (!is_dir($path)) {
}
$fileSource = 'test_source.txt';
if (file_exists($path . $fileSource)) {
unlink($path . $fileSource);
}
$fp = fopen($path . $fileSource, 'a');
fwrite($fp, 'a unit test');
fclose($fp);
$fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
$encodedFile = base64_encode($fileContent);
//echo $encodedFile . PHP_EOL;exit;
$data = [];
array_push(
$data,
array(
'column' => 'subject',
'value' => 'UNIT TEST from slim',
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'type_id',
'value' => 110,
'type' => 'integer',
)
);
array_push(
$data,
array(
'column' => 'custom_t1',
'value' => 'TEST',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'custom_t10',
'value' => 'lgi@maarch.org',
'type' => 'string',
)
);
//print_r(json_encode($data));
//sample in json : [{"column":"subject","value":"UNIT T
//EST from slim","type":"string"},{"column":"type_id","value":110,"type":"integer"},
//{"column":"custom_t1","value":"TES
//T","type":"string"},{"column":"custom_t10","value":"lgi@maarch.org","type":"string"}]
$aArgs = [
'encodedFile' => $encodedFile,
'data' => $data,
'collId' => 'letterbox_coll',
'table' => 'res_letterbox',
'fileFormat' => 'txt',
'status' => 'new',
];
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = new \Slim\Http\Response();
$response = $action->create($request, $response, $aArgs);
$this->assertGreaterThan(1, json_decode($response->getBody())->resId);
{
$action = new \Core\Controllers\ResController();
$resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
];
$response = $action->deleteRes($aArgs);
$this->assertTrue($response);
public function testUpdate()
{
$action = new \Core\Controllers\ResController();
$environment = \Slim\Http\Environment::mock(
[
'REQUEST_METHOD' => 'POST',
]
);
$data = [];
array_push(
$data,
array(
'column' => 'status',
'value' => 'NEW',
'type' => 'string',
)
);
$resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
$aArgs = [
'table' => 'res_letterbox',
'res_id' => $resId[0]['res_id'],
'data' => $data,
];
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = new \Slim\Http\Response();
$response = $action->update($request, $response, $aArgs);
//print_r(json_decode($response->getBody())[0]->res_id);exit;
$this->assertGreaterThan(1, json_decode($response->getBody())[0]->res_id);
}
public function testUpdateResource()
{
$action = new \Core\Controllers\ResController();
$data = [];
array_push(
$data,
array(
'column' => 'status',
'value' => 'NEW',
'type' => 'string',
)
);
$resId = \Core\Models\ResModel::getLastId(['select' => ['res_id']]);
$aArgs = [
'table' => 'res_letterbox',
'res_id' => $resId[0]['res_id'],
'data' => $data,
];
$response = $action->updateResource($aArgs);
//print_r($response);exit;
$this->assertGreaterThan(1, $response);
}