Skip to content

Commit

Permalink
Merge e02800d into 434e920
Browse files Browse the repository at this point in the history
  • Loading branch information
boehsermoe committed Oct 14, 2018
2 parents 434e920 + e02800d commit dff9461
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 35 deletions.
2 changes: 2 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. This projec

## 1.0.13 (in progress)

+ [#1855](https://github.com/luyadev/luya/issues/1855) If create a url to an other module, don't replace the url with current module context.

## 1.0.12 (8. October 2018)

+ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is runing, the cli determination should be forced.
Expand Down
15 changes: 10 additions & 5 deletions core/web/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ private function findModuleInRoute($route)
private function urlReplaceModule($url, $navItemId, Composition $composition)
{
$route = $composition->removeFrom($this->removeBaseUrl($url));
$module = $this->findModuleInRoute($route);
$moduleName = $this->findModuleInRoute($route);

if ($module === false || $this->menu === false) {
if ($moduleName === false || $this->menu === false) {
return $url;
}

Expand All @@ -362,10 +362,15 @@ private function urlReplaceModule($url, $navItemId, Composition $composition)
// another module which should not be modificated.
// 2. If the current page (nav) context is the homepage, we have to keep the original link as it wont work because the homepage
// does not have a route prefix.
if (($item->type == 2 && $module !== $item->moduleName) || $item->isHome) {
if (($item->type == 2 && $moduleName !== $item->moduleName) || $item->isHome) {
return $url;
}

return preg_replace("/$module/", rtrim($item->link, '/'), ltrim($route, '/'), 1);

// if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated.
if ($moduleName !== Yii::$app->controller->module->id) {
return $url;
}

return preg_replace("/$moduleName/", rtrim($item->link, '/'), ltrim($route, '/'), 1);
}
}
28 changes: 0 additions & 28 deletions phpunit.xml.dist

This file was deleted.

40 changes: 38 additions & 2 deletions tests/core/web/UrlManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use luyatests\data\classes\UnitMenu;
use luya\web\Composition;

class UrlStubController extends \luya\web\Controller
{
}

/**
* @author nadar
*/
Expand Down Expand Up @@ -212,11 +216,27 @@ public function testCreateMenuItemUrl()
$urlManager = new UrlManager();
$menu = $urlManager->getMenu();
$this->assertNotFalse($menu);


Yii::$app->controller = new UrlStubController('stub', Yii::$app->getModule('unitmodule'));

$r = $urlManager->createMenuItemUrl(['unitmodule/controller/action'], 3);

$this->assertSame('this-is-a-cms-link/controller/action', $r);
}

public function testCreateMenuItemUrlToOtherModule()
{
Yii::$app->set('menu', ['class' => UnitMenu::class]);
$urlManager = new UrlManager();
$menu = $urlManager->getMenu();
$this->assertNotFalse($menu);

Yii::$app->controller = new UrlStubController('stub', Yii::$app->getModule('unitmodule'));

$r = $urlManager->createMenuItemUrl(['othermodule/controller/action'], 3);

$this->assertContains('/othermodule/controller/action', $r);
}

public function testCreateMenuItemUrlWithHomeItem()
{
Expand All @@ -236,11 +256,27 @@ public function testCreateMenuItemUrlRedirectType2()
$urlManager = new UrlManager();
$menu = $urlManager->getMenu();
$this->assertNotFalse($menu);


Yii::$app->controller = new UrlStubController('stub', Yii::$app->getModule('unitmodule'));

$r = $urlManager->createMenuItemUrl(['unitmodule/controller/action'], 2);

$this->assertSame('this-is-a-module-type-page/controller/action', $r);
}

public function testCreateMenuItemUrlRedirectType2ToOtherModule()
{
Yii::$app->set('menu', ['class' => UnitMenu::class]);
$urlManager = new UrlManager();
$menu = $urlManager->getMenu();
$this->assertNotFalse($menu);

Yii::$app->controller = new UrlStubController('stub', Yii::$app->getModule('unitmodule'));

$r = $urlManager->createMenuItemUrl(['othermodule/controller/action'], 2);

$this->assertContains('/othermodule/controller/action', $r);
}

public function testCreateMenuItemUrlWithException()
{
Expand Down

0 comments on commit dff9461

Please sign in to comment.