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 / dev2.destoffenstraat.com / vendor / magento / framework / App / Test / Unit / Route /
Filename/home/dev2.destoffenstraat.com/vendor/magento/framework/App/Test/Unit/Route/ConfigTest.php
Size5.21 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified07-Jan-2021 21:08
Last accessed23-Aug-2025 03:56
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\App\Test\Unit\Route;

use Magento\Framework\App\AreaList;
use Magento\Framework\App\Route\Config;
use Magento\Framework\App\Route\Config\Reader;
use Magento\Framework\Config\CacheInterface;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
/**
* @var Config
*/
protected $_config;

/**
* @var Reader|MockObject
*/
protected $_readerMock;

/**
* @var MockObject
*/
protected $_cacheMock;

/**
* @var MockObject
*/
protected $_configScopeMock;

/**
* @var MockObject
*/
protected $_areaList;

/**
* @var SerializerInterface|MockObject
*/
private $serializerMock;

protected function setUp(): void
{
$this->_readerMock = $this->createMock(Reader::class);
$this->_cacheMock = $this->getMockForAbstractClass(CacheInterface::class);
$this->_configScopeMock = $this->getMockForAbstractClass(ScopeInterface::class);
$this->_areaList = $this->createMock(AreaList::class);
$this->_configScopeMock->expects($this->any())
->method('getCurrentScope')
->willReturn('areaCode');
$objectManager = new ObjectManager($this);
$this->_config = $objectManager->getObject(
Config::class,
[
'reader' => $this->_readerMock,
'cache' => $this->_cacheMock,
'configScope' => $this->_configScopeMock,
'areaList' => $this->_areaList
]
);
$this->serializerMock = $this->getMockForAbstractClass(SerializerInterface::class);
$objectManager->setBackwardCompatibleProperty($this->_config, 'serializer', $this->serializerMock);
}

public function testGetRouteFrontNameIfCacheIfRouterIdNotExist()
{
$this->_cacheMock->expects($this->once())
->method('load')
->with('areaCode::RoutesConfig')
->willReturn('["expected"]');
$this->assertEquals('routerCode', $this->_config->getRouteFrontName('routerCode'));
}

public function testGetRouteByFrontName()
{
$data = ['routerCode' => ['frontName' => 'routerName']];
$this->_cacheMock->expects($this->once())
->method('load')
->with('areaCode::RoutesConfig')
->willReturn('serializedData');
$this->serializerMock->expects($this->once())
->method('unserialize')
->with('serializedData')
->willReturn($data);
$this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName'));
}

public function testGetRouteByFrontNameNoRoutes()
{
$this->_cacheMock->expects($this->once())
->method('load')
->with('areaCode::RoutesConfig')
->willReturn('serializedData');
$this->serializerMock->expects($this->once())
->method('unserialize')
->with('serializedData')
->willReturn([]);
$this->assertFalse($this->_config->getRouteByFrontName('routerName'));
}

public function testGetRouteByFrontNameNoCache()
{
$this->_cacheMock->expects($this->once())
->method('load')
->with('scope::RoutesConfig')
->willReturn('false');

$routes = [
'routerCode' => [
'frontName' => 'routerName',
],
];

$routers = [
'default_router' => [
'routes' => $routes,
],
];

$serializedData = json_encode($routes);

$this->_readerMock->expects(
$this->once()
)->method(
'read'
)->with(
'scope'
)->willReturn(
$routers
);

$this->_areaList->expects(
$this->once()
)->method(
'getDefaultRouter'
)->with(
'scope'
)->willReturn(
'default_router'
);

$this->serializerMock->expects($this->once())
->method('serialize')
->willReturn($serializedData);

$this->_cacheMock->expects($this->once())
->method('save')
->with($serializedData, 'scope::RoutesConfig');

$this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName', 'scope'));
}

public function testGetModulesByFrontName()
{
$data = ['routerCode' => ['frontName' => 'routerName', 'modules' => ['Module1']]];

$this->_cacheMock->expects($this->once())
->method('load')
->with('areaCode::RoutesConfig')
->willReturn('serializedData');
$this->serializerMock->expects($this->once())
->method('unserialize')
->with('serializedData')
->willReturn($data);
$this->assertEquals(['Module1'], $this->_config->getModulesByFrontName('routerName'));
}
}