]> BookStack Code Mirror - bookstack/blob - tests/Commands/ClearViewsCommandTest.php
Create additional test helper classes
[bookstack] / tests / Commands / ClearViewsCommandTest.php
1 <?php
2
3 namespace Tests\Commands;
4
5 use BookStack\Entities\Models\Page;
6 use Illuminate\Support\Facades\DB;
7 use Tests\TestCase;
8
9 class ClearViewsCommandTest extends TestCase
10 {
11     public function test_clear_views_command()
12     {
13         $this->asEditor();
14         $page = Page::first();
15
16         $this->get($page->getUrl());
17
18         $this->assertDatabaseHas('views', [
19             'user_id'     => $this->users->editor()->id,
20             'viewable_id' => $page->id,
21             'views'       => 1,
22         ]);
23
24         DB::rollBack();
25         $exitCode = \Artisan::call('bookstack:clear-views');
26         DB::beginTransaction();
27         $this->assertTrue($exitCode === 0, 'Command executed successfully');
28
29         $this->assertDatabaseMissing('views', [
30             'user_id' => $this->users->editor()->id,
31         ]);
32     }
33 }