mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
fixed ActiveForm tests for output buffering
related to #8779, and 7dc984d35928128b3612fb6aa4ed19b03ee963fd
This commit is contained in:
@ -179,6 +179,7 @@ class ActiveForm extends Widget
|
||||
$this->options['id'] = $this->getId();
|
||||
}
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,8 @@ class ActiveFieldTest extends \yiiunit\TestCase
|
||||
|
||||
$this->helperModel = new DynamicModel(['attributeName']);
|
||||
ob_start();
|
||||
$this->helperForm = new ActiveForm(['action' => '/something']);
|
||||
$this->helperForm = ActiveForm::begin(['action' => '/something', 'enableClientScript' => false]);
|
||||
ActiveForm::end();
|
||||
ob_end_clean();
|
||||
|
||||
$this->activeField = new ActiveFieldExtend(true);
|
||||
@ -347,7 +348,7 @@ EOD;
|
||||
public function testEnctype()
|
||||
{
|
||||
$this->activeField->fileInput();
|
||||
$this->assertEqualsWithoutLE('multipart/form-data', $this->activeField->form->options['enctype']);
|
||||
$this->assertEquals('multipart/form-data', $this->activeField->form->options['enctype']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,8 @@ class ActiveFormTest extends \yiiunit\TestCase
|
||||
|
||||
$model = new DynamicModel(['name']);
|
||||
ob_start();
|
||||
$form = new ActiveForm(['action' => '/something']);
|
||||
$form = ActiveForm::begin(['action' => '/something', 'enableClientScript' => false]);
|
||||
ActiveForm::end();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEqualsWithoutLE(<<<EOF
|
||||
@ -59,7 +60,8 @@ EOF
|
||||
$model = new DynamicModel(['categories']);
|
||||
$model->categories = 1;
|
||||
ob_start();
|
||||
$form = new ActiveForm(['action' => '/something']);
|
||||
$form = ActiveForm::begin(['action' => '/something', 'enableClientScript' => false]);
|
||||
ActiveForm::end();
|
||||
ob_end_clean();
|
||||
|
||||
// https://github.com/yiisoft/yii2/issues/5356
|
||||
@ -74,4 +76,34 @@ EOF
|
||||
EOF
|
||||
, (string) $form->field($model, 'categories', $o)->listBox(['apple', 'banana', 'avocado'], ['multiple' => true]));
|
||||
}
|
||||
|
||||
public function testOutputBuffering()
|
||||
{
|
||||
$obLevel = ob_get_level();
|
||||
ob_start();
|
||||
|
||||
$model = new DynamicModel(['name']);
|
||||
|
||||
$form = ActiveForm::begin(['id' => 'someform', 'action' => '/someform', 'enableClientScript' => false]);
|
||||
echo "\n" . $form->field($model, 'name') . "\n";
|
||||
ActiveForm::end();
|
||||
|
||||
$content = ob_get_clean();
|
||||
//ob_end_clean();
|
||||
|
||||
$this->assertEquals($obLevel, ob_get_level(), 'Output buffers not closed correctly.');
|
||||
|
||||
$this->assertEqualsWithoutLE(<<<HTML
|
||||
<form id="someform" action="/someform" method="post">
|
||||
<div class="form-group field-dynamicmodel-name">
|
||||
<label class="control-label" for="dynamicmodel-name">Name</label>
|
||||
<input type="text" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
|
||||
|
||||
<div class="help-block"></div>
|
||||
</div>
|
||||
</form>
|
||||
HTML
|
||||
, $content);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user