From 9910519aba26c96d70b7a137b1682045b0273f57 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 1 Oct 2018 01:04:11 +0300 Subject: [PATCH] Revert "Fixes #16657: Ensure widgets after run event result contains the result of the rendered widget" This reverts commit 7dc38ff4029ec96931c574dac430a924370ea039. --- framework/CHANGELOG.md | 2 ++ framework/grid/GridView.php | 4 +-- framework/widgets/BaseListView.php | 2 +- framework/widgets/Block.php | 2 +- framework/widgets/Breadcrumbs.php | 2 +- framework/widgets/ContentDecorator.php | 2 +- framework/widgets/DetailView.php | 2 +- framework/widgets/FragmentCache.php | 4 +-- framework/widgets/LinkPager.php | 2 +- framework/widgets/LinkSorter.php | 2 +- framework/widgets/MaskedInput.php | 2 +- framework/widgets/Menu.php | 2 +- framework/widgets/Pjax.php | 6 ++--- framework/widgets/Spaceless.php | 4 +-- tests/framework/grid/RadiobuttonColumnTest.php | 2 +- tests/framework/widgets/BlockTest.php | 20 -------------- tests/framework/widgets/BreadcrumbsTest.php | 24 +++-------------- tests/framework/widgets/ContentDecoratorTest.php | 21 --------------- tests/framework/widgets/DetailViewTest.php | 19 -------------- tests/framework/widgets/LinkPagerTest.php | 16 ------------ tests/framework/widgets/LinkSorterTest.php | 28 -------------------- tests/framework/widgets/ListViewTest.php | 33 ++++++------------------ tests/framework/widgets/MenuTest.php | 30 --------------------- tests/framework/widgets/PjaxTest.php | 15 ----------- tests/framework/widgets/SpacelessTest.php | 16 ------------ 25 files changed, 33 insertions(+), 229 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e071a95..a1cb746 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -10,6 +10,8 @@ Yii Framework 2 Change Log - Enh #16151: `ActiveQuery::getTableNameAndAlias()` is now protected (s1lver) - Bug #16657: Ensure widgets after run event result contains the result of the rendered widget (AdeAttwood) - Bug #14230: Fixed `itemsOptions` ignored in `checkBoxList` and `radioList` (s1lver) +- Enh #16151: Change of scope for method `getTableNameAndAlias()` (s1lver) +- Bug #14230: Fixed `itemsOptions` ignored in `checkBoxList` (s1lver) - Bug #14368: Added `role` attribute for active radio list (s1lver) - Bug #16680: Fixed ActiveField 'text' input with maxlength (s1lver) - Bug #5341: HasMany via two relations (shirase, cebe) diff --git a/framework/grid/GridView.php b/framework/grid/GridView.php index a900ba1..6de342d 100644 --- a/framework/grid/GridView.php +++ b/framework/grid/GridView.php @@ -298,7 +298,7 @@ class GridView extends BaseListView $id = $this->options['id']; $options = Json::htmlEncode(array_merge($this->getClientOptions(), ['filterOnFocusOut' => $this->filterOnFocusOut])); $view->registerJs("jQuery('#$id').yiiGridView($options);"); - return parent::run(); + parent::run(); } /** @@ -359,7 +359,7 @@ class GridView extends BaseListView $tableFooter = false; $tableFooterAfterBody = false; - + if ($this->showFooter) { if ($this->placeFooterAfterBody) { $tableFooterAfterBody = $this->renderTableFooter(); diff --git a/framework/widgets/BaseListView.php b/framework/widgets/BaseListView.php index d0db864..88686e8 100644 --- a/framework/widgets/BaseListView.php +++ b/framework/widgets/BaseListView.php @@ -142,7 +142,7 @@ abstract class BaseListView extends Widget $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'div'); - return Html::tag($tag, $content, $options); + echo Html::tag($tag, $content, $options); } /** diff --git a/framework/widgets/Block.php b/framework/widgets/Block.php index c91c6fa..72e76d6 100644 --- a/framework/widgets/Block.php +++ b/framework/widgets/Block.php @@ -64,7 +64,7 @@ class Block extends Widget { $block = ob_get_clean(); if ($this->renderInPlace) { - return $block; + echo $block; } $this->view->blocks[$this->getId()] = $block; } diff --git a/framework/widgets/Breadcrumbs.php b/framework/widgets/Breadcrumbs.php index 95bd294..b56aa0f 100644 --- a/framework/widgets/Breadcrumbs.php +++ b/framework/widgets/Breadcrumbs.php @@ -147,7 +147,7 @@ class Breadcrumbs extends Widget } $links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate); } - return Html::tag($this->tag, implode('', $links), $this->options); + echo Html::tag($this->tag, implode('', $links), $this->options); } /** diff --git a/framework/widgets/ContentDecorator.php b/framework/widgets/ContentDecorator.php index 31b90ef..e926e9a 100644 --- a/framework/widgets/ContentDecorator.php +++ b/framework/widgets/ContentDecorator.php @@ -76,6 +76,6 @@ class ContentDecorator extends Widget $params = $this->params; $params['content'] = ob_get_clean(); // render under the existing context - return $this->view->renderFile($this->viewFile, $params); + echo $this->view->renderFile($this->viewFile, $params); } } diff --git a/framework/widgets/DetailView.php b/framework/widgets/DetailView.php index 4e53f2b..62e0987 100644 --- a/framework/widgets/DetailView.php +++ b/framework/widgets/DetailView.php @@ -161,7 +161,7 @@ class DetailView extends Widget $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'table'); - return Html::tag($tag, implode("\n", $rows), $options); + echo Html::tag($tag, implode("\n", $rows), $options); } /** diff --git a/framework/widgets/FragmentCache.php b/framework/widgets/FragmentCache.php index e82b9de..d9bed1f 100644 --- a/framework/widgets/FragmentCache.php +++ b/framework/widgets/FragmentCache.php @@ -101,7 +101,7 @@ class FragmentCache extends Widget implements DynamicContentAwareInterface public function run() { if (($content = $this->getCachedContent()) !== false) { - return $content; + echo $content; } elseif ($this->cache instanceof CacheInterface) { $this->getView()->popDynamicContent(); @@ -114,7 +114,7 @@ class FragmentCache extends Widget implements DynamicContentAwareInterface } $data = [$content, $this->getDynamicPlaceholders()]; $this->cache->set($this->calculateKey(), $data, $this->duration, $this->dependency); - return $this->updateDynamicContent($content, $this->getDynamicPlaceholders()); + echo $this->updateDynamicContent($content, $this->getDynamicPlaceholders()); } } diff --git a/framework/widgets/LinkPager.php b/framework/widgets/LinkPager.php index d4c6bcb..8fc7cf5 100644 --- a/framework/widgets/LinkPager.php +++ b/framework/widgets/LinkPager.php @@ -155,7 +155,7 @@ class LinkPager extends Widget if ($this->registerLinkTags) { $this->registerLinkTags(); } - return $this->renderPageButtons(); + echo $this->renderPageButtons(); } /** diff --git a/framework/widgets/LinkSorter.php b/framework/widgets/LinkSorter.php index f898cff..a0e9599 100644 --- a/framework/widgets/LinkSorter.php +++ b/framework/widgets/LinkSorter.php @@ -66,7 +66,7 @@ class LinkSorter extends Widget */ public function run() { - return $this->renderSortLinks(); + echo $this->renderSortLinks(); } /** diff --git a/framework/widgets/MaskedInput.php b/framework/widgets/MaskedInput.php index 4923c25..8208e13 100644 --- a/framework/widgets/MaskedInput.php +++ b/framework/widgets/MaskedInput.php @@ -124,7 +124,7 @@ class MaskedInput extends InputWidget public function run() { $this->registerClientScript(); - return $this->renderInputHtml($this->type); + echo $this->renderInputHtml($this->type); } /** diff --git a/framework/widgets/Menu.php b/framework/widgets/Menu.php index a2139b6..6efaa7e 100644 --- a/framework/widgets/Menu.php +++ b/framework/widgets/Menu.php @@ -182,7 +182,7 @@ class Menu extends Widget $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'ul'); - return Html::tag($tag, $this->renderItems($items), $options); + echo Html::tag($tag, $this->renderItems($items), $options); } } diff --git a/framework/widgets/Pjax.php b/framework/widgets/Pjax.php index 36438a6..2a93f9c 100644 --- a/framework/widgets/Pjax.php +++ b/framework/widgets/Pjax.php @@ -127,12 +127,12 @@ class Pjax extends Widget $view->head(); $view->beginBody(); if ($view->title !== null) { - return Html::tag('title', Html::encode($view->title)); + echo Html::tag('title', Html::encode($view->title)); } } else { $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'div'); - return Html::beginTag($tag, array_merge([ + echo Html::beginTag($tag, array_merge([ 'data-pjax-container' => '', 'data-pjax-push-state' => $this->enablePushState, 'data-pjax-replace-state' => $this->enableReplaceState, @@ -148,7 +148,7 @@ class Pjax extends Widget public function run() { if (!$this->requiresPjax()) { - return Html::endTag(ArrayHelper::remove($this->options, 'tag', 'div')); + echo Html::endTag(ArrayHelper::remove($this->options, 'tag', 'div')); $this->registerClientScript(); return; diff --git a/framework/widgets/Spaceless.php b/framework/widgets/Spaceless.php index 097295a..e109e1f 100644 --- a/framework/widgets/Spaceless.php +++ b/framework/widgets/Spaceless.php @@ -61,10 +61,10 @@ class Spaceless extends Widget /** * Marks the end of content to be cleaned from whitespace characters between HTML tags. - * Stops capturing an output and returns cleaned result. + * Stops capturing an output and echoes cleaned result. */ public function run() { - return trim(preg_replace('/>\s+<', ob_get_clean())); + echo trim(preg_replace('/>\s+<', ob_get_clean())); } } diff --git a/tests/framework/grid/RadiobuttonColumnTest.php b/tests/framework/grid/RadiobuttonColumnTest.php index c10b6f9..b0f2711 100644 --- a/tests/framework/grid/RadiobuttonColumnTest.php +++ b/tests/framework/grid/RadiobuttonColumnTest.php @@ -105,7 +105,7 @@ class RadiobuttonColumnTest extends TestCase ], ]); ob_start(); - echo $grid->run(); + $grid->run(); $actual = ob_get_clean(); $this->assertEqualsWithoutLE(<<<'HTML'
Showing 1-2 of 2 items.
diff --git a/tests/framework/widgets/BlockTest.php b/tests/framework/widgets/BlockTest.php index fa0eda4..318c82a 100644 --- a/tests/framework/widgets/BlockTest.php +++ b/tests/framework/widgets/BlockTest.php @@ -40,24 +40,4 @@ class BlockTest extends \yiiunit\TestCase $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - Block::begin([ - 'renderInPlace' => true, - 'on afterRun' => function($event) use (&$result) { - $result = $event->result; - }, - ]); - - echo 'The Block'; - - Block::end(); - ob_end_clean(); - - $this->assertEquals('The Block', $result); - } } diff --git a/tests/framework/widgets/BreadcrumbsTest.php b/tests/framework/widgets/BreadcrumbsTest.php index 0fc2cb0..a5a76e8 100644 --- a/tests/framework/widgets/BreadcrumbsTest.php +++ b/tests/framework/widgets/BreadcrumbsTest.php @@ -41,7 +41,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase . ''; ob_start(); - echo $this->breadcrumbs->run(); + $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); @@ -63,7 +63,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase . ''; ob_start(); - echo $this->breadcrumbs->run(); + $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); @@ -82,7 +82,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase . ''; ob_start(); - echo $this->breadcrumbs->run(); + $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); @@ -180,29 +180,13 @@ class BreadcrumbsTest extends \yiiunit\TestCase . "http://my.example.com/yii2/link/page\n"; ob_start(); - echo $this->breadcrumbs->run(); + $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); $this->assertEquals($expectedHtml, $actualHtml); } - public function testAfterRunResultNotEmpty() - { - $result = null; - Breadcrumbs::widget([ - 'links' => [ - ['label' => 'Sample Post', 'url' => 'post/edit'], - 'Edit', - ], - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - - $this->assertNotNull($result); - } - /** * Helper methods. * @param string $class diff --git a/tests/framework/widgets/ContentDecoratorTest.php b/tests/framework/widgets/ContentDecoratorTest.php index 415f83e..ed23c92 100644 --- a/tests/framework/widgets/ContentDecoratorTest.php +++ b/tests/framework/widgets/ContentDecoratorTest.php @@ -41,25 +41,4 @@ class ContentDecoratorTest extends \yiiunit\TestCase $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - ContentDecorator::begin([ - 'viewFile' => '@yiiunit/data/views/layout.php', - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - - echo 'The Content'; - - ContentDecorator::end(); - ob_end_clean(); - - $this->assertContains('The Content', $result); - $this->assertContains('Test', $result); - } } diff --git a/tests/framework/widgets/DetailViewTest.php b/tests/framework/widgets/DetailViewTest.php index 8d23e35..19ca733 100644 --- a/tests/framework/widgets/DetailViewTest.php +++ b/tests/framework/widgets/DetailViewTest.php @@ -334,25 +334,6 @@ class DetailViewTest extends \yiiunit\TestCase $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - $model = new ModelMock(); - $model->id = 1; - - ob_start(); - DetailView::widget([ - 'model' => $model, - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } } /** diff --git a/tests/framework/widgets/LinkPagerTest.php b/tests/framework/widgets/LinkPagerTest.php index 6c97161..2f921c5 100644 --- a/tests/framework/widgets/LinkPagerTest.php +++ b/tests/framework/widgets/LinkPagerTest.php @@ -160,20 +160,4 @@ class LinkPagerTest extends \yiiunit\TestCase $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - LinkPager::widget([ - 'pagination' => $this->getPagination(1), - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } } diff --git a/tests/framework/widgets/LinkSorterTest.php b/tests/framework/widgets/LinkSorterTest.php index 4ceb8ba..ae1a75e 100644 --- a/tests/framework/widgets/LinkSorterTest.php +++ b/tests/framework/widgets/LinkSorterTest.php @@ -100,32 +100,4 @@ class LinkSorterTest extends DatabaseTestCase $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - $dataProvider = new ActiveDataProvider([ - 'query' => Order::find(), - 'models' => [new Order()], - 'totalCount' => 1, - 'sort' => [ - 'attributes' => ['total'], - 'route' => 'site/index', - ], - ]); - - ob_start(); - echo ListView::widget([ - 'dataProvider' => $dataProvider, - 'layout' => '{sorter}', - 'sorter' => [ - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ] - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } } diff --git a/tests/framework/widgets/ListViewTest.php b/tests/framework/widgets/ListViewTest.php index 56d1cea..beb5268 100644 --- a/tests/framework/widgets/ListViewTest.php +++ b/tests/framework/widgets/ListViewTest.php @@ -26,7 +26,7 @@ class ListViewTest extends TestCase public function testEmptyListShown() { ob_start(); - echo $this->getListView([ + $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'emptyText' => 'Nothing at all', ])->run(); @@ -38,7 +38,7 @@ class ListViewTest extends TestCase public function testEmpty() { ob_start(); - echo $this->getListView([ + $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'emptyText' => false, ])->run(); @@ -50,7 +50,7 @@ class ListViewTest extends TestCase public function testEmptyListNotShown() { ob_start(); - echo $this->getListView([ + $this->getListView([ 'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'showOnEmpty' => true, ])->run(); @@ -93,7 +93,7 @@ HTML public function testSimplyListView() { ob_start(); - echo $this->getListView()->run(); + $this->getListView()->run(); $out = ob_get_clean(); $this->assertEqualsWithoutLE(<<<'HTML' @@ -109,7 +109,7 @@ HTML public function testWidgetOptions() { ob_start(); - echo $this->getListView(['options' => ['class' => 'test-passed'], 'separator' => ''])->run(); + $this->getListView(['options' => ['class' => 'test-passed'], 'separator' => ''])->run(); $out = ob_get_clean(); $this->assertEqualsWithoutLE(<<<'HTML' @@ -160,7 +160,7 @@ HTML public function testItemViewOptions($itemView, $expected) { ob_start(); - echo $this->getListView(['itemView' => $itemView])->run(); + $this->getListView(['itemView' => $itemView])->run(); $out = ob_get_clean(); $this->assertEqualsWithoutLE($expected, $out); @@ -206,7 +206,7 @@ HTML public function testItemOptions($itemOptions, $expected) { ob_start(); - echo $this->getListView(['itemOptions' => $itemOptions])->run(); + $this->getListView(['itemOptions' => $itemOptions])->run(); $out = ob_get_clean(); $this->assertEqualsWithoutLE($expected, $out); @@ -227,7 +227,7 @@ HTML }; ob_start(); - echo $this->getListView([ + $this->getListView([ 'beforeItem' => $before, 'afterItem' => $after, ])->run(); @@ -263,21 +263,4 @@ HTML ]); $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - ListView::widget([ - 'id' => 'w0', - 'dataProvider' => $this->getDataProvider(), - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } } diff --git a/tests/framework/widgets/MenuTest.php b/tests/framework/widgets/MenuTest.php index dce2b38..70e8446 100644 --- a/tests/framework/widgets/MenuTest.php +++ b/tests/framework/widgets/MenuTest.php @@ -302,36 +302,6 @@ HTML; $this->assertEqualsWithoutLE($expected, $output); } - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - Menu::widget([ - 'route' => 'test/test', - 'params' => [], - 'encodeLabels' => true, - 'items' => [ - [ - 'encode' => false, - 'label' => ' Users', - 'url' => '#', - ], - [ - 'encode' => true, - 'label' => 'Authors & Publications', - 'url' => '#', - ], - ], - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } - /*public function testIsItemActive() { // TODO: implement test of protected method isItemActive() diff --git a/tests/framework/widgets/PjaxTest.php b/tests/framework/widgets/PjaxTest.php index 73e8fe8..4af4979 100644 --- a/tests/framework/widgets/PjaxTest.php +++ b/tests/framework/widgets/PjaxTest.php @@ -56,19 +56,4 @@ class PjaxTest extends TestCase ob_end_clean(); $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - Pjax::widget([ - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - ob_end_clean(); - - $this->assertNotNull($result); - } } diff --git a/tests/framework/widgets/SpacelessTest.php b/tests/framework/widgets/SpacelessTest.php index 3b20b90..577f47c 100644 --- a/tests/framework/widgets/SpacelessTest.php +++ b/tests/framework/widgets/SpacelessTest.php @@ -60,20 +60,4 @@ class SpacelessTest extends \yiiunit\TestCase Spaceless::end(); $this->assertTrue($initTriggered); } - - public function testAfterRunResultNotEmpty() - { - $result = null; - - ob_start(); - Spaceless::begin([ - 'on afterRun' => function ($event) use (&$result) { - $result = $event->result; - }, - ]); - Spaceless::end(); - ob_end_clean(); - - $this->assertNotNull($result); - } }