mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
merged branch fabpot/twig-c-bug (PR #920)
This PR was merged into the master branch. Commits -------df13370added a missing test33e690bfixed some tests when the extension is not enabled51e707fmerged branch char101/fix-ext-retval (PR #921)014f459added some missing test for Template::getAttribute()e8d12daFix empty string comparison4311df3added some missing test for Template::getAttribute() Discussion ---------- The C extension does not behave in the same way as the PHP code The added test shows that the C extension does not behave in the same way as the PHP code. I have no idea why. The problem is probably around line 1033 in the extension code: https://github.com/fabpot/Twig/blob/master/ext/twig/twig.c#L1033 --------------------------------------------------------------------------- by stof at 2012-12-05T17:07:00Z The testsuite is broken when you run it without the C Twig extension. The test should be skipped when ``useExt`` is ``true`` and the extension is not available
This commit is contained in:
+1
-1
@@ -1030,7 +1030,7 @@ PHP_FUNCTION(twig_template_get_attributes)
|
||||
// ret can be null, if e.g. the called method throws an exception
|
||||
if (ret) {
|
||||
if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) {
|
||||
if (Z_STRVAL_P(ret) == "") {
|
||||
if (Z_STRLEN_P(ret) == 0) {
|
||||
free_ret = 1;
|
||||
} else {
|
||||
zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC);
|
||||
|
||||
@@ -105,6 +105,40 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getGetAttributeWithTemplateAsObject
|
||||
*/
|
||||
public function testGetAttributeWithTemplateAsObject($useExt)
|
||||
{
|
||||
$template = new Twig_TemplateTest(new Twig_Environment(), $useExt);
|
||||
$template1 = new Twig_TemplateTest(new Twig_Environment(), false);
|
||||
|
||||
$this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string'));
|
||||
$this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
|
||||
|
||||
$this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true'));
|
||||
$this->assertEquals('1', $template->getAttribute($template1, 'true'));
|
||||
|
||||
$this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero'));
|
||||
$this->assertEquals('0', $template->getAttribute($template1, 'zero'));
|
||||
|
||||
$this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
|
||||
$this->assertSame('', $template->getAttribute($template1, 'empty'));
|
||||
}
|
||||
|
||||
public function getGetAttributeWithTemplateAsObject()
|
||||
{
|
||||
$bools = array(
|
||||
array(false),
|
||||
);
|
||||
|
||||
if (function_exists('twig_template_get_attributes')) {
|
||||
$bools[] = array(true);
|
||||
}
|
||||
|
||||
return $bools;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getGetAttributeTests
|
||||
*/
|
||||
@@ -289,6 +323,26 @@ class Twig_TemplateTest extends Twig_Template
|
||||
Twig_Template::clearCache();
|
||||
}
|
||||
|
||||
public function getZero()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getEmpty()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getString()
|
||||
{
|
||||
return 'some_string';
|
||||
}
|
||||
|
||||
public function getTrue()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTemplateName()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user