File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414use PHPUnit \Framework \TestCase ;
1515use Twig \Environment ;
16+ use Twig \Error \RuntimeError ;
1617use Twig \Extra \Html \HtmlAttr \AttributeValueInterface ;
1718use Twig \Extra \Html \HtmlAttr \SeparatedTokenList ;
1819use Twig \Extra \Html \HtmlExtension ;
@@ -269,6 +270,28 @@ public function getIterator(): \Traversable
269270
270271 self ::assertSame ('data-controller="dropdown tooltip" data-action="click->dropdown#toggle mouseover->tooltip#show" ' , $ result );
271272 }
273+
274+ public function testDataAttributeWithNonJsonEncodableValueThrowsRuntimeError ()
275+ {
276+ $ this ->expectException (RuntimeError::class);
277+ $ this ->expectExceptionMessage ('The "data-bad" attribute value cannot be JSON encoded. ' );
278+
279+ HtmlExtension::htmlAttr (
280+ new Environment (new ArrayLoader ()),
281+ ['data-bad ' => [\INF ]] // INF cannot be JSON-encoded
282+ );
283+ }
284+
285+ public function testNonStringableObjectAsAttributeValueThrowsRuntimeError ()
286+ {
287+ $ this ->expectException (RuntimeError::class);
288+ $ this ->expectExceptionMessage ('The "title" attribute value should be a scalar, an iterable, or an object implementing "Stringable" ' );
289+
290+ HtmlExtension::htmlAttr (
291+ new Environment (new ArrayLoader ()),
292+ ['title ' => new \stdClass ()]
293+ );
294+ }
272295}
273296
274297class StringableStub implements \Stringable
You can’t perform that action at this time.
0 commit comments