Skip to content

Commit

Permalink
Merge pull request #7976 in SW/shopware from ntr/5.6/fix-request-getp…
Browse files Browse the repository at this point in the history
…aram-null-handling to 5.6

* commit '0c4aebb25aaa2fe45616c53ab181856d5b323092':
  NTR - Fix request getParam null handling
  • Loading branch information
shyim committed Aug 9, 2019
2 parents 5ef42e0 + 0c4aebb commit bd88f2f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
8 changes: 6 additions & 2 deletions engine/Library/Enlight/Controller/Request/RequestHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,13 @@ public function getParam($key, $default = null)
{
if (isset($this->_params[$key])) {
return $this->_params[$key];
} elseif ($this->query->has($key)) {
}

if ($this->query->has($key) && $this->query->get($key) !== null) {
return $this->query->get($key);
} elseif ($this->request->has($key)) {
}

if ($this->request->has($key) && $this->request->get($key) !== null) {
return $this->request->get($key);
}

Expand Down
93 changes: 93 additions & 0 deletions tests/Unit/Library/RequestHttpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/

namespace Shopware\Tests\Unit\Library;

use PHPUnit\Framework\TestCase;
use Shopware\Tests\Functional\Helper\Utils;

class RequestHttpTest extends TestCase
{
private $request;

public function setUp(): void
{
$this->request = new \Enlight_Controller_Request_RequestHttp();
}

/**
* @dataProvider getDataParamHandling
*/
public function testGetParamHandling($filled, $default, $expect): void
{
Utils::hijackProperty($this->request, '_params', ['foo' => $filled]);

static::assertEquals($expect, $this->request->getParam('foo', $default));

$this->request->request->set('foo', $filled);
static::assertEquals($expect, $this->request->getParam('foo', $default));

$this->request->query->set('foo', $filled);
static::assertEquals($expect, $this->request->getParam('foo', $default));
}

public function getDataParamHandling(): array
{
return [
[
null,
'foo',
'foo',
], [
false,
'foo',
false,
], [
true,
'foo',
true,
], [
0,
'foo',
0,
], [
'0',
'foo',
'0',
], [
'false',
'foo',
'false',
], [
'true',
'foo',
'true',
], [
5.5,
'foo',
5.5,
],
];
}
}

0 comments on commit bd88f2f

Please sign in to comment.