mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-07 16:06:53 +00:00
Add two tests for error conditions in #3930
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Twig\Extra\Html\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Extra\Html\HtmlAttr\AttributeValueInterface;
|
||||
use Twig\Extra\Html\HtmlAttr\SeparatedTokenList;
|
||||
use Twig\Extra\Html\HtmlExtension;
|
||||
@@ -269,6 +270,28 @@ class HtmlAttrTest extends TestCase
|
||||
|
||||
self::assertSame('data-controller="dropdown tooltip" data-action="click->dropdown#toggle mouseover->tooltip#show"', $result);
|
||||
}
|
||||
|
||||
public function testDataAttributeWithNonJsonEncodableValueThrowsRuntimeError()
|
||||
{
|
||||
$this->expectException(RuntimeError::class);
|
||||
$this->expectExceptionMessage('The "data-bad" attribute value cannot be JSON encoded.');
|
||||
|
||||
HtmlExtension::htmlAttr(
|
||||
new Environment(new ArrayLoader()),
|
||||
['data-bad' => [\INF]] // INF cannot be JSON-encoded
|
||||
);
|
||||
}
|
||||
|
||||
public function testNonStringableObjectAsAttributeValueThrowsRuntimeError()
|
||||
{
|
||||
$this->expectException(RuntimeError::class);
|
||||
$this->expectExceptionMessage('The "title" attribute value should be a scalar, an iterable, or an object implementing "Stringable"');
|
||||
|
||||
HtmlExtension::htmlAttr(
|
||||
new Environment(new ArrayLoader()),
|
||||
['title' => new \stdClass()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StringableStub implements \Stringable
|
||||
|
||||
Reference in New Issue
Block a user