-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #951 - User Model forceDelete doesn't remove the record from the DB
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |