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