getUsers() as $user) test @endforeach'; $expected = 'getUsers(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> test popLoop(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testForeachStatementsAreCompileWithUppercaseSyntax() { $string = '@foreach ($this->getUsers() AS $user) test @endforeach'; $expected = 'getUsers(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> test popLoop(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testForeachStatementsAreCompileWithMultipleLine() { $string = '@foreach ([ foo, bar, ] as $label) test @endforeach'; $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> test popLoop(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testNestedForeachStatementsAreCompiled() { $string = '@foreach ($this->getUsers() as $user) user info @foreach ($user->tags as $tag) tag info @endforeach @endforeach'; $expected = 'getUsers(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> user info tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> tag info popLoop(); $loop = $__env->getLastLoop(); ?> popLoop(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); } public function testLoopContentHolderIsExtractedFromForeachStatements() { $string = '@foreach ($some_uSers1 as $user)'; $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); $string = '@foreach ($users->get() as $user)'; $expected = 'get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); $string = '@foreach (range(1, 4) as $user)'; $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); $string = '@foreach ( $users as $user)'; $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); $string = '@foreach ($tasks as $task)'; $expected = 'addLoop($__currentLoopData); foreach($__currentLoopData as $task): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); $string = "@foreach(resolve('App\\\\DataProviders\\\\'.\$provider)->data() as \$key => \$value) @endforeach"; $expected = "data(); \$__env->addLoop(\$__currentLoopData); foreach(\$__currentLoopData as \$key => \$value): \$__env->incrementLoopIndices(); \$loop = \$__env->getLastLoop(); ?> > popLoop(); \$loop = \$__env->getLastLoop(); ?>"; $this->assertEquals($expected, $this->compiler->compileString($string)); } }