Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix wrong var in Callback renderer and make last Default tests pass w…
…ith Callback renderer

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_QuickForm2/trunk@309736 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
golgote committed Mar 27, 2011
1 parent 19fe555 commit 4fe9e35
Showing 1 changed file with 75 additions and 25 deletions.
100 changes: 75 additions & 25 deletions tests/QuickForm2/Renderer/CallbackTest.php
Expand Up @@ -120,26 +120,6 @@ public static function _renderTestMultipleLabels($renderer, $element)
return (string)$element;
}

public static function _renderGroupInputText($renderer, $element)
{
return 'IgnoreThis;html='.$element;
}

public static function _renderGroupInput($renderer, $element)
{
return 'GroupedInput;id='.$element->getId().',html='.$element;
}

public static function _renderGroupElement($renderer, $element)
{
return 'GroupedElement;id='.$element->getId().',html='.$element;
}

public static function _renderGroupId($renderer, $element)
{
return 'testRenderGroupedElement;id='.$element->getId().',html='.$element;
}

public function testRenderElementUsingMostAppropriateCallback()
{
$element = HTML_QuickForm2_Factory::createElement(
Expand Down Expand Up @@ -325,7 +305,27 @@ public function testRenderGroupedHiddens()

$this->assertContains($hidden1->__toString() . $hidden2->__toString(), $html);
}
/*

public static function _renderGroupInputText($renderer, $element)
{
return 'IgnoreThis;html='.$element;
}

public static function _renderGroupInput($renderer, $element)
{
return 'GroupedInput;id='.$element->getId().',html='.$element;
}

public static function _renderGroup($renderer, $element)
{
return 'GroupedElement;id='.$element->getId().',html='.$element;
}

public static function _renderGroupedElement($renderer, $element)
{
return 'testRenderGroupedElement;id='.$element->getId().',html='.$element;
}

public function testRenderGroupedElementUsingMostAppropriateTemplate()
{
$group = HTML_QuickForm2_Factory::createElement('group', 'foo', array('id' => 'testRenderGroup'));
Expand All @@ -341,10 +341,10 @@ public function testRenderGroupedElementUsingMostAppropriateTemplate()
array($class, '_renderGroupInput')
)->setElementCallbackForGroupId(
'testRenderGroup', 'HTML_QuickForm2_Element',
array($class, '_renderGroupElement')
array($class, '_renderGroup')
)->setCallbackForId(
'testRenderGroupedElement',
array($class, '_renderGroupId')
array($class, '_renderGroupedElement')
);

$this->assertContains(
Expand All @@ -353,7 +353,6 @@ public function testRenderGroupedElementUsingMostAppropriateTemplate()
);

$renderer->setCallbackForId('testRenderGroupedElement', null);
var_dump($group->render($renderer->reset())->__toString());
$this->assertContains(
'GroupedElement;id=' . $element->getId() . ',html=' . $element->__toString(),
$group->render($renderer->reset())->__toString()
Expand All @@ -370,7 +369,58 @@ public function testRenderGroupedElementUsingMostAppropriateTemplate()
'IgnoreThis', $group->render($renderer->reset())->__toString()
);
}
*/

public static function _renderTestSeparators($renderer, $group)
{
$separator = $group->getSeparator();
$elements = array_pop($renderer->html);
if (!is_array($separator)) {
$content = implode((string)$separator, $elements);
} else {
$content = '';
$cSeparator = count($separator);
for ($i = 0, $count = count($elements); $i < $count; $i++) {
$content .= (0 == $i? '': $separator[($i - 1) % $cSeparator]) .
$elements[$i];
}
}
return $content;
}

public static function _renderTestSeparators2($renderer, $element)
{
return '<foo>'.$element.'</foo>';
}

public function testRenderGroupedElementsWithSeparators()
{
$group = HTML_QuickForm2_Factory::createElement('group', 'foo', array('id' => 'testSeparators'));
$element1 = $group->addElement('text', 'bar');
$element2 = $group->addElement('text', 'baz');
$element3 = $group->addElement('text', 'quux');

$renderer = HTML_Quickform2_Renderer::factory('callback')
->setCallbackForId('testSeparators', array(get_class($this), '_renderTestSeparators'))
->setElementCallbackForGroupId(
'testSeparators', 'HTML_QuickForm2_Element_InputText', array(get_class($this), '_renderTestSeparators2')
);

$this->assertEquals(
'<foo>' . $element1 . '</foo><foo>' . $element2 . '</foo><foo>' . $element3 . '</foo>',
$group->render($renderer->reset())->__toString()
);

$group->setSeparator('&nbsp;');
$this->assertEquals(
'<foo>' . $element1 . '</foo>&nbsp;<foo>' . $element2 . '</foo>&nbsp;<foo>' . $element3 . '</foo>',
$group->render($renderer->reset())->__toString()
);

$group->setSeparator(array('<br />', '&nbsp;'));
$this->assertEquals(
'<foo>' . $element1 . '</foo><br /><foo>' . $element2 . '</foo>&nbsp;<foo>' . $element3 . '</foo>',
$group->render($renderer->reset())->__toString()
);
}
}
?>

0 comments on commit 4fe9e35

Please sign in to comment.