Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Mage_Core_Controller_Front_Router::getUrl() #4356

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2915,11 +2915,6 @@ parameters:
count: 1
path: app/code/core/Mage/Core/Controller/Front/Router.php

-
message: "#^Parameter \\#1 \\$type of static method Mage\\:\\:getBaseUrl\\(\\) expects string, array given\\.$#"
count: 1
path: app/code/core/Mage/Core/Controller/Front/Router.php

-
message: "#^Constructor of class Mage_Core_Controller_Varien_Action has an unused parameter \\$invokeArgs\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public static function getStoreConfigFlag($path, $store = null)
/**
* Get base URL path by type
*
* @param string $type
* @param Mage_Core_Model_Store::URL_TYPE_* $type
kiatng marked this conversation as resolved.
Show resolved Hide resolved
* @param null|bool $secure
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Core/Controller/Front/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function addRoutes(Zend_Controller_Router_Interface $router)
}

/**
* @param array $params
* @param string|array $params
* @return string
*/
- */
public function getUrl($params = [])
{
static $reservedKeys = ['module' => 1, 'controller' => 1, 'action' => 1, 'array' => 1];
Expand All @@ -65,7 +65,7 @@ public function getUrl($params = [])
$params = ['controller' => $paramsArr[0], 'action' => $paramsArr[1]];
}

$url = Mage::getBaseUrl($params);
$url = Mage::getBaseUrl();

if (!empty($params['frontName'])) {
$url .= $params['frontName'] . '/';
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function getUrl($route = '', $params = [])
/**
* Retrieve base URL
*
* @param string $type
* @param self::URL_TYPE_* $type
* @param bool|null $secure
* @return string
*/
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/Mage/Core/Controller/Front/RouterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Core\Controller\Front;

use Mage;
use Mage_Core_Controller_Front_Router;
use Mage_Core_Model_Config_Element;
use PHPUnit\Framework\TestCase;

class RouterTest extends TestCase
{
public Mage_Core_Controller_Front_Router $subject;

public function setUp(): void
{
Mage::app();
$config = new Mage_Core_Model_Config_Element('<?xml version="1.0" encoding="utf-8" ?><test-url />');
$this->subject = new Mage_Core_Controller_Front_Router($config);
}

/**
* @group Mage_Core
* @group Mage_Core_Controller
*/
public function testGetUrl(): void
{
$this->assertStringEndsWith('test-url/', $this->subject->getUrl());
}
}