default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Enhancer;
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;
use Symfony\Cmf\Component\Routing\Enhancer\ContentRepositoryEnhancer;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
class ContentRepositoryEnhancerTest extends TestCase
{
/**
* {@inheritdoc}
*/
public function setUp(): void
{
$cRepository = $this->createMock(ContentRepositoryInterface::class);
$cRepository
->method('findById')
->will($this->returnValue('document'))
;
$this->mapper = new ContentRepositoryEnhancer($cRepository);
$this->request = Request::create('/test');
}
/**
* @dataProvider dataEnhancer
*/
public function testEnhancer($defaults, $expected)
{
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
/**
* @return array
*/
public function dataEnhancer()
{
return [
'empty' => [[], []],
'with content_id' => [
[
RouteObjectInterface::CONTENT_ID => 'Simple:1',
],
[
RouteObjectInterface::CONTENT_ID => 'Simple:1',
RouteObjectInterface::CONTENT_OBJECT => 'document',
],
],
'with content_id and content' => [
[
RouteObjectInterface::CONTENT_ID => 'Simple:1',
RouteObjectInterface::CONTENT_OBJECT => 'exist object',
],
[
RouteObjectInterface::CONTENT_ID => 'Simple:1',
RouteObjectInterface::CONTENT_OBJECT => 'exist object',
],
],
'with content' => [
[
RouteObjectInterface::CONTENT_OBJECT => 'exist object',
],
[
RouteObjectInterface::CONTENT_OBJECT => 'exist object',
],
],
];
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Enhancer;
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Component\Routing\Enhancer\FieldByClassEnhancer;
use Symfony\Component\HttpFoundation\Request;
class FieldByClassEnhancerTest extends TestCase
{
private $request;
/**
* @var FieldByClassEnhancer
*/
private $mapper;
private $document;
public function setUp(): void
{
$this->document = $this->createMock(RouteObject::class);
$mapping = [RouteObject::class => 'cmf_content.controller:indexAction'];
$this->mapper = new FieldByClassEnhancer('_content', '_controller', $mapping);
$this->request = Request::create('/test');
}
public function testClassFoundInMapping()
{
// this is the mock, thus a child class to make sure we properly check with instanceof
$defaults = ['_content' => $this->document];
$expected = [
'_content' => $this->document,
'_controller' => 'cmf_content.controller:indexAction',
];
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = [
'_content' => $this->document,
'_controller' => 'custom.controller:indexAction',
];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testClassNotFoundInMapping()
{
$defaults = ['_content' => $this];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoClass()
{
$defaults = ['foo' => 'bar'];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Mapper;
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Component\Routing\Enhancer\FieldMapEnhancer;
use Symfony\Component\HttpFoundation\Request;
class FieldMapEnhancerTest extends TestCase
{
/**
* @var Request
*/
private $request;
/**
* @var FieldMapEnhancer
*/
private $enhancer;
public function setUp(): void
{
$this->request = Request::create('/test');
$mapping = ['static_pages' => 'cmf_content.controller:indexAction'];
$this->enhancer = new FieldMapEnhancer('type', '_controller', $mapping);
}
public function testFieldFoundInMapping()
{
$defaults = ['type' => 'static_pages'];
$expected = [
'type' => 'static_pages',
'_controller' => 'cmf_content.controller:indexAction',
];
$this->assertEquals($expected, $this->enhancer->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = [
'type' => 'static_pages',
'_controller' => 'custom.controller:indexAction',
];
$this->assertEquals($defaults, $this->enhancer->enhance($defaults, $this->request));
}
public function testNoType()
{
$defaults = [];
$this->assertEquals([], $this->enhancer->enhance($defaults, $this->request));
}
public function testNotFoundInMapping()
{
$defaults = ['type' => 'unknown_route'];
$this->assertEquals($defaults, $this->enhancer->enhance($defaults, $this->request));
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Enhancer;
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer;
use Symfony\Component\HttpFoundation\Request;
class FieldPresenceEnhancerTest extends TestCase
{
/**
* @var FieldPresenceEnhancer
*/
private $mapper;
private $request;
public function setUp(): void
{
$this->mapper = new FieldPresenceEnhancer('_template', '_controller', 'cmf_content.controller:indexAction');
$this->request = Request::create('/test');
}
public function testHasTemplate()
{
$defaults = ['_template' => 'Bundle:Topic:template.html.twig'];
$expected = [
'_template' => 'Bundle:Topic:template.html.twig',
'_controller' => 'cmf_content.controller:indexAction',
];
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = [
'_template' => 'Bundle:Topic:template.html.twig',
'_controller' => 'custom.controller:indexAction',
];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testHasNoSourceValue()
{
$defaults = ['foo' => 'bar'];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testHasNoSource()
{
$this->mapper = new FieldPresenceEnhancer(null, '_controller', 'cmf_content.controller:indexAction');
$defaults = ['foo' => 'bar'];
$expected = [
'foo' => 'bar',
'_controller' => 'cmf_content.controller:indexAction',
];
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Enhancer;
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class RouteContentEnhancerTest extends TestCase
{
/**
* @var RouteContentEnhancer
*/
private $mapper;
private $document;
private $request;
public function setUp(): void
{
$this->document = $this->createMock(RouteObject::class);
$this->mapper = new RouteContentEnhancer(RouteObjectInterface::ROUTE_OBJECT, '_content');
$this->request = Request::create('/test');
}
public function testContent()
{
$targetDocument = new TargetDocument();
$this->document->expects($this->once())
->method('getContent')
->will($this->returnValue($targetDocument));
$defaults = [RouteObjectInterface::ROUTE_OBJECT => $this->document];
$expected = [RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => $targetDocument];
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$this->document->expects($this->never())
->method('getContent')
;
$defaults = [RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => 'foo'];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoContent()
{
$this->document->expects($this->once())
->method('getContent')
->will($this->returnValue(null));
$defaults = [RouteObjectInterface::ROUTE_OBJECT => $this->document];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoCmfRoute()
{
$defaults = [RouteObjectInterface::ROUTE_OBJECT => $this->createMock(Route::class)];
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
}
class TargetDocument
{
}
class UnknownDocument
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Unit\Enhancer;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
/**
* Empty abstract class to be able to mock an object that both extends Route
* and implements RouteObjectInterface.
*/
abstract class RouteObject extends Route implements RouteObjectInterface
{
public function getRouteKey()
{
}
}