b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / vendor / magento / framework / App / Test / Unit / Router /
Filename/home/a/home/dev2.destoffenstraat.com/vendor/magento/framework/App/Test/Unit/Router/BaseTest.php
Size10.55 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified07-Jan-2021 21:08
Last accessed23-Aug-2025 16:34
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php declare(strict_types=1);
/**
* Tests Magento\Framework\App\Router\Base
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\App\Test\Unit\Router;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\ActionFactory;
use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\Route\ConfigInterface;
use Magento\Framework\App\Router\ActionList;
use Magento\Framework\App\Router\Base;
use Magento\Framework\App\State;
use Magento\Framework\Code\NameBuilder;
use Magento\Framework\TestFramework\Unit\BaseTestCase;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Base router unit test.
*/
class BaseTest extends BaseTestCase
{
/**
* @var Base
*/
private $model;

/**
* @var MockObject|Http
*/
private $requestMock;

/**
* @var MockObject|ConfigInterface
*/
private $routeConfigMock;

/**
* @var MockObject|State
*/
private $appStateMock;

/**
* @var MockObject|ActionList
*/
private $actionListMock;

/**
* @var MockObject|ActionFactory
*/
private $actionFactoryMock;

/**
* @var MockObject|NameBuilder
*/
private $nameBuilderMock;

/**
* @var MockObject|DefaultPathInterface
*/
private $defaultPathMock;

protected function setUp(): void
{
parent::setUp();
// Create mocks
$this->requestMock = $this->basicMock(Http::class);
$this->routeConfigMock = $this->basicMock(ConfigInterface::class);
$this->appStateMock = $this->getMockBuilder(State::class)
->addMethods(['isInstalled'])
->disableOriginalConstructor()
->getMock();
$this->actionListMock = $this->basicMock(ActionList::class);
$this->actionFactoryMock = $this->basicMock(ActionFactory::class);
$this->nameBuilderMock = $this->basicMock(NameBuilder::class);
$this->defaultPathMock = $this->basicMock(DefaultPathInterface::class);

// Prepare SUT
$mocks = [
'actionList' => $this->actionListMock,
'actionFactory' => $this->actionFactoryMock,
'routeConfig' => $this->routeConfigMock,
'appState' => $this->appStateMock,
'nameBuilder' => $this->nameBuilderMock,
'defaultPath' => $this->defaultPathMock,
];
$this->model = $this->objectManager->getObject(Base::class, $mocks);
}

public function testMatch()
{
// Test Data
$actionInstance = 'action instance';
$moduleFrontName = 'module front name';
$actionPath = 'action path';
$actionName = 'action name';
$actionClassName = Action::class;
$moduleName = 'module name';
$moduleList = [$moduleName];
$paramList = $moduleFrontName . '/' . $actionPath . '/' . $actionName . '/key/val/key2/val2/';

// Stubs
$this->requestMock->expects($this->any())->method('getModuleName')->willReturn($moduleFrontName);
$this->requestMock->expects($this->any())->method('getControllerName')->willReturn($actionPath);
$this->requestMock->expects($this->any())->method('getActionName')->willReturn($actionName);
$this->requestMock->expects($this->any())->method('getPathInfo')->willReturn($paramList);
$this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList);
$this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(true);
$this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
$this->actionFactoryMock->expects($this->any())->method('create')->willReturn($actionInstance);

// Expectations and Test
$this->requestExpects('setModuleName', $moduleFrontName)
->requestExpects('setControllerName', $actionPath)
->requestExpects('setActionName', $actionName)
->requestExpects('setControllerModule', $moduleName);

$this->assertSame($actionInstance, $this->model->match($this->requestMock));
}

public function testMatchUseParams()
{
// Test Data
$actionInstance = 'action instance';
$moduleFrontName = 'module front name';
$actionPath = 'action path';
$actionName = 'action name';
$actionClassName = Action::class;
$moduleName = 'module name';
$moduleList = [$moduleName];
$paramList = $moduleFrontName . '/' . $actionPath . '/' . $actionName . '/key/val/key2/val2/';

// Stubs
$this->requestMock->expects($this->any())->method('getPathInfo')->willReturn($paramList);
$this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList);
$this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false);
$this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
$this->actionFactoryMock->expects($this->any())->method('create')->willReturn($actionInstance);

// Expectations and Test
$this->requestExpects('setModuleName', $moduleFrontName)
->requestExpects('setControllerName', $actionPath)
->requestExpects('setActionName', $actionName)
->requestExpects('setControllerModule', $moduleName);

$this->assertSame($actionInstance, $this->model->match($this->requestMock));
}

public function testMatchUseDefaultPath()
{
// Test Data
$actionInstance = 'action instance';
$moduleFrontName = 'module front name';
$actionPath = 'action path';
$actionName = 'action name';
$actionClassName = Action::class;
$moduleName = 'module name';
$moduleList = [$moduleName];
$paramList = $moduleFrontName . '/' . $actionPath . '/' . $actionName . '/key/val/key2/val2/';

// Stubs
$defaultReturnMap = [
['module', $moduleFrontName],
['controller', $actionPath],
['action', $actionName],
];
$this->requestMock->expects($this->any())->method('getPathInfo')->willReturn($paramList);
$this->defaultPathMock->expects($this->any())->method('getPart')->willReturnMap($defaultReturnMap);
$this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList);
$this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false);
$this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
$this->actionFactoryMock->expects($this->any())->method('create')->willReturn($actionInstance);

// Expectations and Test
$this->requestExpects('setModuleName', $moduleFrontName)
->requestExpects('setControllerName', $actionPath)
->requestExpects('setActionName', $actionName)
->requestExpects('setControllerModule', $moduleName);

$this->assertSame($actionInstance, $this->model->match($this->requestMock));
}

public function testMatchEmptyModuleList()
{
// Test Data
$actionInstance = 'action instance';
$moduleFrontName = 'module front name';
$actionPath = 'action path';
$actionName = 'action name';
$actionClassName = Action::class;
$emptyModuleList = [];
$paramList = $moduleFrontName . '/' . $actionPath . '/' . $actionName . '/key/val/key2/val2/';

// Stubs
$this->requestMock->expects($this->any())->method('getModuleName')->willReturn($moduleFrontName);
$this->requestMock->expects($this->any())->method('getPathInfo')->willReturn($paramList);
$this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($emptyModuleList);
$this->requestMock->expects($this->any())->method('getControllerName')->willReturn($actionPath);
$this->requestMock->expects($this->any())->method('getActionName')->willReturn($actionName);
$this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false);
$this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
$this->actionFactoryMock->expects($this->any())->method('create')->willReturn($actionInstance);

// Test
$this->assertNull($this->model->match($this->requestMock));
}

public function testMatchEmptyActionInstance()
{
// Test Data
$nullActionInstance = null;
$moduleFrontName = 'module front name';
$actionPath = 'action path';
$actionName = 'action name';
$actionClassName = Action::class;
$moduleName = 'module name';
$moduleList = [$moduleName];
$paramList = $moduleFrontName . '/' . $actionPath . '/' . $actionName . '/key/val/key2/val2/';

// Stubs
$this->requestMock->expects($this->any())->method('getModuleName')->willReturn($moduleFrontName);
$this->requestMock->expects($this->any())->method('getPathInfo')->willReturn($paramList);
$this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList);
$this->requestMock->expects($this->any())->method('getControllerName')->willReturn($actionPath);
$this->requestMock->expects($this->any())->method('getActionName')->willReturn($actionName);
$this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false);
$this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
$this->actionFactoryMock->expects($this->any())->method('create')->willReturn($nullActionInstance);

// Expectations and Test
$this->assertNull($this->model->match($this->requestMock));
}

public function testGetActionClassName()
{
$className = 'name of class';
$module = 'module';
$prefix = 'Controller';
$actionPath = 'action path';
$this->nameBuilderMock->expects($this->once())
->method('buildClassName')
->with([$module, $prefix, $actionPath])
->willReturn($className);
$this->assertEquals($className, $this->model->getActionClassName($module, $actionPath));
}

/**
* Generate a stub with an expected usage for the request mock object
*
* @param string $method
* @param string $with
* @return $this
*/
private function requestExpects($method, $with)
{
$this->requestMock->expects($this->once())
->method($method)
->with($with);
return $this;
}
}