Skip to content

Commit 1724278

Browse files
committed
test: some additional minor tests
1 parent a4cccc1 commit 1724278

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/FieldTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ public function testHiddenField(){
1515
$this->assertEquals('1', $mock->field['foo']->attribute('value'));
1616
}
1717

18+
public function testExplicitId(){
19+
$mock = new MockLayout();
20+
$form = Form::create('id', function($f){
21+
$f->text_field('foo', 'Label', ['id' => 'explicit_set_id']);
22+
}, ['layout' => $mock]);
23+
$this->assertArrayHasKey('foo', $mock->field);
24+
$this->assertEquals('explicit_set_id', $mock->field['foo']->attribute('id'));
25+
}
26+
27+
28+
/**
29+
* @expectedException PHPUnit_Framework_Error
30+
*/
31+
public function testInvalidLabel(){
32+
$mock = new MockLayout();
33+
$form = Form::create('id', function($f){
34+
$f->text_field('foo', 5);
35+
}, ['layout' => $mock]);
36+
}
37+
1838
public function testInputFields(){
1939
$mock = new MockLayout();
2040
$matrix = [

tests/FormTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@
55
require_once 'MockForm.php';
66

77
class FormTest extends PHPUnit_Framework_TestCase {
8+
public function testClassString(){
9+
$mock = new MockLayout();
10+
$form = Form::create('id', function($f){}, ['layout' => $mock, 'class' => 'foo bar']);
11+
$this->assertEquals('POST', $mock->form_attr['method']);
12+
$this->assertEquals(['form', 'mock', 'foo', 'bar'], $mock->form_attr['class']);
13+
}
14+
15+
public function testClassArray(){
16+
$mock = new MockLayout();
17+
$form = Form::create('id', function($f){}, ['layout' => $mock, 'class' => ['foo', 'bar']]);
18+
$this->assertEquals('POST', $mock->form_attr['method']);
19+
$this->assertEquals(['form', 'mock', 'foo', 'bar'], $mock->form_attr['class']);
20+
}
21+
22+
/**
23+
* @expectedException PHPUnit_Framework_Error_Notice
24+
*/
25+
public function testLayoutMissing(){
26+
$form = Form::create('id', function($f){}, ['layout' => 'foobar']);
27+
}
28+
29+
/**
30+
* @expectedException PHPUnit_Framework_Error
31+
*/
32+
public function testLayoutInvalidClass(){
33+
$form = Form::create('id', function($f){}, ['layout' => new stdClass]);
34+
}
35+
836
public function testHttpMethodDefault(){
937
$mock = new MockLayout();
1038
$form = Form::create('id', function($f){}, ['layout' => $mock]);

0 commit comments

Comments
 (0)