|
| 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