Skip to content

Commit

Permalink
Fix #951 - User Model forceDelete doesn't remove the record from the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette authored Apr 9, 2019
1 parent ba33eb7 commit e56f5c2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Italian translation ([#950])
- User Registration failing when trying to register two accounts with the same email address ([#953])
- Bad test case for `CoreController::getAsset`.
- User Model `forceDelete` doesn't remove the record from the DB ([#951])
- Fix PHP Fatal error that can be thrown when registering a new User

## [v4.2.0]
Expand Down Expand Up @@ -713,6 +714,7 @@ See [http://learn.userfrosting.com/upgrading/40-to-41](Upgrading 4.0.x to 4.1.x
[#919]: https://github.com/userfrosting/UserFrosting/issues/919
[#940]: https://github.com/userfrosting/UserFrosting/issues/940
[#950]: https://github.com/userfrosting/UserFrosting/issues/950
[#951]: https://github.com/userfrosting/UserFrosting/issues/951
[#953]: https://github.com/userfrosting/UserFrosting/issues/953

[v4.2.0]: https://github.com/userfrosting/UserFrosting/compare/v4.1.22...v4.2.0
Expand Down
2 changes: 1 addition & 1 deletion app/sprinkles/account/src/Database/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function delete($hardDelete = false)
// TODO: remove any persistences

// Delete the user
$result = parent::forceDelete();
$result = $this->forceDelete();
} else {
// Soft delete the user, leaving all associated records alone
$result = parent::delete();
Expand Down
69 changes: 69 additions & 0 deletions app/sprinkles/account/tests/Unit/UserModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2019 Alexander Weissman
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Sprinkle\Account\Tests\Unit;

use UserFrosting\Sprinkle\Account\Database\Models\User;
use UserFrosting\Sprinkle\Account\Tests\withTestUser;
use UserFrosting\Sprinkle\Core\Tests\TestDatabase;
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase;
use UserFrosting\Tests\TestCase;

/**
* UserModelTest Class
* Tests the User Model.
*/
class UserModelTest extends TestCase
{
use TestDatabase;
use RefreshDatabase;
use withTestUser;

/**
* Setup the database schema.
*/
public function setUp()
{
parent::setUp();

// Setup test database
$this->setupTestDatabase();
$this->refreshDatabase();
}

/**
* Test user soft deletion.
*/
public function testUserSoftDelete()
{
// Create a user & make sure it exist
$user = $this->createTestUser();
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));

// Soft Delete. User won't be found using normal query, but will withTrash
$this->assertTrue($user->delete());
$this->assertNull(User::find($user->id));
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));
}

/**
* Test user hard deletion.
*
*/
public function testUserHardDelete()
{
// Create a user & make sure it exist
$user = $this->createTestUser();
$this->assertInstanceOf(User::class, User::withTrashed()->find($user->id));

// Force delete. Now user can't be found at all
$this->assertTrue($user->delete(true));
$this->assertNull(User::withTrashed()->find($user->id));
}
}

0 comments on commit e56f5c2

Please sign in to comment.