|
|
@@ -4107,6 +4107,37 @@ class FormHelperTest extends TestCase
|
|
|
$result = $this->Form->text('Model.field', ['default' => 'default value']);
|
|
|
$expected = ['input' => ['type' => 'text', 'name' => 'Model[field]', 'value' => 'default value']];
|
|
|
$this->assertHtml($expected, $result);
|
|
|
+
|
|
|
+ $Articles = TableRegistry::get('Articles');
|
|
|
+ $title = $Articles->schema()->column('title');
|
|
|
+ $Articles->schema()->addColumn(
|
|
|
+ 'title',
|
|
|
+ ['default' => 'default title'] + $title
|
|
|
+ );
|
|
|
+
|
|
|
+ $entity = $Articles->newEntity();
|
|
|
+ $this->Form->create($entity);
|
|
|
+
|
|
|
+ // Get default value from schema
|
|
|
+ $result = $this->Form->text('title');
|
|
|
+ $expected = ['input' => ['type' => 'text', 'name' => 'title', 'value' => 'default title']];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+
|
|
|
+ // Don't get value from schema
|
|
|
+ $result = $this->Form->text('title', ['schemaDefault' => false]);
|
|
|
+ $expected = ['input' => ['type' => 'text', 'name' => 'title']];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+
|
|
|
+ // Custom default value overrides default value from schema
|
|
|
+ $result = $this->Form->text('title', ['default' => 'override default']);
|
|
|
+ $expected = ['input' => ['type' => 'text', 'name' => 'title', 'value' => 'override default']];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+
|
|
|
+ // Default value from schema is used only for new entities.
|
|
|
+ $entity->isNew(false);
|
|
|
+ $result = $this->Form->text('title');
|
|
|
+ $expected = ['input' => ['type' => 'text', 'name' => 'title']];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -4317,6 +4348,37 @@ class FormHelperTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Test default value setting on radio() method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testRadioDefaultValue()
|
|
|
+ {
|
|
|
+ $Articles = TableRegistry::get('Articles');
|
|
|
+ $title = $Articles->schema()->column('title');
|
|
|
+ $Articles->schema()->addColumn(
|
|
|
+ 'title',
|
|
|
+ ['default' => '1'] + $title
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->Form->create($Articles->newEntity());
|
|
|
+
|
|
|
+ $result = $this->Form->radio('title', ['option A', 'option B']);
|
|
|
+ $expected = [
|
|
|
+ ['input' => ['type' => 'hidden', 'name' => 'title', 'value' => '']],
|
|
|
+ ['label' => ['for' => 'title-0']],
|
|
|
+ ['input' => ['type' => 'radio', 'name' => 'title', 'value' => '0', 'id' => 'title-0']],
|
|
|
+ 'option A',
|
|
|
+ '/label',
|
|
|
+ ['label' => ['for' => 'title-1']],
|
|
|
+ ['input' => ['type' => 'radio', 'name' => 'title', 'value' => '1', 'id' => 'title-1', 'checked' => 'checked']],
|
|
|
+ 'option B',
|
|
|
+ '/label',
|
|
|
+ ];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Test that input works with radio types
|
|
|
*
|
|
|
* @return void
|
|
|
@@ -5385,6 +5447,17 @@ class FormHelperTest extends TestCase
|
|
|
$result = $this->Form->checkbox('Model.field', ['default' => false, 'hiddenField' => false]);
|
|
|
$expected = ['input' => ['type' => 'checkbox', 'name' => 'Model[field]', 'value' => '1']];
|
|
|
$this->assertHtml($expected, $result);
|
|
|
+
|
|
|
+ $Articles = TableRegistry::get('Articles');
|
|
|
+ $Articles->schema()->addColumn(
|
|
|
+ 'published',
|
|
|
+ ['type' => 'boolean', 'null' => false, 'default' => true]
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->Form->create($Articles->newEntity());
|
|
|
+ $result = $this->Form->checkbox('published', ['hiddenField' => false]);
|
|
|
+ $expected = ['input' => ['type' => 'checkbox', 'name' => 'published', 'value' => '1', 'checked' => 'checked']];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
}
|
|
|
|
|
|
/**
|