-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathContentTest.php
56 lines (42 loc) · 1.5 KB
/
ContentTest.php
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
<?php
namespace Tests\Unit\Models;
use App\Models\Content;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ContentTest extends TestCase
{
use RefreshDatabase;
public function test_content_can_create_version()
{
$user = User::factory()->create();
$content = Content::factory()->create([
'author_id' => $user->id,
]);
$this->assertCount(0, $content->versions);
$content->createVersion();
$this->assertCount(1, $content->fresh()->versions);
}
public function test_content_can_rollback_to_version()
{
$user = User::factory()->create();
$content = Content::factory()->create([
'author_id' => $user->id,
'title' => 'Original Title',
'body' => 'Original Body',
]);
$content->createVersion();
$content->update([
'title' => 'Updated Title',
'body' => 'Updated Body',
]);
$content->createVersion();
$this->assertEquals('Updated Title', $content->fresh()->title);
$this->assertEquals('Updated Body', $content->fresh()->body);
$oldVersion = $content->versions()->orderBy('version_number')->first();
$content->rollbackToVersion($oldVersion);
$this->assertEquals('Original Title', $content->fresh()->title);
$this->assertEquals('Original Body', $content->fresh()->body);
$this->assertCount(3, $content->fresh()->versions);
}
}