8
8
9
9
final class RendererTest extends TestCase
10
10
{
11
+ /**
12
+ * Static method to assert strings are equal while ignoring whitespace
13
+ *
14
+ * @param string $expected
15
+ * @param string $actual
16
+ */
17
+ public static function compareNoCommentsOrWhitespace (string $ expected , string $ actual )
18
+ {
19
+ // remove comments and whitespace
20
+ $ expected = preg_replace ("/\s+/ " , " " , preg_replace ("/<!--.*?-->/s " , " " , $ expected ));
21
+ $ actual = preg_replace ("/\s+/ " , " " , preg_replace ("/<!--.*?-->/s " , " " , $ actual ));
22
+ // add newlines to make it easier to debug
23
+ $ expected = str_replace ("> " , "> \n" , $ expected );
24
+ $ actual = str_replace ("> " , "> \n" , $ actual );
25
+ // assert strings are equal
26
+ self ::assertSame ($ expected , $ actual );
27
+ }
28
+
11
29
/**
12
30
* Test normal card render
13
31
*/
@@ -26,7 +44,9 @@ public function testCardRender(): void
26
44
"height " => "50 " ,
27
45
];
28
46
$ controller = new RendererController ($ params );
29
- $ this ->assertStringEqualsFile ("tests/svg/test_normal.svg " , $ controller ->render ());
47
+ $ expectedSVG = file_get_contents ("tests/svg/test_normal.svg " );
48
+ $ actualSVG = $ controller ->render ();
49
+ $ this ->compareNoCommentsOrWhitespace ($ expectedSVG , $ actualSVG );
30
50
}
31
51
32
52
public function testMultilineCardRender (): void
@@ -134,7 +154,9 @@ public function testLineTrimming(): void
134
154
"height " => "50 " ,
135
155
];
136
156
$ controller = new RendererController ($ params );
137
- $ this ->assertStringEqualsFile ("tests/svg/test_normal.svg " , $ controller ->render ());
157
+ $ expectedSVG = file_get_contents ("tests/svg/test_normal.svg " );
158
+ $ actualSVG = $ controller ->render ();
159
+ $ this ->compareNoCommentsOrWhitespace ($ expectedSVG , $ actualSVG );
138
160
}
139
161
140
162
/**
@@ -205,4 +227,57 @@ public function testPauseMultiline(): void
205
227
$ this ->assertStringContainsString ("dur='12000ms' " , $ controller ->render ());
206
228
$ this ->assertStringContainsString ("keyTimes='0;0.5;0.91666666666667;1' " , $ controller ->render ());
207
229
}
230
+
231
+ /**
232
+ * Test repeat set to false
233
+ */
234
+ public function testRepeatFalse (): void
235
+ {
236
+ $ params = [
237
+ "lines " => implode ("; " , [
238
+ "Full-stack web and app developer " ,
239
+ "Self-taught UI/UX Designer " ,
240
+ "10+ years of coding experience " ,
241
+ "Always learning new things " ,
242
+ ]),
243
+ "center " => "true " ,
244
+ "vCenter " => "true " ,
245
+ "width " => "380 " ,
246
+ "height " => "50 " ,
247
+ "repeat " => "false " ,
248
+ ];
249
+ $ controller = new RendererController ($ params );
250
+ $ actualSVG = preg_replace ("/\s+/ " , " " , $ controller ->render ());
251
+ $ this ->assertStringContainsString ("begin='0s' " , $ actualSVG );
252
+ $ this ->assertStringContainsString (
253
+ "begin='d2.end' dur='5000ms' fill='freeze' values='m0,25 h0 ; m0,25 h380 ; m0,25 h380 ; m0,25 h380' " ,
254
+ $ actualSVG
255
+ );
256
+ $ this ->assertStringNotContainsString (";d3.end " , $ actualSVG );
257
+ }
258
+
259
+ /**
260
+ * Test repeat set to false on multiline card
261
+ */
262
+ public function testRepeatFalseMultiline (): void
263
+ {
264
+ $ params = [
265
+ "lines " => implode ("; " , [
266
+ "Full-stack web and app developer " ,
267
+ "Self-taught UI/UX Designer " ,
268
+ "10+ years of coding experience " ,
269
+ "Always learning new things " ,
270
+ ]),
271
+ "center " => "true " ,
272
+ "vCenter " => "true " ,
273
+ "width " => "380 " ,
274
+ "height " => "200 " ,
275
+ "multiline " => "true " ,
276
+ "repeat " => "false " ,
277
+ ];
278
+ $ controller = new RendererController ($ params );
279
+ $ actualSVG = preg_replace ("/\s+/ " , " " , $ controller ->render ());
280
+ $ this ->assertStringContainsString ("begin='0s' " , $ actualSVG );
281
+ $ this ->assertStringNotContainsString (";d3.end " , $ actualSVG );
282
+ }
208
283
}
0 commit comments