|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace codecept\configuration; |
|
4
|
|
|
|
|
5
|
|
|
use codecept\ApiTester; |
|
6
|
|
|
use Codeception\Util\HttpCode; |
|
7
|
|
|
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration; |
|
8
|
|
|
use SlayerBirden\DataFlowServer\Domain\Entities\User; |
|
9
|
|
|
|
|
10
|
|
|
class DeleteConfigCest |
|
11
|
|
|
{ |
|
12
|
|
|
public function _before(ApiTester $I) |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => 1]); |
|
15
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
|
16
|
|
|
'owner' => $user, |
|
17
|
|
|
'title' => 'Test config', |
|
18
|
|
|
'url' => 'sqlite:///data/db/db.sqlite', |
|
19
|
|
|
]); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function deleteConfiguration(ApiTester $I) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$I->wantTo('delete db configuration'); |
|
25
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
26
|
|
|
$I->sendDELETE('/config/1'); |
|
27
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
|
28
|
|
|
$I->seeResponseContainsJson([ |
|
29
|
|
|
'success' => true, |
|
30
|
|
|
'data' => [ |
|
31
|
|
|
'configuration' => [ |
|
32
|
|
|
'title' => 'Test config', |
|
33
|
|
|
] |
|
34
|
|
|
] |
|
35
|
|
|
]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function deleteNonExistingConfiguration(ApiTester $I) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$I->wantTo('delete non-existing db configuration'); |
|
41
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
42
|
|
|
$I->sendDELETE('/config/0'); |
|
43
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
|
44
|
|
|
$I->seeResponseContainsJson([ |
|
45
|
|
|
'success' => false, |
|
46
|
|
|
'data' => [ |
|
47
|
|
|
'configuration' => null |
|
48
|
|
|
] |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function deleteSomeoneElsesConfiguration(ApiTester $I) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$userId = $I->haveInRepository(User::class, [ |
|
55
|
|
|
'first' => 'Tester2', |
|
56
|
|
|
'last' => 'Tester2', |
|
57
|
|
|
'email' => '[email protected]', |
|
58
|
|
|
]); |
|
59
|
|
|
$user = $I->grabEntityFromRepository(User::class, ['id' => $userId]); |
|
60
|
|
|
$I->haveInRepository(DbConfiguration::class, [ |
|
61
|
|
|
'owner' => $user, |
|
62
|
|
|
'title' => 'Test config 2', |
|
63
|
|
|
'url' => 'sqlite:///data/db/db2.sqlite', |
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
|
|
$I->wantTo('delete someone elses db configuration'); |
|
67
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
|
68
|
|
|
$I->sendDELETE('/config/2'); |
|
69
|
|
|
$I->seeResponseCodeIs(HttpCode::FORBIDDEN); |
|
70
|
|
|
$I->seeResponseContainsJson([ |
|
71
|
|
|
'success' => false, |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.