-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add directive @bool to Blade #53179
Add directive @bool to Blade #53179
Changes from 1 commit
a07a477
012ec53
f1d4a86
d722388
f874756
f4800d6
8937669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\View\Blade; | ||
|
||
class BladeBoolTest extends AbstractBladeTestCase | ||
{ | ||
public function testBool() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably one of the few cases where an public function testCompileBool(): void
{
$someViewVarTruthy = 123;
$compiled = $this->compiler->compileString('@bool($someViewVarTruthy)');
ob_start();
eval(substr($compiled, 6, -3));
$this->assertEquals('true', ob_get_clean());
$someViewVarFalsey = '0';
$compiled = $this->compiler->compileString('@bool($someViewVarFalsey)');
ob_start();
eval(substr($compiled, 6, -3));
$this->assertEquals('false', ob_get_clean());
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it didn't consider a Falsey values, i added a Falsey support and a couple of test for NULL and Class instances. |
||
{ | ||
|
||
// For Javascript object{'isBool' : true} | ||
$string = "{'isBool' : @bool(true)}"; | ||
$expected = "{'isBool' : <?php if(true): echo 'true'; else: 'false'; endif; ?>}"; | ||
$this->assertEquals($expected, $this->compiler->compileString($string)); | ||
|
||
// For Javascript object{'isBool' : false} | ||
$string = "{'isBool' : @bool(false)}"; | ||
$expected = "{'isBool' : <?php if(false): echo 'true'; else: 'false'; endif; ?>}"; | ||
$this->assertEquals($expected, $this->compiler->compileString($string)); | ||
|
||
// For Alpine.js x-show attribute | ||
$string = "<input type='text' x-show='@bool(true)' />"; | ||
$expected = "<input type='text' x-show='<?php if(true): echo 'true'; else: 'false'; endif; ?>' />"; | ||
$this->assertEquals($expected, $this->compiler->compileString($string)); | ||
|
||
// For Alpine.js x-show attribute | ||
$string = "<input type='text' x-show='@bool(false)' />"; | ||
$expected = "<input type='text' x-show='<?php if(false): echo 'true'; else: 'false'; endif; ?>' />"; | ||
$this->assertEquals($expected, $this->compiler->compileString($string)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code doesn't print anything for the "false" path.