|
@@ -143,4 +143,91 @@ class CollectionFormTest extends TypeTestCase
|
|
|
|
|
|
$this->assertFalse($form->has('$$name$$'));
|
|
|
}
|
|
|
+
|
|
|
+ public function testSetTypeOptions()
|
|
|
+ {
|
|
|
+ $form = $this->factory->create('collection', null, array(
|
|
|
+ 'type' => 'field',
|
|
|
+ 'type_options' => array(
|
|
|
+ 'required' => false,
|
|
|
+ 'max_length' => 20
|
|
|
+ ),
|
|
|
+ ));
|
|
|
+ $form->setData(array('foo@foo.com', 'foo@bar.com'));
|
|
|
+
|
|
|
+ $this->assertFalse($form[0]->isRequired());
|
|
|
+ $this->assertFalse($form[1]->isRequired());
|
|
|
+ $this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ $form->bind(array('foo@bar.com', 'bar@foo.com'));
|
|
|
+
|
|
|
+ $this->assertFalse($form[0]->isRequired());
|
|
|
+ $this->assertFalse($form[1]->isRequired());
|
|
|
+ $this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ //Test with prototype and extra field
|
|
|
+ $form = $this->factory->create('collection', null, array(
|
|
|
+ 'allow_add' => true,
|
|
|
+ 'prototype' => true,
|
|
|
+ 'type' => 'field',
|
|
|
+ 'type_options' => array(
|
|
|
+ 'required' => false,
|
|
|
+ 'max_length' => 20
|
|
|
+ ),
|
|
|
+ ));
|
|
|
+
|
|
|
+ $form->setData(array('foo@foo.com'));
|
|
|
+
|
|
|
+ $this->assertFalse($form[0]->isRequired());
|
|
|
+ $this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ $form->bind(array('foo@bar.com', 'bar@foo.com'));
|
|
|
+
|
|
|
+ $this->assertFalse($form[0]->isRequired());
|
|
|
+ $this->assertFalse($form[1]->isRequired());
|
|
|
+ $this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSetTypeOptionsWithoutOptions()
|
|
|
+ {
|
|
|
+ $form = $this->factory->create('collection', null, array(
|
|
|
+ 'type' => 'field',
|
|
|
+ ));
|
|
|
+ $form->setData(array('foo@foo.com', 'foo@bar.com'));
|
|
|
+
|
|
|
+ $this->assertTrue($form[0]->isRequired());
|
|
|
+ $this->assertTrue($form[1]->isRequired());
|
|
|
+ $this->assertNull($form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertNull($form[1]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ $form->bind(array('foo@bar.com', 'bar@foo.com'));
|
|
|
+
|
|
|
+ $this->assertTrue($form[0]->isRequired());
|
|
|
+ $this->assertTrue($form[1]->isRequired());
|
|
|
+ $this->assertNull($form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertNull($form[1]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ //Test with prototype and extra field
|
|
|
+ $form = $this->factory->create('collection', null, array(
|
|
|
+ 'allow_add' => true,
|
|
|
+ 'prototype' => true,
|
|
|
+ 'type' => 'field',
|
|
|
+ ));
|
|
|
+
|
|
|
+ $form->setData(array('foo@foo.com'));
|
|
|
+
|
|
|
+ $this->assertTrue($form[0]->isRequired());
|
|
|
+ $this->assertNull($form[0]->getAttribute('max_length'));
|
|
|
+
|
|
|
+ $form->bind(array('foo@bar.com', 'bar@foo.com'));
|
|
|
+
|
|
|
+ $this->assertTrue($form[0]->isRequired());
|
|
|
+ $this->assertTrue($form[1]->isRequired());
|
|
|
+ $this->assertNull($form[0]->getAttribute('max_length'));
|
|
|
+ $this->assertNull($form[1]->getAttribute('max_length'));
|
|
|
+ }
|
|
|
}
|