Skip to content

Commit

Permalink
Added procesing for native url formats of Yii2 (Codeception#3725)
Browse files Browse the repository at this point in the history
* Added procesing for native url formats of Yii2

* Deleted whitespace for love with bots. Forever.

* Added syntax from 21st century.

* Added syntax from 21st century.

* Update CHANGELOG.md
  • Loading branch information
DavertMik authored Nov 14, 2016
2 parents 807d5b4 + 6958454 commit b34f392
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [Phalcon] **Refactored**. Moved in-memory session adapter to the separated namespace. By @sergeyklay
* [Phalcon] Fixed overwriting server parameters on requests. By @sergeyklay
* [Yii2] Fixed unintentional DB connection drop during exception logging, #3696 by @ivokund
* [Yii2] Added procesing for native url formats of Yii2 #3725 by @githubjeka

#### 2.2.6 (October 2016)

Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/InnerBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function _getResponseContent()
return (string)$this->getRunningClient()->getInternalResponse()->getContent();
}

protected function clientRequest($method, $uri, array $parameters = array(), array $files = array(), array $server = array(), $content = null, $changeHistory = true)
protected function clientRequest($method, $uri, array $parameters = [], array $files = [], array $server = [], $content = null, $changeHistory = true)
{
$this->debugSection("Request Headers", $this->headers);

Expand Down
54 changes: 32 additions & 22 deletions src/Codeception/Module/Yii2.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@
* }
* ```
*
* ## URL
* This module provide to use native URL formats of Yii2 for all codeception commands that use url for work.
* This commands allows input like:
*
* ```php
* <?php
* $I->amOnPage(['site/view','page'=>'about']);
* $I->amOnPage('index-test.php?site/index');
* $I->amOnPage('http://localhost/index-test.php?site/index');
* $I->sendAjaxPostRequest(['/user/update', 'id' => 1], ['UserForm[name]' => 'G.Hopper');
* ```
*
* ## Status
*
* Maintainer: **samdark**
Expand Down Expand Up @@ -445,28 +457,6 @@ protected function getModelRecord($model)
return $record;
}

/**
* Converting $page to valid Yii 2 URL
*
* Allows input like:
*
* ```php
* <?php
* $I->amOnPage(['site/view','page'=>'about']);
* $I->amOnPage('index-test.php?site/index');
* $I->amOnPage('http://localhost/index-test.php?site/index');
* ```
*
* @param $page string|array parameter for \yii\web\UrlManager::createUrl()
*/
public function amOnPage($page)
{
if (is_array($page)) {
$page = Yii::$app->getUrlManager()->createUrl($page);
}
parent::amOnPage($page);
}

/**
* Similar to amOnPage but accepts route as first argument and params as second
*
Expand All @@ -480,6 +470,26 @@ public function amOnRoute($route, array $params = [])
array_unshift($params, $route);
$this->amOnPage($params);
}

/**
* To support to use the behavior of urlManager component
* for the methods like this: amOnPage(), sendAjaxRequest() and etc.
* @param $method
* @param $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param null $content
* @param bool $changeHistory
* @return mixed
*/
protected function clientRequest($method, $uri, array $parameters = [], array $files = [], array $server = [], $content = null, $changeHistory = true)
{
if (is_array($uri)) {
$uri = Yii::$app->getUrlManager()->createUrl($uri);
}
return parent::clientRequest($method, $uri, $parameters, $files, $server, $content, $changeHistory);
}

/**
* Gets a component from Yii container. Throws exception if component is not available
Expand Down

0 comments on commit b34f392

Please sign in to comment.