-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathTestHelpers.php
More file actions
45 lines (32 loc) · 1.11 KB
/
TestHelpers.php
File metadata and controls
45 lines (32 loc) · 1.11 KB
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
<?php
namespace Styde\Html\Tests;
use Illuminate\Contracts\Support\Htmlable;
trait TestHelpers
{
protected function assertHtmlEquals($expected, $actual)
{
$this->assertInstanceOf(Htmlable::class, $actual);
$this->assertSame($expected, trim($actual->toHtml()));
}
protected function assertTemplateMatches($template, $actual)
{
$this->assertInstanceOf(Htmlable::class, $actual);
$actual = $actual->toHtml();
$theme = config('html.theme', 'bootstrap4');
$template = __DIR__ . "/snapshots/$theme/$template.html";
if (! file_exists($template)) {
file_put_contents($template, $actual);
$this->markTestIncomplete("The template [$template] was created");
return;
}
$html = file_get_contents($template);
return $this->assertEquals(
$this->removeExtraWhitespaces($html),
$this->removeExtraWhitespaces($actual)
);
}
private function removeExtraWhitespaces($string)
{
return trim(str_replace('> <', '><', preg_replace('/\s+/', ' ', $string)));
}
}