|
4 | 4 |
|
5 | 5 | use Exception;
|
6 | 6 | use PHPUnit\Framework\TestCase;
|
| 7 | +use Illuminate\Database\Eloquent\SoftDeletes; |
7 | 8 | use Illuminate\Database\Capsule\Manager as DB;
|
8 | 9 | use Illuminate\Database\Eloquent\Relations\Pivot;
|
| 10 | +use Illuminate\Database\Eloquent\SoftDeletingScope; |
9 | 11 | use Illuminate\Database\Eloquent\Model as Eloquent;
|
10 | 12 | use Illuminate\Database\Eloquent\Relations\Relation;
|
11 | 13 | use Illuminate\Pagination\AbstractPaginator as Paginator;
|
@@ -90,6 +92,14 @@ protected function createSchema()
|
90 | 92 | $table->string('name');
|
91 | 93 | $table->timestamps();
|
92 | 94 | });
|
| 95 | + |
| 96 | + $this->schema($connection)->create('soft_deleted_users', function ($table) { |
| 97 | + $table->increments('id'); |
| 98 | + $table->string('name')->nullable(); |
| 99 | + $table->string('email'); |
| 100 | + $table->timestamps(); |
| 101 | + $table->softDeletes(); |
| 102 | + }); |
93 | 103 | }
|
94 | 104 |
|
95 | 105 | $this->schema($connection)->create('non_incrementing_users', function ($table) {
|
@@ -1012,6 +1022,14 @@ public function testModelIgnoredByGlobalScopeCanBeRefreshed()
|
1012 | 1022 | $this->assertNotNull($user->fresh());
|
1013 | 1023 | }
|
1014 | 1024 |
|
| 1025 | + public function testGlobalScopeCanBeRemovedByOtherGlobalScope() |
| 1026 | + { |
| 1027 | + $user = EloquentTestUserWithGlobalScopeRemovingOtherScope:: create([ 'id' => 1, 'email' => '[email protected]']); |
| 1028 | + $user->delete(); |
| 1029 | + |
| 1030 | + $this->assertNotNull(EloquentTestUserWithGlobalScopeRemovingOtherScope::find($user->id)); |
| 1031 | + } |
| 1032 | + |
1015 | 1033 | public function testForPageAfterIdCorrectlyPaginates()
|
1016 | 1034 | {
|
1017 | 1035 | EloquentTestUser:: create([ 'id' => 1, 'email' => '[email protected]']);
|
@@ -1224,6 +1242,24 @@ public static function boot()
|
1224 | 1242 | }
|
1225 | 1243 | }
|
1226 | 1244 |
|
| 1245 | +class EloquentTestUserWithGlobalScopeRemovingOtherScope extends Eloquent |
| 1246 | +{ |
| 1247 | + use SoftDeletes; |
| 1248 | + |
| 1249 | + protected $table = 'soft_deleted_users'; |
| 1250 | + |
| 1251 | + protected $guarded = []; |
| 1252 | + |
| 1253 | + public static function boot() |
| 1254 | + { |
| 1255 | + static::addGlobalScope(function ($builder) { |
| 1256 | + $builder->withoutGlobalScope(SoftDeletingScope::class); |
| 1257 | + }); |
| 1258 | + |
| 1259 | + parent::boot(); |
| 1260 | + } |
| 1261 | +} |
| 1262 | + |
1227 | 1263 | class EloquentTestPost extends Eloquent
|
1228 | 1264 | {
|
1229 | 1265 | protected $table = 'posts';
|
|
0 commit comments