Browse Source

Revert "Fixes #16657: Ensure widgets after run event result contains the result of the rendered widget"

This reverts commit 7dc38ff402.
tags/2.0.16
Alexander Makarov 6 years ago
parent
commit
9910519aba
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 2
      framework/CHANGELOG.md
  2. 4
      framework/grid/GridView.php
  3. 2
      framework/widgets/BaseListView.php
  4. 2
      framework/widgets/Block.php
  5. 2
      framework/widgets/Breadcrumbs.php
  6. 2
      framework/widgets/ContentDecorator.php
  7. 2
      framework/widgets/DetailView.php
  8. 4
      framework/widgets/FragmentCache.php
  9. 2
      framework/widgets/LinkPager.php
  10. 2
      framework/widgets/LinkSorter.php
  11. 2
      framework/widgets/MaskedInput.php
  12. 2
      framework/widgets/Menu.php
  13. 6
      framework/widgets/Pjax.php
  14. 4
      framework/widgets/Spaceless.php
  15. 2
      tests/framework/grid/RadiobuttonColumnTest.php
  16. 20
      tests/framework/widgets/BlockTest.php
  17. 24
      tests/framework/widgets/BreadcrumbsTest.php
  18. 21
      tests/framework/widgets/ContentDecoratorTest.php
  19. 19
      tests/framework/widgets/DetailViewTest.php
  20. 16
      tests/framework/widgets/LinkPagerTest.php
  21. 28
      tests/framework/widgets/LinkSorterTest.php
  22. 33
      tests/framework/widgets/ListViewTest.php
  23. 30
      tests/framework/widgets/MenuTest.php
  24. 15
      tests/framework/widgets/PjaxTest.php
  25. 16
      tests/framework/widgets/SpacelessTest.php

2
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)

4
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();

2
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);
}
/**

2
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;
}

2
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);
}
/**

2
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);
}
}

2
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);
}
/**

4
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());
}
}

2
framework/widgets/LinkPager.php

@ -155,7 +155,7 @@ class LinkPager extends Widget
if ($this->registerLinkTags) {
$this->registerLinkTags();
}
return $this->renderPageButtons();
echo $this->renderPageButtons();
}
/**

2
framework/widgets/LinkSorter.php

@ -66,7 +66,7 @@ class LinkSorter extends Widget
*/
public function run()
{
return $this->renderSortLinks();
echo $this->renderSortLinks();
}
/**

2
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);
}
/**

2
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);
}
}

6
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;

4
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()));
}
}

2
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'
<div id="radio-gridview"><div class="summary">Showing <b>1-2</b> of <b>2</b> items.</div>

20
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);
}
}

24
tests/framework/widgets/BreadcrumbsTest.php

@ -41,7 +41,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase
. '</ul>';
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
. '</ul>';
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
. '</ul>';
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

21
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('<title>Test</title>', $result);
}
}

19
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);
}
}
/**

16
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);
}
}

28
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);
}
}

33
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);
}
}

30
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' => '<span class="glyphicon glyphicon-user"></span> 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()

15
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);
}
}

16
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);
}
}

Loading…
Cancel
Save