|
|
|
@ -8,6 +8,24 @@ require "vendor/autoload.php";
|
|
|
|
|
|
|
|
|
|
final class RendererTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Static method to assert strings are equal while ignoring whitespace
|
|
|
|
|
*
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param string $actual
|
|
|
|
|
*/
|
|
|
|
|
public static function compareNoCommentsOrWhitespace(string $expected, string $actual)
|
|
|
|
|
{
|
|
|
|
|
// remove comments and whitespace
|
|
|
|
|
$expected = preg_replace("/\s+/", " ", preg_replace("/<!--.*?-->/s", " ", $expected));
|
|
|
|
|
$actual = preg_replace("/\s+/", " ", preg_replace("/<!--.*?-->/s", " ", $actual));
|
|
|
|
|
// add newlines to make it easier to debug
|
|
|
|
|
$expected = str_replace(">", ">\n", $expected);
|
|
|
|
|
$actual = str_replace(">", ">\n", $actual);
|
|
|
|
|
// assert strings are equal
|
|
|
|
|
self::assertSame($expected, $actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test normal card render
|
|
|
|
|
*/
|
|
|
|
@ -26,7 +44,9 @@ final class RendererTest extends TestCase
|
|
|
|
|
"height" => "50",
|
|
|
|
|
];
|
|
|
|
|
$controller = new RendererController($params);
|
|
|
|
|
$this->assertStringEqualsFile("tests/svg/test_normal.svg", $controller->render());
|
|
|
|
|
$expectedSVG = file_get_contents("tests/svg/test_normal.svg");
|
|
|
|
|
$actualSVG = $controller->render();
|
|
|
|
|
$this->compareNoCommentsOrWhitespace($expectedSVG, $actualSVG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMultilineCardRender(): void
|
|
|
|
@ -134,7 +154,9 @@ final class RendererTest extends TestCase
|
|
|
|
|
"height" => "50",
|
|
|
|
|
];
|
|
|
|
|
$controller = new RendererController($params);
|
|
|
|
|
$this->assertStringEqualsFile("tests/svg/test_normal.svg", $controller->render());
|
|
|
|
|
$expectedSVG = file_get_contents("tests/svg/test_normal.svg");
|
|
|
|
|
$actualSVG = $controller->render();
|
|
|
|
|
$this->compareNoCommentsOrWhitespace($expectedSVG, $actualSVG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -205,4 +227,57 @@ final class RendererTest extends TestCase
|
|
|
|
|
$this->assertStringContainsString("dur='12000ms'", $controller->render());
|
|
|
|
|
$this->assertStringContainsString("keyTimes='0;0.5;0.91666666666667;1'", $controller->render());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test repeat set to false
|
|
|
|
|
*/
|
|
|
|
|
public function testRepeatFalse(): void
|
|
|
|
|
{
|
|
|
|
|
$params = [
|
|
|
|
|
"lines" => implode(";", [
|
|
|
|
|
"Full-stack web and app developer",
|
|
|
|
|
"Self-taught UI/UX Designer",
|
|
|
|
|
"10+ years of coding experience",
|
|
|
|
|
"Always learning new things",
|
|
|
|
|
]),
|
|
|
|
|
"center" => "true",
|
|
|
|
|
"vCenter" => "true",
|
|
|
|
|
"width" => "380",
|
|
|
|
|
"height" => "50",
|
|
|
|
|
"repeat" => "false",
|
|
|
|
|
];
|
|
|
|
|
$controller = new RendererController($params);
|
|
|
|
|
$actualSVG = preg_replace("/\s+/", " ", $controller->render());
|
|
|
|
|
$this->assertStringContainsString("begin='0s'", $actualSVG);
|
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
|
"begin='d2.end' dur='5000ms' fill='freeze' values='m0,25 h0 ; m0,25 h380 ; m0,25 h380 ; m0,25 h380'",
|
|
|
|
|
$actualSVG
|
|
|
|
|
);
|
|
|
|
|
$this->assertStringNotContainsString(";d3.end", $actualSVG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test repeat set to false on multiline card
|
|
|
|
|
*/
|
|
|
|
|
public function testRepeatFalseMultiline(): void
|
|
|
|
|
{
|
|
|
|
|
$params = [
|
|
|
|
|
"lines" => implode(";", [
|
|
|
|
|
"Full-stack web and app developer",
|
|
|
|
|
"Self-taught UI/UX Designer",
|
|
|
|
|
"10+ years of coding experience",
|
|
|
|
|
"Always learning new things",
|
|
|
|
|
]),
|
|
|
|
|
"center" => "true",
|
|
|
|
|
"vCenter" => "true",
|
|
|
|
|
"width" => "380",
|
|
|
|
|
"height" => "200",
|
|
|
|
|
"multiline" => "true",
|
|
|
|
|
"repeat" => "false",
|
|
|
|
|
];
|
|
|
|
|
$controller = new RendererController($params);
|
|
|
|
|
$actualSVG = preg_replace("/\s+/", " ", $controller->render());
|
|
|
|
|
$this->assertStringContainsString("begin='0s'", $actualSVG);
|
|
|
|
|
$this->assertStringNotContainsString(";d3.end", $actualSVG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|