public function testExtendedClass() { $this->
assertEquals(' class="kitten"',
$this->twig->
render('{{ attribute.addClass("kitten") }}',
['attribute' =>
new TestAttribute()]));
} /**
* Tests that prefixed methods can be called from within Twig templates.
*
* Currently "get", "has", and "is" are the only allowed prefixes.
*/
public function testEntitySafePrefixes() { $entity =
$this->
createMock('Drupal\Core\Entity\EntityInterface'
);
$entity->
expects($this->
atLeastOnce()) ->
method('hasLinkTemplate'
) ->
with('test'
) ->
willReturn(TRUE
);
$result =
$this->twig->
render('{{ entity.hasLinkTemplate("test") }}',
['entity' =>
$entity]);
$this->
assertTrue((bool) $result, 'Sandbox policy allows has* functions to be called.'
);
$entity =
$this->
createMock('Drupal\Core\Entity\EntityInterface'
);
$entity->
expects($this->
atLeastOnce()) ->
method('isNew'
) ->
willReturn(TRUE
);
$result =
$this->twig->
render('{{ entity.isNew }}',
['entity' =>
$entity]);