-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaravelFontAwesomeTest.php
59 lines (50 loc) · 1.68 KB
/
LaravelFontAwesomeTest.php
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
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Djam90\LaravelFontAwesome\Test;
class LaravelFontAwesomeTest extends TestCase
{
private $blade;
public function setUp(): void
{
parent::setUp();
$this->blade = resolve('blade.compiler');
}
public function testBladeDirectiveOutputsSuccessfully()
{
$types = ['fas', 'far', 'fad', 'fal', 'fab'];
foreach ($types as $type) {
$this->assertDirectiveOutput(
'<i class="' . $type . ' fa-user"></i>',
'@' . $type . '("user")',
[],
''
);
}
}
/**
* Evaluate a Blade expression with the given $variables in scope.
*
* Thanks to https://stevegrunwell.com/blog/custom-laravel-blade-directives/
*
* @param string $expected The expected output.
* @param string $expression The Blade directive, as it would be written in a view.
* @param array $variables Variables to extract() into the scope of the eval() statement.
* @param string $message A message to display if the output does not match $expected.
*/
protected function assertDirectiveOutput(
string $expected,
string $expression = '',
array $variables = [],
string $message = ''
) {
$compiled = $this->blade->compileString($expression);
/*
* Normally using eval() would be a big no-no, but when you're working on a templating
* engine it's difficult to avoid.
*/
ob_start();
extract($variables);
eval(' ?>' . $compiled . '<?php ');
$output = ob_get_clean();
$this->assertEquals($expected, $output, $message);
}
}