Skip to content

Commit

Permalink
Fixes yiisoft#15536: Fixed yii\widgets\ActiveForm::init() for call …
Browse files Browse the repository at this point in the history
…`parent::init()`
  • Loading branch information
Alone authored and samdark committed Jan 24, 2018
1 parent 3d27ab3 commit 08eccb6
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 0 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.14 under development
------------------------

- Bug #15536: Fixed `yii\widgets\ActiveForm::init()` for call `parent::init()` (panchenkodv)
- Enh #14806: Added $placeFooterAfterBody option for GridView (terehru)
- Bug #14711: Fixed `yii\web\ErrorHandler` displaying exception message in non-debug mode (samdark)
- Enh #13814: MySQL unique index names can now contain spaces (df2)
Expand Down
1 change: 1 addition & 0 deletions framework/widgets/ActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class ActiveForm extends Widget
*/
public function init()
{
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
Expand Down
2 changes: 2 additions & 0 deletions framework/widgets/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Block extends Widget
*/
public function init()
{
parent::init();

ob_start();
ob_implicit_flush(false);
}
Expand Down
2 changes: 2 additions & 0 deletions framework/widgets/ContentDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ContentDecorator extends Widget
*/
public function init()
{
parent::init();

if ($this->viewFile === null) {
throw new InvalidConfigException('ContentDecorator::viewFile must be set.');
}
Expand Down
2 changes: 2 additions & 0 deletions framework/widgets/DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class DetailView extends Widget
*/
public function init()
{
parent::init();

if ($this->model === null) {
throw new InvalidConfigException('Please specify the "model" property.');
}
Expand Down
2 changes: 2 additions & 0 deletions framework/widgets/LinkPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class LinkPager extends Widget
*/
public function init()
{
parent::init();

if ($this->pagination === null) {
throw new InvalidConfigException('The "pagination" property must be set.');
}
Expand Down
2 changes: 2 additions & 0 deletions framework/widgets/LinkSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class LinkSorter extends Widget
*/
public function init()
{
parent::init();

if ($this->sort === null) {
throw new InvalidConfigException('The "sort" property must be set.');
}
Expand Down
1 change: 1 addition & 0 deletions framework/widgets/Pjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Pjax extends Widget
*/
public function init()
{
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
Expand Down
1 change: 1 addition & 0 deletions framework/widgets/Spaceless.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Spaceless extends Widget
*/
public function init()
{
parent::init();
ob_start();
ob_implicit_flush(false);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/framework/widgets/ActiveFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,23 @@ public function testRegisterClientScript()
$form::end();
ob_get_clean();
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$form = ActiveForm::begin(
[
'action' => '/something',
'enableClientScript' => false,
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);
ActiveForm::end();
$this->assertTrue($initTriggered);
}
}
43 changes: 43 additions & 0 deletions tests/framework/widgets/BlockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yiiunit\framework\widgets;

use yii\widgets\Block;

/**
* @group widgets
*/
class BlockTest extends \yiiunit\TestCase
{
protected function setUp()
{
parent::setUp();

$this->mockWebApplication();
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;

$block = new Block(
[
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);

ob_get_clean();

$this->assertTrue($initTriggered);
}
}
44 changes: 44 additions & 0 deletions tests/framework/widgets/ContentDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yiiunit\framework\widgets;

use yii\widgets\ContentDecorator;

/**
* @group widgets
*/
class ContentDecoratorTest extends \yiiunit\TestCase
{
protected function setUp()
{
parent::setUp();

$this->mockWebApplication();
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;

$contentDecorator = new ContentDecorator(
[
'viewFile' => '@app/views/layouts/base.php',
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);

ob_get_clean();

$this->assertTrue($initTriggered);
}
}
20 changes: 20 additions & 0 deletions tests/framework/widgets/DetailViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ public function testOptionsTags()
$this->assertEquals($expectedValue, $a);
}
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$model = new ModelMock();
$model->id = 1;
$model->text = 'I`m an object';

$this->detailView = new DetailView([
'model' => $model,
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]);

$this->assertTrue($initTriggered);
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/framework/widgets/LinkPagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,20 @@ public function testLinkWrapOptions()
$output
);
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$output = LinkPager::widget([
'pagination' => $this->getPagination(1),
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]);

$this->assertTrue($initTriggered);
}
}
22 changes: 22 additions & 0 deletions tests/framework/widgets/LinkSorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use yii\data\ActiveDataProvider;
use yii\widgets\Breadcrumbs;
use yii\widgets\LinkSorter;
use yii\widgets\ListView;
use yiiunit\data\ar\ActiveRecord;
use yiiunit\data\ar\Order;
Expand Down Expand Up @@ -78,4 +79,25 @@ public function testLabelsExplicit()
$this->assertNotFalse(strpos($actualHtml,
'<a href="/index.php?r=site%2Findex&amp;sort=total" data-sort="total">Invoice Total</a>'));
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$linkSorter = new LinkSorter(
[
'sort' => [
'attributes' => ['total'],
'route' => 'site/index',
],
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);

$this->assertTrue($initTriggered);
}
}
17 changes: 17 additions & 0 deletions tests/framework/widgets/PjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ protected function setUp()
parent::setUp();
$this->mockWebApplication();
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$pjax = new Pjax(
[
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);

$this->assertTrue($initTriggered);
}
}
17 changes: 17 additions & 0 deletions tests/framework/widgets/SpacelessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ public function testWidget()
"</div><div class='right-column'><p>This is a right bar!</p></div></div>\t<p>Bye!</p>\n</body>\n";
$this->assertEquals($expected, ob_get_clean());
}

/**
* @see https://github.com/yiisoft/yii2/issues/15536
*/
public function testShouldTriggerInitEvent()
{
$initTriggered = false;
$spaceless = Spaceless::begin(
[
'on init' => function () use (&$initTriggered) {
$initTriggered = true;
}
]
);
Spaceless::end();
$this->assertTrue($initTriggered);
}
}

0 comments on commit 08eccb6

Please sign in to comment.