forked from DataLinx/eclipsephp-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveScopeTest.php
More file actions
34 lines (25 loc) · 1.34 KB
/
Copy pathActiveScopeTest.php
File metadata and controls
34 lines (25 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use Eclipse\Common\Foundation\Models\Scopes\ActiveScope;
use Workbench\App\Models\Product;
test('active scope filters inactive records', function () {
Product::factory()->create(['name' => 'Active Product', 'is_active' => true]);
Product::factory()->create(['name' => 'Inactive Product', 'is_active' => false]);
expect(Product::count())->toBe(1)
->and(Product::first()->name)->toBe('Active Product');
});
test('active scope can be disabled with withoutGlobalScope', function () {
Product::factory()->create(['is_active' => true]);
Product::factory()->inactive()->create();
expect(Product::count())->toBe(1)
->and(Product::withoutGlobalScope(ActiveScope::class)->count())->toBe(2);
});
test('active scope only returns active records by default', function () {
$activeProduct = Product::factory()->create(['is_active' => true]);
$inactiveProduct = Product::factory()->inactive()->create();
expect(Product::where('id', $activeProduct->id)->count())->toBe(1)
->and(Product::where('id', $inactiveProduct->id)->count())->toBe(0);
});
test('active scope allows querying inactive records without scope', function () {
$inactiveProduct = Product::factory()->inactive()->create();
expect(Product::withoutGlobalScope(ActiveScope::class)->where('id', $inactiveProduct->id)->count())->toBe(1);
});