-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ElseAuth and ElseGuest Blade directives (#23569)
- Loading branch information
1 parent
ac0c717
commit d64e500
Showing
3 changed files
with
114 additions
and
0 deletions.
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,52 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Blade; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Illuminate\View\Compilers\BladeCompiler; | ||
|
||
class BladeElseAuthStatementsTest extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testElseAuthStatementsAreCompiled() | ||
{ | ||
$compiler = new BladeCompiler($this->getFiles(), __DIR__); | ||
$string = '@auth("api") | ||
breeze | ||
@elseauth("standard") | ||
wheeze | ||
@endauth'; | ||
$expected = '<?php if(auth()->guard("api")->check()): ?> | ||
breeze | ||
<?php elseif(auth()->guard("standard")->check()): ?> | ||
wheeze | ||
<?php endif; ?>'; | ||
$this->assertEquals($expected, $compiler->compileString($string)); | ||
} | ||
|
||
public function testPlainElseAuthStatementsAreCompiled() | ||
{ | ||
$compiler = new BladeCompiler($this->getFiles(), __DIR__); | ||
$string = '@auth("api") | ||
breeze | ||
@elseauth | ||
wheeze | ||
@endauth'; | ||
$expected = '<?php if(auth()->guard("api")->check()): ?> | ||
breeze | ||
<?php elseif(auth()->guard()->check()): ?> | ||
wheeze | ||
<?php endif; ?>'; | ||
$this->assertEquals($expected, $compiler->compileString($string)); | ||
} | ||
|
||
protected function getFiles() | ||
{ | ||
return m::mock('Illuminate\Filesystem\Filesystem'); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Blade; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Illuminate\View\Compilers\BladeCompiler; | ||
|
||
class BladeElseGuestStatementsTest extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testIfStatementsAreCompiled() | ||
{ | ||
$compiler = new BladeCompiler($this->getFiles(), __DIR__); | ||
$string = '@guest("api") | ||
breeze | ||
@elseguest("standard") | ||
wheeze | ||
@endguest'; | ||
$expected = '<?php if(auth()->guard("api")->guest()): ?> | ||
breeze | ||
<?php elseif(auth()->guard("standard")->guest()): ?> | ||
wheeze | ||
<?php endif; ?>'; | ||
$this->assertEquals($expected, $compiler->compileString($string)); | ||
} | ||
|
||
protected function getFiles() | ||
{ | ||
return m::mock('Illuminate\Filesystem\Filesystem'); | ||
} | ||
} |