Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Commit

Permalink
Add test for form model binding
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Jul 13, 2014
1 parent b287cbe commit 9490c55
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/BasicFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,40 @@ public function testRenderFileGroupWithError()
$this->assertEquals($expected, $result);
}

public function testCanAddClassToUnderlyingControl()
{
public function testCanAddClassToUnderlyingControl()
{
$expected = '<div class="form-group"><label class="control-label" for="color">Favorite Color</label><select name="color" id="color" class="form-control my-class"><option value="1">Red</option><option value="2">Green</option><option value="3">Blue</option></select></div>';

$options = array('1' => 'Red', '2' => 'Green', '3' => 'Blue');
$result = $this->form->select('Favorite Color', 'color', $options)->addClass('my-class')->render();
$this->assertEquals($expected, $result);
}
}

public function testRenderTextGroupWithLabelClass()
public function testRenderTextGroupWithLabelClass()
{
$expected = '<div class="form-group"><label class="control-label required" for="email">Email</label><input type="text" name="email" id="email" class="form-control"></div>';
$result = $this->form->text('Email', 'email')->labelClass('required')->render();
$this->assertEquals($expected, $result);
}

public function testBindObject()
{
$object = $this->getStubObject();
$this->form->bind($object);
$expected = '<div class="form-group"><label class="control-label" for="first_name">First Name</label><input type="text" name="first_name" value="John" id="first_name" class="form-control"></div>';
$result = $this->form->text('First Name', 'first_name')->render();
$this->assertEquals($expected, $result);
}

private function getStubObject()
{
$obj = new stdClass;
$obj->email = '[email protected]';
$obj->first_name = 'John';
$obj->last_name = 'Doe';
$obj->date_of_birth = new \DateTime('1985-05-06');
$obj->gender = 'male';
$obj->terms = 'agree';
return $obj;
}
}

0 comments on commit 9490c55

Please sign in to comment.