Newer
Older
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
<?php
namespace MaarchTest;
use PHPUnit\Framework\TestCase;
class PriorityControllerTest extends TestCase
{
private static $id = null;
public function testCreate()
{
$priorityController = new \Core\Controllers\PriorityController();
// CREATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'label' => 'TEST-OVER-URGENT',
'color' => '#ffffff',
'working_days' => true,
'delays' => '2'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $priorityController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->priority;
$this->assertInternalType('string', self::$id);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(self::$id, $responseBody->priority->id);
$this->assertSame('TEST-OVER-URGENT', $responseBody->priority->label);
$this->assertSame('#ffffff', $responseBody->priority->color);
$this->assertSame(true, $responseBody->priority->working_days);
$this->assertSame(2, $responseBody->priority->delays);
}
public function testGet()
{
$priorityController = new \Core\Controllers\PriorityController();
// GET
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $priorityController->get($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertInternalType('array', $responseBody->priorities);
$this->assertNotNull($responseBody->priorities);
}
public function testUpdate()
{
$priorityController = new \Core\Controllers\PriorityController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'label' => 'TEST-OVER-URGENT-UPDATED',
'color' => '#f2f2f2',
'working_days' => false,
'delays' => '4'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $priorityController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(_UPDATED_PRIORITY, $responseBody->success);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(self::$id, $responseBody->priority->id);
$this->assertSame('TEST-OVER-URGENT-UPDATED', $responseBody->priority->label);
$this->assertSame('#f2f2f2', $responseBody->priority->color);
$this->assertSame(false, $responseBody->priority->working_days);
$this->assertSame(4, $responseBody->priority->delays);
}
public function testDelete()
{
$priorityController = new \Core\Controllers\PriorityController();
// DELETE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'DELETE']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $priorityController->delete($request, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(_DELETED_PRIORITY, $responseBody->success);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $priorityController->getById($request, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Priority not found', $responseBody->errors);
}
}