Skip to content

Commit

Permalink
tests: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
castamir authored and dg committed Oct 12, 2015
1 parent 55fcc48 commit f89c58b
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Forms/ControlGroup.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Test: Nette\Forms\ControlGroup.
*/

use Tester\Assert;
use Nette\Forms\ControlGroup;

require __DIR__ . '/../bootstrap.php';


function createContainer() {
$container = new Nette\Forms\Container;
$container->addText('street', 'Street');
$container->addText('town', 'Town');
return $container;
}

$form = new Nette\Forms\Form;


// controls only
$group = $form->addGroup();
$form->addText('name', 'Name');
$form->addText('surname', 'Surname');

Assert::same($group, $form->getGroup(0));
Assert::true($form->getGroup(0) instanceof ControlGroup);
Assert::equal(2, count($group->getControls()));
Assert::equal(array($form['name'], $form['surname']), $group->getControls());
57 changes: 57 additions & 0 deletions tests/Forms/Forms.renderer.5.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<form action="" method="post">

<fieldset>
<table>
<tr>
<th><label for="frm-name">Name</label></th>

<td><input type="text" name="name" id="frm-name" class="text"></td>
</tr>

<tr>
<th><label for="frm-surname">Surname</label></th>

<td><input type="text" name="surname" id="frm-surname" class="text"></td>
</tr>
</table>
</fieldset>

<fieldset>
<legend>Address</legend>

<table>
<tr>
<th><label for="frm-note">Note</label></th>

<td><textarea name="note" id="frm-note"></textarea></td>
</tr>
</table>
</fieldset>

<table>
<tr>
<th><label for="frm-address-street">Street</label></th>

<td><input type="text" name="address[street]" id="frm-address-street" class="text"></td>
</tr>

<tr>
<th><label for="frm-address-town">Town</label></th>

<td><input type="text" name="address[town]" id="frm-address-town" class="text"></td>
</tr>

<tr>
<th><label for="frm-address-country">Country</label></th>

<td><input type="text" name="address[country]" id="frm-address-country" class="text"></td>
</tr>

<tr>
<th></th>

<td><input type="submit" name="_submit" value="Order" class="button"></td>
</tr>
</table>

</form>
37 changes: 37 additions & 0 deletions tests/Forms/Forms.renderer.5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Test: Nette\Forms default rendering containers inside groups.
*/

use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


function createContainer() {
$container = new Nette\Forms\Container;
$container->addText('street', 'Street');
$container->addText('town', 'Town');
$container->addText('country', 'Country');
return $container;
}

$form = new Nette\Forms\Form;

// controls only
$form->addGroup();
$form->addText('name', 'Name');
$form->addText('surname', 'Surname');

// container is ignored
$form->addGroup('Address');
$form->addComponent(createContainer(), 'address');

$form->addTextArea('note', 'Note');
$form->setCurrentGroup();
$form->addSubmit('submit', 'Order');

$form->fireEvents();

Assert::matchFile(__DIR__ . '/Forms.renderer.5.expect', $form->__toString(TRUE));

0 comments on commit f89c58b

Please sign in to comment.