Browse Source

improved test coverage of HostFilter

PR #13063
tags/2.0.11
Carsten Brandt 8 years ago
parent
commit
6782954c6a
  1. 34
      tests/framework/filters/HostControlTest.php

34
tests/framework/filters/HostControlTest.php

@ -9,6 +9,9 @@ use yii\filters\HostControl;
use yii\web\Controller;
use yiiunit\TestCase;
/**
* @group filters
*/
class HostControlTest extends TestCase
{
protected function setUp()
@ -24,10 +27,20 @@ class HostControlTest extends TestCase
/**
* @return array test data.
*/
public function dataProviderFilter()
public function hostInfoValidationDataProvider()
{
return [
[
null,
'example.com',
true
],
[
'example.com',
'example.com',
true
],
[
['example.com'],
'example.com',
true
@ -65,7 +78,7 @@ class HostControlTest extends TestCase
}
/**
* @dataProvider dataProviderFilter
* @dataProvider hostInfoValidationDataProvider
*
* @param mixed $allowedHosts
* @param string $host
@ -101,4 +114,21 @@ class HostControlTest extends TestCase
$this->assertEquals(404, Yii::$app->response->getStatusCode());
}
}
public $denyCallBackCalled = false;
public function testDenyCallback()
{
$filter = new HostControl();
$filter->allowedHosts = ['example.com'];
$this->denyCallBackCalled = false;
$filter->denyCallback = function() {
$this->denyCallBackCalled = true;
};
$controller = new Controller('test', Yii::$app);
$action = new Action('test', $controller);
$this->assertFalse($filter->beforeAction($action));
$this->assertTrue($this->denyCallBackCalled, 'denyCallback should have been called.');
}
}
Loading…
Cancel
Save