From 608066b05f79f33479aa6f4400e9892c567ab38b Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 28 Mar 2016 04:54:52 +0200 Subject: [PATCH] fixed ActiveForm tests for output buffering related to #8779, and 7dc984d35928128b3612fb6aa4ed19b03ee963fd --- framework/widgets/ActiveForm.php | 1 + tests/framework/widgets/ActiveFieldTest.php | 5 +-- tests/framework/widgets/ActiveFormTest.php | 36 +++++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index df76cab2e2..c92cbcf8d7 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -179,6 +179,7 @@ class ActiveForm extends Widget $this->options['id'] = $this->getId(); } ob_start(); + ob_implicit_flush(false); } /** diff --git a/tests/framework/widgets/ActiveFieldTest.php b/tests/framework/widgets/ActiveFieldTest.php index 073368f490..0b555adec5 100644 --- a/tests/framework/widgets/ActiveFieldTest.php +++ b/tests/framework/widgets/ActiveFieldTest.php @@ -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']); } /** diff --git a/tests/framework/widgets/ActiveFormTest.php b/tests/framework/widgets/ActiveFormTest.php index ac3a4f232d..26e0ad51b9 100644 --- a/tests/framework/widgets/ActiveFormTest.php +++ b/tests/framework/widgets/ActiveFormTest.php @@ -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(<<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 +, $content); + + } }