<commit_before><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */

require_once('limb/macro/src/tags/form/lmbMacroFormErrorList.class.php'); 
 

class lmbMacroInputTagTest extends lmbBaseMacroTest
{
  function testTypeText()
  {
    $template = '{{input type="text" name="my_input" value="$#var"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('var', 100);
 
    $out = $page->render();
    $this->assertEqual($out, '<input type="text" name="my_input" value="100" />');
  }

  function testTypeTextRendersValueAttributeInAnyCase()
  {
    $template = '{{input type="text" name="my_input"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
 
    $out = $page->render();
    $this->assertEqual($out, '<input type="text" name="my_input" value="" />');
  }

  function testTypeTextTakesValueFromFormIfPossible()
  {
    $template = '{{form name="my_form" from="$#form_data"}}{{input type="text" name="my_input"}}{{/form}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('form_data', array('my_input' => 100));
 
    $out = $page->render();
    $this->assertEqual($out, '<form name="my_form"><input type="text" name="my_input" value="100" /></form>');
  }   
  
  function testTypesHiddenAndButtonAndImage()
  {
    $template = '{{input type="hidden" name="my_hidden" value="$#for_hidden"}}'.
                '{{input type="button" name="my_button" value="$#for_button"}}'.
                '{{input type="image" src="some_path" name="my_image" value="$#for_image"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('for_hidden', 10);
    $page->set('for_button', 20);
    $page->set('for_image', 30);
 
    $out = $page->render();
    $expected = '<input type="hidden" name="my_hidden" value="10" />'.
                '<input type="button" name="my_button" value="20" />'.
                '<input type="image" src="some_path" name="my_image" value="30" />';
    $this->assertEqual($out, $expected);
  }
  
  function testTypesFileAndSubmitAndPasswordAndResetAndFile_DontTakeValueFromFormDatasource()
  {
    $template = '{{form name="my_form" from="$#form_data"}}'.
                '{{input type="file" name="my_file"}}'.
                '{{input type="submit" name="my_submit"}}'.
                '{{input type="password" name="my_password"}}'.
                '{{input type="reset" name="my_reset"}}'.
                '{{/form}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('form_data', array('my_file' => 10, 'my_submit' => 20, 'my_password' => 30, 'my_reset' => 40));
 
    $out = $page->render();
    $expected = '<form name="my_form"><input type="file" name="my_file" />'.
                '<input type="submit" name="my_submit" />'.
                '<input type="password" name="<PASSWORD>" />'.
                '<input type="reset" name="my_reset" /></form>';
    $this->assertEqual($out, $expected);
  }
}
<commit_msg>[svn r6557] -- a bit better test for {{input}} tag<commit_after><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */

require_once('limb/macro/src/tags/form/lmbMacroFormErrorList.class.php'); 
 

class lmbMacroInputTagTest extends lmbBaseMacroTest
{
  function testTypeText()
  {
    $template = '{{input type="text" name="my_input" value="$#var"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('var', 100);
 
    $out = $page->render();
    $this->assertEqual($out, '<input type="text" name="my_input" value="100" />');
  }

  function testTypeTextRendersValueAttributeInAnyCase()
  {
    $template = '{{input type="text" name="my_input"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
 
    $out = $page->render();
    $this->assertEqual($out, '<input type="text" name="my_input" value="" />');
  }

  function testTypeTextTakesValueFromFormIfPossible()
  {
    $template = '{{form name="my_form" from="$#form_data"}}{{input type="text" name="my_input"}}{{/form}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('form_data', array('my_input' => 100));
 
    $out = $page->render();
    $this->assertEqual($out, '<form name="my_form"><input type="text" name="my_input" value="100" /></form>');
  }   
  
  function testTypesHiddenAndButtonAndImage()
  {
    $template = '{{input type="hidden" name="my_hidden" value="$#for_hidden"}}'.
                '{{input type="button" name="my_button" value="$#for_button"}}'.
                '{{input type="image" src="some_path" name="my_image" value="$#for_image"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('for_hidden', 10);
    $page->set('for_button', 20);
    $page->set('for_image', 30);
 
    $out = $page->render();
    $expected = '<input type="hidden" name="my_hidden" value="10" />'.
                '<input type="button" name="my_button" value="20" />'.
                '<input type="image" src="some_path" name="my_image" value="30" />';
    $this->assertEqual($out, $expected);
  }
  
  function testTypesFileAndSubmitAndPasswordAndResetAndFile_DontTakeValueFromFormDatasource()
  {
    $template = '{{form name="my_form" from="$#form_data"}}'.
                '{{input type="file" name="my_file"}}'.
                '{{input type="submit" name="my_submit"}}'.
                '{{input type="password" name="<PASSWORD>"}}'.
                '{{input type="reset" name="my_reset"}}'.
                '{{/form}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('form_data', array('my_file' => 10, 'my_submit' => 20, 'my_password' => 30, 'my_reset' => 40));
 
    $out = $page->render();
    $expected = '<form name="my_form"><input type="file" name="my_file" />'.
                '<input type="submit" name="my_submit" />'.
                '<input type="password" name="<PASSWORD>" />'.
                '<input type="reset" name="my_reset" /></form>';
    $this->assertEqual($out, $expected);
  }
  
  function testTypesFileAndSubmitAndPasswordAndResetAndFile_MayRenderValueAttribute()
  {
    $template = '{{input type="file" name="my_file" value="$#my_file"}}'.
                '{{input type="submit" name="my_submit" value="title_{$#my_submit}"}}'.
                '{{input type="password" name="my_password" value="<PASSWORD>"}}'.
                '{{input type="reset" name="my_reset" value="any_value"}}';

    $page = $this->_createMacroTemplate($template, 'tpl.html');
    $page->set('my_file', 10);
    $page->set('my_submit', 20);
    $page->set('my_password', 30);
 
    $out = $page->render();
    $expected = '<input type="file" name="my_file" value="10" />'.
                '<input type="submit" name="my_submit" value="title_20" />'.
                '<input type="password" name="my_password" value="30" />'.
                '<input type="reset" name="my_reset" value="any_value" />';
    $this->assertEqual($out, $expected);
  }  
}

{'fraction_non_alphanumeric': 0.21211703008556446, 'fraction_numerical': 0.013248688931824454, 'mean_word_length': 3.6100508905852418, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6439163', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2382, 'n_words': 397}