diff --git a/src/demo/index.php b/src/demo/index.php
index c4db5218..5c9184ca 100644
--- a/src/demo/index.php
+++ b/src/demo/index.php
@@ -106,6 +106,12 @@ function gtag() {
+
+
+
diff --git a/src/models/RendererModel.php b/src/models/RendererModel.php
index 3ca813a2..64e08d0e 100644
--- a/src/models/RendererModel.php
+++ b/src/models/RendererModel.php
@@ -52,6 +52,9 @@ class RendererModel
/** @var string $separator Line separator */
public $separator;
+ /** @var bool $random True = Sort lines in random order */
+ public $random;
+
/** @var string $fontCSS CSS required for displaying the selected font */
public $fontCSS;
@@ -74,6 +77,7 @@ class RendererModel
"pause" => "0",
"repeat" => "true",
"separator" => ";",
+ "random" => "false",
];
/**
@@ -86,6 +90,7 @@ public function __construct($template, $params)
{
$this->template = $template;
$this->separator = $params["separator"] ?? $this->DEFAULTS["separator"];
+ $this->random = $this->checkBoolean($params["random"] ?? $this->DEFAULTS["random"]);
$this->lines = $this->checkLines($params["lines"] ?? "");
$this->font = $this->checkFont($params["font"] ?? $this->DEFAULTS["font"]);
$this->weight = $this->checkNumberPositive($params["weight"] ?? $this->DEFAULTS["weight"], "Font weight");
@@ -118,6 +123,9 @@ private function checkLines($lines)
$lines = rtrim($lines, $this->separator);
}
$exploded = explode($this->separator, $lines);
+ if ($this->random) {
+ shuffle($exploded);
+ }
// escape special characters to prevent code injection
return array_map("htmlspecialchars", $exploded);
}
diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php
index 697b8fe8..48ff687e 100644
--- a/tests/OptionsTest.php
+++ b/tests/OptionsTest.php
@@ -338,4 +338,33 @@ public function testSeparator(): void
$this->assertEquals(";;", $model->separator);
$this->assertEquals(["text", "tex;t2"], $model->lines);
}
+
+ /**
+ * Test random order
+ */
+ public function testRandom(): void
+ {
+ // not set
+ $params = [
+ "lines" => "text",
+ ];
+ $model = new RendererModel("src/templates/main.php", $params);
+ $this->assertEquals(false, $model->random);
+
+ // true
+ $params = [
+ "lines" => "text",
+ "random" => "true",
+ ];
+ $model = new RendererModel("src/templates/main.php", $params);
+ $this->assertEquals(true, $model->random);
+
+ // other / false
+ $params = [
+ "lines" => "text",
+ "random" => "other",
+ ];
+ $model = new RendererModel("src/templates/main.php", $params);
+ $this->assertEquals(false, $model->random);
+ }
}
diff --git a/tests/RendererTest.php b/tests/RendererTest.php
index 7d122db1..6093aaf6 100644
--- a/tests/RendererTest.php
+++ b/tests/RendererTest.php
@@ -304,4 +304,26 @@ public function testSeparator(): void
$actualSVG = $controller->render();
$this->compareNoCommentsOrWhitespace($expectedSVG, $actualSVG);
}
+
+ /**
+ * Test random
+ */
+ public function testRandom(): void
+ {
+ $lines = [
+ "Full-stack web and app developer",
+ "Self-taught UI/UX Designer",
+ "10+ years of coding experience",
+ "Always learning new things",
+ ];
+ $params = [
+ "lines" => implode(";", $lines),
+ "random" => "true",
+ ];
+ $controller = new RendererController($params);
+ $actualSVG = preg_replace("/\s+/", " ", $controller->render());
+ foreach ($lines as $line) {
+ $this->assertStringContainsString("> $line ", $actualSVG);
+ }
+ }
}