assertSame(' ', $this->compiler->compileString("@if(\$test) @endif")); } public function testMixingYieldAndEcho() { $this->assertSame('yieldContent(\'title\'); ?> - ', $this->compiler->compileString("@yield('title') - {{Config::get('site.title')}}")); } public function testCustomExtensionsAreCompiled() { $this->compiler->extend(function ($value) { return str_replace('foo', 'bar', $value); }); $this->assertSame('bar', $this->compiler->compileString('foo')); } public function testCustomStatements() { $this->assertCount(0, $this->compiler->getCustomDirectives()); $this->compiler->directive('customControl', function ($expression) { return ""; }); $this->assertCount(1, $this->compiler->getCustomDirectives()); $string = '@if($foo) @customControl(10, $foo, \'bar\') @endif'; $expected = ' '; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomShortStatements() { $this->compiler->directive('customControl', function ($expression) { return ''; }); $string = '@customControl'; $expected = ''; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testValidCustomNames() { $this->assertNull($this->compiler->directive('custom', function () { // })); $this->assertNull($this->compiler->directive('custom_custom', function () { // })); $this->assertNull($this->compiler->directive('customCustom', function () { // })); $this->assertNull($this->compiler->directive('custom::custom', function () { // })); } public function testInvalidCustomNames() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The directive name [custom-custom] is not valid.'); $this->compiler->directive('custom-custom', function () { // }); } public function testInvalidCustomNames2() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The directive name [custom:custom] is not valid.'); $this->compiler->directive('custom:custom', function () { // }); } public function testCustomExtensionOverwritesCore() { $this->compiler->directive('foreach', function ($expression) { return ''; }); $string = '@foreach'; $expected = ''; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomConditions() { $this->compiler->if('custom', function ($user) { return true; }); $string = '@custom($user) @endcustom'; $expected = ' '; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomIfElseConditions() { $this->compiler->if('custom', function ($anything) { return true; }); $string = '@custom($user) @elsecustom($product) @else @endcustom'; $expected = ' '; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomUnlessConditions() { $this->compiler->if('custom', function ($anything) { return true; }); $string = '@unlesscustom($user) @endcustom'; $expected = ' '; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomConditionsAccepts0AsArgument() { $this->compiler->if('custom', function ($number) { return true; }); $string = '@custom(0) @elsecustom(0) @endcustom'; $expected = ' '; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomComponents() { $this->compiler->aliasComponent('app.components.alert', 'alert'); $string = '@alert @endalert'; $expected = 'startComponent(\'app.components.alert\'); ?> renderComponent(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomComponentsWithSlots() { $this->compiler->aliasComponent('app.components.alert', 'alert'); $string = '@alert([\'type\' => \'danger\']) @endalert'; $expected = 'startComponent(\'app.components.alert\', [\'type\' => \'danger\']); ?> renderComponent(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomComponentsWithExistingDirective() { $this->compiler->aliasComponent('app.components.foreach', 'foreach'); $string = '@foreach @endforeach'; $expected = 'startComponent(\'app.components.foreach\'); ?> renderComponent(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomIncludes() { $this->compiler->include('app.includes.input', 'input'); $string = '@input'; $expected = 'make(\'app.includes.input\', [], \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomIncludesWithData() { $this->compiler->include('app.includes.input', 'input'); $string = '@input([\'type\' => \'email\'])'; $expected = 'make(\'app.includes.input\', [\'type\' => \'email\'], \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomIncludesDefaultAlias() { $this->compiler->include('app.includes.input'); $string = '@input'; $expected = 'make(\'app.includes.input\', [], \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testCustomIncludesWithExistingDirective() { $this->compiler->include('app.includes.foreach'); $string = '@foreach'; $expected = 'make(\'app.includes.foreach\', [], \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } }