Skip to content

Commit af3222f

Browse files
committed
Add UserRoleSprunje tests
1 parent f1826ea commit af3222f

5 files changed

Lines changed: 37 additions & 6 deletions

File tree

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"XDEBUG_CONFIG": "idekey=VSCODE",
1212
}
1313
},
14-
"command": "printf '\\33c\\e[3J' && vendor/bin/phpunit",
14+
"command": "printf '\\33c\\e[3J' && vendor/bin/phpunit --stop-on-failure --stop-on-error",
1515
"problemMatcher": [],
1616
"group": {
1717
"kind": "build",

app/src/App.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace App\ExtendUser;
1212

1313
use App\ExtendUser\Database\Migrations\v400\MembersTable;
14+
use App\ExtendUser\ServicesProvider\MemberModelService;
1415
use UserFrosting\Sprinkle\Account\Account;
1516
use UserFrosting\Sprinkle\Admin\Admin;
1617
use UserFrosting\Sprinkle\Core\Core;
@@ -93,7 +94,7 @@ public function getRoutes(): array
9394
public function getServices(): array
9495
{
9596
return [
96-
Services::class,
97+
MemberModelService::class,
9798
];
9899
}
99100

app/src/Database/Models/MemberAux.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919
*/
2020
class MemberAux extends Model
2121
{
22+
/**
23+
* The table doesn't have timestamps columns
24+
*/
2225
public $timestamps = false;
2326

2427
/**
25-
* @var string The name of the table for the current model.
28+
* @var string The name of the table for the current model. We defined it,
29+
* because the table name is different than the model name
2630
*/
2731
protected $table = 'members';
2832

33+
/**
34+
* Define the fillable columns
35+
*/
2936
protected $fillable = [
3037
'city',
3138
'country',

app/src/Services.php renamed to app/src/ServicesProvider/MemberModelService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
* @license https://github.com/userfrosting/extend-user/blob/5.0/LICENSE.md (MIT License)
99
*/
1010

11-
namespace App\ExtendUser;
11+
namespace App\ExtendUser\ServicesProvider;
1212

1313
use App\ExtendUser\Controller\MemberPageAction;
1414
use App\ExtendUser\Database\Models\Member;
1515
use UserFrosting\ServicesProvider\ServicesProviderInterface;
1616
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
1717
use UserFrosting\Sprinkle\Admin\Controller\User\UserPageAction;
1818

19-
class Services implements ServicesProviderInterface
19+
class MemberModelService implements ServicesProviderInterface
2020
{
2121
public function register(): array
2222
{

app/tests/Controller/MemberPageActionTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function setUp(): void
3535
$this->refreshDatabase();
3636
}
3737

38+
/**
39+
* Make sure the Member doesn't create issue when editing a user
40+
*/
3841
public function testEditUser(): void
3942
{
4043
/** @var Member */
@@ -84,7 +87,7 @@ public function testEditUser(): void
8487
}
8588

8689
/**
87-
* Test index (`/users/u/{user_name}`) page.
90+
* Test `/users/u/{user_name}` page.
8891
*/
8992
public function testPage(): void
9093
{
@@ -108,6 +111,9 @@ public function testPage(): void
108111
$this->assertNotEmpty((string) $response->getBody());
109112
}
110113

114+
/**
115+
* Test `/users/u/{user_name}` page forbidden exception
116+
*/
111117
public function testPageForForbiddenException(): void
112118
{
113119
/** @var Member */
@@ -122,4 +128,21 @@ public function testPageForForbiddenException(): void
122128
$this->assertJsonResponse('Access Denied', $response, 'title');
123129
$this->assertResponseStatus(403, $response);
124130
}
131+
132+
/**
133+
* Test issue that arose when using the Member model with UserRoleSprunje
134+
*/
135+
public function testUserRoleSprunje(): void
136+
{
137+
/** @var Member */
138+
$user = Member::factory()->create();
139+
$this->actAsUser($user, isMaster: true);
140+
141+
// Create request with method and url and fetch response
142+
$request = $this->createJsonRequest('GET', "/api/users/u/{$user->user_name}/roles");
143+
$response = $this->handleRequest($request);
144+
145+
// Assert status & response is not empty
146+
$this->assertResponseStatus(200, $response);
147+
}
125148
}

0 commit comments

Comments
 (0)