Skip to content

Commit e56f5c2

Browse files
authored
Fix #951 - User Model forceDelete doesn't remove the record from the DB
1 parent ba33eb7 commit e56f5c2

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
- Italian translation ([#950])
1212
- User Registration failing when trying to register two accounts with the same email address ([#953])
1313
- Bad test case for `CoreController::getAsset`.
14+
- User Model `forceDelete` doesn't remove the record from the DB ([#951])
1415
- Fix PHP Fatal error that can be thrown when registering a new User
1516

1617
## [v4.2.0]
@@ -713,6 +714,7 @@ See [http://learn.userfrosting.com/upgrading/40-to-41](Upgrading 4.0.x to 4.1.x
713714
[#919]: https://github.com/userfrosting/UserFrosting/issues/919
714715
[#940]: https://github.com/userfrosting/UserFrosting/issues/940
715716
[#950]: https://github.com/userfrosting/UserFrosting/issues/950
717+
[#951]: https://github.com/userfrosting/UserFrosting/issues/951
716718
[#953]: https://github.com/userfrosting/UserFrosting/issues/953
717719

718720
[v4.2.0]: https://github.com/userfrosting/UserFrosting/compare/v4.1.22...v4.2.0

app/sprinkles/account/src/Database/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function delete($hardDelete = false)
198198
// TODO: remove any persistences
199199

200200
// Delete the user
201-
$result = parent::forceDelete();
201+
$result = $this->forceDelete();
202202
} else {
203203
// Soft delete the user, leaving all associated records alone
204204
$result = parent::delete();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* UserFrosting (http://www.userfrosting.com)
4+
*
5+
* @link https://github.com/userfrosting/UserFrosting
6+
* @copyright Copyright (c) 2019 Alexander Weissman
7+
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
8+
*/
9+
10+
namespace UserFrosting\Sprinkle\Account\Tests\Unit;
11+
12+
use UserFrosting\Sprinkle\Account\Database\Models\User;
13+
use UserFrosting\Sprinkle\Account\Tests\withTestUser;
14+
use UserFrosting\Sprinkle\Core\Tests\TestDatabase;
15+
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase;
16+
use UserFrosting\Tests\TestCase;
17+
18+
/**
19+
* UserModelTest Class
20+
* Tests the User Model.
21+
*/
22+
class UserModelTest extends TestCase
23+
{
24+
use TestDatabase;
25+
use RefreshDatabase;
26+
use withTestUser;
27+
28+
/**
29+
* Setup the database schema.
30+
*/
31+
public function setUp()
32+
{
33+
parent::setUp();
34+
35+
// Setup test database
36+
$this->setupTestDatabase();
37+
$this->refreshDatabase();
38+
}
39+
40+
/**
41+
* Test user soft deletion.
42+
*/
43+
public function testUserSoftDelete()
44+
{
45+
// Create a user & make sure it exist
46+
$user = $this->createTestUser();
47+
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));
48+
49+
// Soft Delete. User won't be found using normal query, but will withTrash
50+
$this->assertTrue($user->delete());
51+
$this->assertNull(User::find($user->id));
52+
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));
53+
}
54+
55+
/**
56+
* Test user hard deletion.
57+
*
58+
*/
59+
public function testUserHardDelete()
60+
{
61+
// Create a user & make sure it exist
62+
$user = $this->createTestUser();
63+
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));
64+
65+
// Force delete. Now user can't be found at all
66+
$this->assertTrue($user->delete(true));
67+
$this->assertNull(User::withTrashed()->find($user->id));
68+
}
69+
}

0 commit comments

Comments
 (0)