merged branch fabpot/twig-c-bug (PR #920)

This PR was merged into the master branch.

Commits
-------

df13370 added a missing test
33e690b fixed some tests when the extension is not enabled
51e707f merged branch char101/fix-ext-retval (PR #921)
014f459 added some missing test for Template::getAttribute()
e8d12da Fix empty string comparison
4311df3 added 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:
Fabien Potencier
2012-12-06 08:16:52 +01:00
2 changed files with 55 additions and 1 deletions
+1 -1
View File
@@ -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);
+54
View File
@@ -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()
{
}