]> BookStack Code Mirror - bookstack/blob - tests/Unit/FrameworkAssumptionTest.php
Merge pull request #4903 from BookStackApp/laravel10
[bookstack] / tests / Unit / FrameworkAssumptionTest.php
1 <?php
2
3 namespace Tests\Unit;
4
5 use BadMethodCallException;
6 use BookStack\Entities\Models\Page;
7 use Tests\TestCase;
8
9 /**
10  * This class tests assumptions we're relying upon in the framework.
11  * This is primarily to keep track of certain bits of functionality that
12  * may be used in important areas such as to enforce permissions.
13  */
14 class FrameworkAssumptionTest extends TestCase
15 {
16     public function test_scopes_error_if_not_existing()
17     {
18         $this->expectException(BadMethodCallException::class);
19         $this->expectExceptionMessage('Call to undefined method BookStack\Entities\Models\Page::scopeNotfoundscope()');
20         Page::query()->scopes('notfoundscope');
21     }
22
23     public function test_scopes_applies_upon_existing()
24     {
25         // Page has SoftDeletes trait by default, so we apply our custom scope and ensure
26         // it stacks on the global scope to filter out deleted items.
27         $query = Page::query()->scopes('visible')->toSql();
28         $this->assertStringContainsString('joint_permissions', $query);
29         $this->assertStringContainsString('`deleted_at` is null', $query);
30     }
31 }