-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1886 from pboivin/fix/3x-legacy-nav-items
[3.x] fix: Hide nav item if user is not authorized (legacy config)
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace A17\Twill\Tests\Integration\Navigation; | ||
|
||
use A17\Twill\Facades\TwillNavigation; | ||
use A17\Twill\Tests\Integration\TestCase; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class LegacyNavigationTest extends TestCase | ||
{ | ||
public function testNavItemIsNotVisibleIfNotAuthorized(): void | ||
{ | ||
config()->set('twill-navigation', [ | ||
'pages' => [ | ||
'module' => true, | ||
'can' => 'see-nav-item', | ||
] | ||
]); | ||
|
||
$this->login(); | ||
|
||
$navigation = TwillNavigation::buildNavigationTree(); | ||
|
||
$this->assertFalse(Auth::user()->can('see-nav-item')); | ||
$this->assertEmpty($navigation['left']); | ||
} | ||
|
||
public function testNavItemIsVisibleIfAuthorized(): void | ||
{ | ||
config()->set('twill-navigation', [ | ||
'pages' => [ | ||
'module' => true, | ||
'can' => 'see-nav-item', | ||
] | ||
]); | ||
|
||
Gate::define('see-nav-item', function () { | ||
return true; | ||
}); | ||
|
||
$this->login(); | ||
|
||
$navigation = TwillNavigation::buildNavigationTree(); | ||
|
||
$this->assertTrue(Auth::user()->can('see-nav-item')); | ||
$this->assertNotEmpty($navigation['left']); | ||
$this->assertEquals('Pages', $navigation['left'][0]->getTitle()); | ||
} | ||
} |