-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathProductPageTest.php
More file actions
87 lines (73 loc) · 2.28 KB
/
ProductPageTest.php
File metadata and controls
87 lines (73 loc) · 2.28 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Tests\Feature;
use App\Models\Product;
use App\Models\ProductLicense;
use App\Models\ProductPrice;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ProductPageTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function masterclass_product_page_redirects_to_course(): void
{
$product = Product::where('slug', 'nativephp-masterclass')->first();
$this
->get(route('products.show', $product))
->assertRedirect(route('course'));
}
#[Test]
public function non_masterclass_product_page_loads_normally(): void
{
$product = Product::factory()->active()->create([
'slug' => 'plugin-dev-kit',
]);
ProductPrice::factory()->for($product)->create();
$this
->withoutVite()
->get(route('products.show', $product))
->assertStatus(200)
->assertSee($product->name);
}
#[Test]
public function course_page_shows_purchase_form_for_guests(): void
{
$this
->withoutVite()
->get(route('course'))
->assertStatus(200)
->assertSee('Get Early Bird Access')
->assertDontSee('You Own This Course');
}
#[Test]
public function course_page_shows_purchase_form_for_users_without_purchase(): void
{
$user = User::factory()->create();
$this
->withoutVite()
->actingAs($user)
->get(route('course'))
->assertStatus(200)
->assertSee('Get Early Bird Access')
->assertDontSee('You Own This Course');
}
#[Test]
public function course_page_shows_owned_state_for_purchasers(): void
{
$user = User::factory()->create();
$product = Product::where('slug', 'nativephp-masterclass')->first();
ProductLicense::factory()->create([
'user_id' => $user->id,
'product_id' => $product->id,
]);
$this
->withoutVite()
->actingAs($user)
->get(route('course'))
->assertStatus(200)
->assertSee('You Own This Course')
->assertDontSee('Get Early Bird Access');
}
}