Browse Source

Fixes #16101: Fixed Error Handler to clear registered meta tags, link tags, css/js scripts and files in error view

tags/2.0.16
Bizley 6 years ago committed by Alexander Makarov
parent
commit
ab39246ab5
  1. 1
      framework/CHANGELOG.md
  2. 5
      framework/web/ErrorHandler.php
  3. 10
      tests/data/views/errorHandlerForAssetFiles.php
  4. 14
      tests/framework/web/ErrorHandlerTest.php

1
framework/CHANGELOG.md

@ -75,6 +75,7 @@ Yii Framework 2 Change Log
- Bug #10843: Additional hidden input rendered by `yii\helpers\BaseHtml` methods inherits `disabled` HTML option if provided and set to `true` (bizley)
- Bug #16424: `yii\db\Transaction::begin()` throws now `NotSupportedException` for nested transaction and DBMS not supporting savepoints (bizley)
- Bug #15204: `yii\helpers\BaseInflector::slug()` is not removing substrings matching provided replacement from given string anymore (bizley)
- Bug #16101: Fixed Error Handler to clear registered meta tags, link tags, css/js scripts and files in error view (bizley)
- Bug #16836: Fix `yii\mutex\MysqlMutex` to handle locks with names longer than 64 character (rob006)

5
framework/web/ErrorHandler.php

@ -263,7 +263,10 @@ class ErrorHandler extends \yii\base\ErrorHandler
return ob_get_clean();
}
return Yii::$app->getView()->renderFile($_file_, $_params_, $this);
$view = Yii::$app->getView();
$view->clear();
return $view->renderFile($_file_, $_params_, $this);
}
/**

10
tests/data/views/errorHandlerForAssetFiles.php

@ -0,0 +1,10 @@
<?php if (method_exists($this, 'beginPage')): ?>
<?php $this->beginPage(); ?>
<?php endif; ?>
Exception View
<?php if (method_exists($this, 'endBody')): ?>
<?php $this->endBody(); ?>
<?php endif; ?>
<?php if (method_exists($this, 'endPage')): ?>
<?php $this->endPage(); ?>
<?php endif;

14
tests/framework/web/ErrorHandlerTest.php

@ -21,6 +21,7 @@ class ErrorHandlerTest extends TestCase
'errorHandler' => [
'class' => 'yiiunit\framework\web\ErrorHandler',
'errorView' => '@yiiunit/data/views/errorHandler.php',
'exceptionView' => '@yiiunit/data/views/errorHandlerForAssetFiles.php',
],
],
]);
@ -39,6 +40,19 @@ Message: This message is displayed to end user
Exception: yii\web\NotFoundHttpException', $out);
}
public function testClearAssetFilesInErrorView()
{
Yii::$app->getView()->registerJsFile('somefile.js');
/** @var ErrorHandler $handler */
$handler = Yii::$app->getErrorHandler();
ob_start(); // suppress response output
$this->invokeMethod($handler, 'renderException', [new \Exception('Some Exception')]);
ob_get_clean();
$out = Yii::$app->response->data;
$this->assertEquals('Exception View
', $out);
}
public function testRenderCallStackItem()
{
$handler = Yii::$app->getErrorHandler();

Loading…
Cancel
Save