@@ -13,8 +13,10 @@ class DataTemplateTest extends TestCase
13
13
14
14
public function setUp (): void
15
15
{
16
- $ this ->dataTemplate = $ this ->createPartialMock (DataTemplateImplementation::class, ['getTemplate ' , 'getData ' , 'getDateTimeFormat ' ]);
16
+ $ this ->dataTemplate = $ this ->createPartialMock (DataTemplateImplementation::class, ['getTemplate ' , 'getData ' , 'getMode ' , ' getDateTimeFormat ' ]);
17
17
$ this ->dataTemplate ->expects ($ this ->any ())->method ('getDateTimeFormat ' )->willReturn (\DateTimeImmutable::W3C );
18
+ $ this ->dataTemplate ->expects ($ this ->any ())->method ('getMode ' )->willReturn ('html ' );
19
+
18
20
}
19
21
20
22
public function stringifyConvertsDataProvider (): \Generator
@@ -76,4 +78,33 @@ public function evaluateAccessesNestedData(mixed $data, string $template, string
76
78
$ this ->dataTemplate ->expects ($ this ->once ())->method ('getData ' )->willReturn ($ data );
77
79
$ this ->assertSame ($ expectedString , $ this ->dataTemplate ->evaluate ());
78
80
}
81
+
82
+ public function modeControlsEntityEscapingDataProvider (): \Generator
83
+ {
84
+ yield 'string with ampersand ' => ['foo & bar ' , 'foo & bar ' , 'foo & bar ' ];
85
+ yield 'string with script ' => ['foo <script>evil</script> bar ' , 'foo evil bar ' , 'foo evil bar ' ];
86
+ }
87
+
88
+ /**
89
+ * @test
90
+ * @dataProvider modeControlsEntityEscapingDataProvider
91
+ */
92
+ public function modeControlsEntityEscaping (mixed $ data , string $ expectedHtmlString , string $ expectedPlaintextString ): void
93
+ {
94
+
95
+ $ htmlDataTemplate = $ this ->createPartialMock (DataTemplateImplementation::class, ['getTemplate ' , 'getData ' , 'getDateTimeFormat ' , 'getMode ' ]);
96
+ $ htmlDataTemplate ->expects ($ this ->any ())->method ('getDateTimeFormat ' )->willReturn (\DateTimeImmutable::W3C );
97
+ $ htmlDataTemplate ->expects ($ this ->any ())->method ('getMode ' )->willReturn ('html ' );
98
+ $ htmlDataTemplate ->expects ($ this ->any ())->method ('getTemplate ' )->willReturn ('{data} ' );
99
+ $ htmlDataTemplate ->expects ($ this ->any ())->method ('getData ' )->willReturn (['data ' => $ data ]);
100
+
101
+ $ plainte = $ this ->createPartialMock (DataTemplateImplementation::class, ['getTemplate ' , 'getData ' , 'getDateTimeFormat ' , 'getMode ' ]);
102
+ $ plainte ->expects ($ this ->any ())->method ('getDateTimeFormat ' )->willReturn (\DateTimeImmutable::W3C );
103
+ $ plainte ->expects ($ this ->any ())->method ('getMode ' )->willReturn ('plaintext ' );
104
+ $ plainte ->expects ($ this ->any ())->method ('getTemplate ' )->willReturn ('{data} ' );
105
+ $ plainte ->expects ($ this ->any ())->method ('getData ' )->willReturn (['data ' => $ data ]);
106
+
107
+ $ this ->assertSame ($ expectedHtmlString , $ htmlDataTemplate ->evaluate ());
108
+ $ this ->assertSame ($ expectedPlaintextString , $ plainte ->evaluate ());
109
+ }
79
110
}
0 commit comments