<commit_before><?php

use Wasp\Test\TestCase;

/**
 * Test case for the form classes
 *
 * @package Wasp
 * @subpackage Tests/Form
 * @author <NAME>
 */
class FormTest extends TestCase
{

	/**
	 * An Array of Compiler Passes used by this test
	 *
	 * @var Array
	 */
	protected $passes = [
		'Wasp\DI\Pass\DatabaseMockeryPass'
	];

	/**
	 * Set up test environment
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function setUp()
	{
		parent::setUp();
		
		// The route we use.
		$this->DI->get('route')->add('form.test', '/form/test', Array('GET'));

		// Setup the DB
		$this->DI->get('database')->create(ENTITIES);
	}

	/**
	 * Test building a new form 
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_processForm()
	{
		$form = new Wasp\Test\Forms\Forms\TestForm();

		$this->assertEquals(4, count($form->fields()));
		$this->assertEquals('<form action="/form/test" method="POST" class="form">', $form->open(['class' => 'form']));
		$this->assertEquals('</form>', $form->close());
	}

	/**
	 * Test the default values
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_defaultValues()
	{
		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$username = $fields[0];

		$this->assertEquals('Dan', $username->getValue());
		$this->assertEquals('<input type="text" name="username" id="username" value="Dan" />', $username->field());
	}

	/**
	 * Test values that come from user input
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_inputValues()
	{
		$request = $this->DI->get('request')->make('/form', 'POST', Array('username' => 'Bob'));

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$username = $fields[0];

		$this->assertEquals('Bob', $username->getValue());
	}

	/**
	 * Test validating a form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_validation()
	{
		$this->DI->get('request')->make('/form', 'POST', Array());

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$result = $form->validate();

		$this->assertFalse($result);
	}

	/**
	 * Check the checkbox group output from our test form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_checkboxGroupOutput()
	{
		$request = $this->DI->get('request')->make('/form', 'POST', Array('checkgroup' => 'Y'));

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$checkgroup = $fields[2];

		$this->assertEquals('Y', $checkgroup->getValue());
		$this->assertEquals('<label><input type="checkbox" name="checkgroup" value="Y" checked="checked"/>Yes</label><label><input type="checkbox" name="checkgroup" value="N" />No</label>', $checkgroup->field());
	}

	/**
	 * Test binding model data to the form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_modelBindingForm()
	{
		$form = new Wasp\Test\Forms\Forms\TestModelForm();

		$fields = $form->fields();
		$name = $fields[0];

		$this->assertEquals('Dan', $name->getValue());
	}	


} // END class FormTest extends TestCase<commit_msg>Missing test from previous commits<commit_after><?php

use Wasp\Test\TestCase;

/**
 * Test case for the form classes
 *
 * @package Wasp
 * @subpackage Tests/Form
 * @author <NAME>
 */
class FormTest extends TestCase
{

	/**
	 * An Array of Compiler Passes used by this test
	 *
	 * @var Array
	 */
	protected $passes = [
		'Wasp\DI\Pass\DatabaseMockeryPass'
	];

	/**
	 * Set up test environment
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function setUp()
	{
		parent::setUp();
		
		// The route we use.
		$this->DI->get('route')->add('form.test', '/form/test', Array('GET'));

		// Setup the DB
		$this->DI->get('database')->create(ENTITIES);
	}

	/**
	 * Test building a new form 
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_processForm()
	{
		$form = new Wasp\Test\Forms\Forms\TestForm();

		$this->assertEquals(4, count($form->fields()));
		$this->assertEquals('<form action="/form/test" method="POST" class="form">', $form->open(['class' => 'form']));
		$this->assertEquals('</form>', $form->close());
	}

	/**
	 * Test the default values
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_defaultValues()
	{
		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$username = $fields[0];

		$this->assertEquals('Dan', $username->getValue());
		$this->assertEquals('<input type="text" name="username" id="username" value="Dan" />', $username->field());
	}

	/**
	 * Test values that come from user input
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_inputValues()
	{
		$request = $this->DI->get('request')->make('/form', 'POST', Array('username' => 'Bob'));

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$username = $fields[0];

		$this->assertEquals('Bob', $username->getValue());
	}

	/**
	 * Test validating a form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_validation()
	{
		$this->DI->get('request')->make('/form', 'POST', Array());

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$result = $form->validate();

		$this->assertFalse($result);
	}

	/**
	 * Check the checkbox group output from our test form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_checkboxGroupOutput()
	{
		$request = $this->DI->get('request')->make('/form', 'POST', Array('checkgroup' => 'Y'));

		$form = new Wasp\Test\Forms\Forms\TestForm();
		$fields = $form->fields();

		$checkgroup = $fields[2];

		$this->assertEquals('Y', $checkgroup->getValue());
		$this->assertEquals('<label><input type="checkbox" name="checkgroup" value="Y" checked="checked"/>Yes</label><label><input type="checkbox" name="checkgroup" value="N" />No</label>', $checkgroup->field());
	}

	/**
	 * Test binding model data to the form
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_modelBindingForm()
	{
		$form = new Wasp\Test\Forms\Forms\TestModelForm();

		$fields = $form->fields();
		$name = $fields[0];

		$this->assertEquals('Dan', $name->getValue());
	}	

	/**
	 * Test that input from the request has higher priority than the model data
	 *
	 * @return void
	 * @author <NAME>
	 */
	public function test_userInputShouldOverrideModelData()
	{
		$request = $this->DI->get('request')->make('/form', 'POST', Array('name' => 'Bob'));

		$form = new Wasp\Test\Forms\Forms\TestModelForm();

		$fields = $form->fields();
		$name = $fields[0];

		$this->assertEquals('Bob', $name->getValue());
	}


} // END class FormTest extends TestCase
{'fraction_non_alphanumeric': 0.20532028741782601, 'fraction_numerical': 0.0016817000458645467, 'mean_word_length': 3.7578181818181817, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '739507', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2111, 'n_words': 483}