"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/framework/web/ControllerTest.php" between
yii2-2.0.35.tar.gz and yii2-2.0.36.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

ControllerTest.php  (yii2-2.0.35):ControllerTest.php  (yii2-2.0.36)
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yiiunit\framework\web; namespace yiiunit\framework\web;
use RuntimeException;
use Yii; use Yii;
use yii\base\InlineAction; use yii\base\InlineAction;
use yii\web\Response; use yii\web\Response;
use yii\web\ServerErrorHttpException;
use yiiunit\framework\web\stubs\VendorImage;
use yiiunit\TestCase; use yiiunit\TestCase;
/** /**
* @group web * @group web
*/ */
class ControllerTest extends TestCase class ControllerTest extends TestCase
{ {
/** @var FakeController */
private $controller;
public function testBindActionParams() public function testBindActionParams()
{ {
$aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1'); $aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1');
$params = ['fromGet' => 'from query params', 'q' => 'd426', 'validator' => 'avaliable']; $params = ['fromGet' => 'from query params', 'q' => 'd426', 'validator' => 'avaliable'];
list($fromGet, $other) = $this->controller->bindActionParams($aksi1, $pa rams); list($fromGet, $other) = $this->controller->bindActionParams($aksi1, $pa rams);
$this->assertEquals('from query params', $fromGet); $this->assertEquals('from query params', $fromGet);
$this->assertEquals('default', $other); $this->assertEquals('default', $other);
$params = ['fromGet' => 'from query params', 'q' => 'd426', 'other' => ' avaliable']; $params = ['fromGet' => 'from query params', 'q' => 'd426', 'other' => ' avaliable'];
list($fromGet, $other) = $this->controller->bindActionParams($aksi1, $pa rams); list($fromGet, $other) = $this->controller->bindActionParams($aksi1, $pa rams);
$this->assertEquals('from query params', $fromGet); $this->assertEquals('from query params', $fromGet);
$this->assertEquals('avaliable', $other); $this->assertEquals('avaliable', $other);
} }
public function testNullableInjectedActionParams()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new \yii\web\Applica
tion([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionNullableInjection');
$params = [];
$args = $this->controller->bindActionParams($injectionAction, $params);
$this->assertEquals(\Yii::$app->request, $args[0]);
$this->assertNull($args[1]);
}
public function testInjectionContainerException()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new \yii\web\Applica
tion([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->set(VendorImage::className(), function() { throw new \
RuntimeException('uh oh'); });
$this->expectException(get_class(new RuntimeException()));
$this->expectExceptionMessage('uh oh');
$this->controller->bindActionParams($injectionAction, $params);
}
public function testUnknownInjection()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new \yii\web\Applica
tion([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->clear(VendorImage::className());
$this->expectException(get_class(new ServerErrorHttpException()));
$this->expectExceptionMessage('Could not load required service: vendorIm
age');
$this->controller->bindActionParams($injectionAction, $params);
}
public function testInjectedActionParams()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new \yii\web\Applica
tion([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->set(VendorImage::className(), VendorImage::className()
);
$args = $this->controller->bindActionParams($injectionAction, $params);
$this->assertEquals($params['before'], $args[0]);
$this->assertEquals(\Yii::$app->request, $args[1]);
$this->assertEquals('Component: yii\web\Request $request', \Yii::$app->r
equestedParams['request']);
$this->assertEquals($params['between'], $args[2]);
$this->assertInstanceOf(VendorImage::className(), $args[3]);
$this->assertEquals('Container DI: yiiunit\framework\web\stubs\VendorIma
ge $vendorImage', \Yii::$app->requestedParams['vendorImage']);
$this->assertNull($args[4]);
$this->assertEquals('Unavailable service: post', \Yii::$app->requestedPa
rams['post']);
$this->assertEquals($params['after'], $args[5]);
}
public function testInjectedActionParamsFromModule()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
$module = new \yii\base\Module('fake', new \yii\web\Application([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$module->set('yii\data\DataProviderInterface', [
'class' => \yii\data\ArrayDataProvider::className(),
]);
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', $module);
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionModuleServiceInjection');
$args = $this->controller->bindActionParams($injectionAction, []);
$this->assertInstanceOf(\yii\data\ArrayDataProvider::className(), $args[
0]);
$this->assertEquals('Module yii\base\Module DI: yii\data\DataProviderInt
erface $dataProvider', \Yii::$app->requestedParams['dataProvider']);
}
/** /**
* @see https://github.com/yiisoft/yii2/issues/17701 * @see https://github.com/yiisoft/yii2/issues/17701
*/ */
public function testBindTypedActionParams() public function testBindTypedActionParams()
{ {
if (PHP_VERSION_ID < 70000) { if (PHP_VERSION_ID < 70000) {
$this->markTestSkipped('Can not be tested on PHP < 7.0'); $this->markTestSkipped('Can not be tested on PHP < 7.0');
return; return;
} }
skipping to change at line 121 skipping to change at line 281
$this->assertEquals($this->controller->redirect(['/controller/index'])-> headers->get('location'), '/index.php?r=controller%2Findex'); $this->assertEquals($this->controller->redirect(['/controller/index'])-> headers->get('location'), '/index.php?r=controller%2Findex');
$this->assertEquals($this->controller->redirect(['//controller/index'])- >headers->get('location'), '/index.php?r=controller%2Findex'); $this->assertEquals($this->controller->redirect(['//controller/index'])- >headers->get('location'), '/index.php?r=controller%2Findex');
$this->assertEquals($this->controller->redirect(['//controller/index', ' id' => 3])->headers->get('location'), '/index.php?r=controller%2Findex&id=3'); $this->assertEquals($this->controller->redirect(['//controller/index', ' id' => 3])->headers->get('location'), '/index.php?r=controller%2Findex&id=3');
$this->assertEquals($this->controller->redirect(['//controller/index', ' id_1' => 3, 'id_2' => 4])->headers->get('location'), '/index.php?r=controller%2F index&id_1=3&id_2=4'); $this->assertEquals($this->controller->redirect(['//controller/index', ' id_1' => 3, 'id_2' => 4])->headers->get('location'), '/index.php?r=controller%2F index&id_1=3&id_2=4');
$this->assertEquals($this->controller->redirect(['//controller/index', ' slug' => 'äöüß!"§$%&/()'])->headers->get('location'), '/index.php?r=controller%2 Findex&slug=%C3%A4%C3%B6%C3%BC%C3%9F%21%22%C2%A7%24%25%26%2F%28%29'); $this->assertEquals($this->controller->redirect(['//controller/index', ' slug' => 'äöüß!"§$%&/()'])->headers->get('location'), '/index.php?r=controller%2 Findex&slug=%C3%A4%C3%B6%C3%BC%C3%9F%21%22%C2%A7%24%25%26%2F%28%29');
} }
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
$this->mockWebApplication();
$this->controller = new FakeController('fake', new \yii\web\Application( [ $this->controller = new FakeController('fake', new \yii\web\Application( [
'id' => 'app', 'id' => 'app',
'basePath' => __DIR__, 'basePath' => __DIR__,
'components' => [ 'components' => [
'request' => [ 'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php', 'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php', 'scriptUrl' => '/index.php',
], ],
], ],
])); ]));
$this->mockWebApplication(['controller' => $this->controller]); Yii::$app->controller = $this->controller;
} }
} }
 End of changes. 6 change blocks. 
1 lines changed or deleted 182 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)