File: BladeAnonymousComponentTest.php

package info (click to toggle)
php-laravel-framework 10.48.29%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,188 kB
  • sloc: php: 232,347; sh: 167; makefile: 46
file content (48 lines) | stat: -rw-r--r-- 1,705 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace Illuminate\Tests\Integration\View;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use InvalidArgumentException;
use Orchestra\Testbench\TestCase;

class BladeAnonymousComponentTest extends TestCase
{
    public function test_anonymous_components_with_custom_paths_can_be_rendered()
    {
        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-1', 'layouts');
        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-2');

        $view = View::make('page')->render();

        $this->assertTrue(str_contains($view, 'Panel content.'));
        $this->assertTrue(str_contains($view, 'class="app-layout"'));
        $this->assertTrue(str_contains($view, 'class="danger-button"'));
    }

    public function test_anonymous_components_with_custom_paths_cant_be_rendered_as_normal_views()
    {
        $this->expectException(InvalidArgumentException::class);

        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-1', 'layouts');
        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-2');

        $view = View::make('layouts::app')->render();
    }

    public function test_anonymous_components_with_custom_paths_cant_be_rendered_as_normal_views_even_with_no_prefix()
    {
        $this->expectException(InvalidArgumentException::class);

        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-1', 'layouts');
        Blade::anonymousComponentPath(__DIR__.'/anonymous-components-2');

        $view = View::make('panel')->render();
    }

    protected function getEnvironmentSetUp($app)
    {
        $app['config']->set('view.paths', [__DIR__.'/anonymous-components-templates']);
    }
}