class EntityResolverManagerTest in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php \Drupal\Tests\Core\Entity\EntityResolverManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityResolverManager @group Entity
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Entity\EntityResolverManagerTest
Expanded class hierarchy of EntityResolverManagerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityResolverManagerTest.php, line 23 - Contains \Drupal\Tests\Core\Entity\EntityResolverManagerTest.
Namespace
Drupal\Tests\Core\EntityView source
class EntityResolverManagerTest extends UnitTestCase {
/**
* The tested entity resolver manager.
*
* @var \Drupal\Core\Entity\EntityResolverManager
*/
protected $entityResolverManager;
/**
* The mocked entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The mocked class resolver.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $classResolver;
/**
* The mocked dependency injection container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $container;
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp() {
$this->entityManager = $this
->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->container = $this
->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$this->classResolver = $this
->getClassResolverStub();
$this->entityResolverManager = new EntityResolverManager($this->entityManager, $this->classResolver);
}
/**
* Tests setRouteOptions() with no parameter.
*
* We don't have any entity type involved, so we don't need any upcasting.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
*
* @dataProvider providerTestSetRouteOptionsWithStandardRoute
*/
public function testSetRouteOptionsWithStandardRoute($controller) {
$route = new Route('/example', array(
'_controller' => $controller,
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$this
->assertEmpty($route
->getOption('parameters'));
}
/**
* Data provider for testSetRouteOptionsWithStandardRoute.
*/
public function providerTestSetRouteOptionsWithStandardRoute() {
return array(
array(
'Drupal\\Tests\\Core\\Entity\\BasicControllerClass::exampleControllerMethod',
),
array(
'test_function_controller',
),
);
}
/**
* Tests setRouteOptions() with a controller with a non entity argument.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
*
* @dataProvider providerTestSetRouteOptionsWithStandardRouteWithArgument
*/
public function testSetRouteOptionsWithStandardRouteWithArgument($controller) {
$route = new Route('/example/{argument}', array(
'_controller' => $controller,
'argument' => 'test',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$this
->assertEmpty($route
->getOption('parameters'));
}
/**
* Data provider for testSetRouteOptionsWithStandardRouteWithArgument.
*/
public function providerTestSetRouteOptionsWithStandardRouteWithArgument() {
return array(
array(
'Drupal\\Tests\\Core\\Entity\\BasicControllerClass::exampleControllerMethodWithArgument',
),
array(
'test_function_controller_with_argument',
),
);
}
/**
* Tests setRouteOptions() with a _content default.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
*
* @dataProvider providerTestSetRouteOptionsWithContentController
*/
public function testSetRouteOptionsWithContentController($controller) {
$route = new Route('/example/{argument}', array(
'_controller' => $controller,
'argument' => 'test',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$this
->assertEmpty($route
->getOption('parameters'));
}
/**
* Data provider for testSetRouteOptionsWithContentController.
*/
public function providerTestSetRouteOptionsWithContentController() {
return array(
array(
'Drupal\\Tests\\Core\\Entity\\BasicControllerClass::exampleControllerMethodWithArgument',
),
array(
'test_function_controller_with_argument',
),
);
}
/**
* Tests setRouteOptions() with an entity type parameter.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
*
* @dataProvider providerTestSetRouteOptionsWithEntityTypeNoUpcasting
*/
public function testSetRouteOptionsWithEntityTypeNoUpcasting($controller) {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_controller' => $controller,
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$this
->assertEmpty($route
->getOption('parameters'));
}
/**
* Data provider for testSetRouteOptionsWithEntityTypeNoUpcasting.
*/
public function providerTestSetRouteOptionsWithEntityTypeNoUpcasting() {
return array(
array(
'Drupal\\Tests\\Core\\Entity\\BasicControllerClass::exampleControllerWithEntityNoUpcasting',
),
array(
'test_function_controller_no_upcasting',
),
);
}
/**
* Tests setRouteOptions() with an entity type parameter, upcasting.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
*
* @dataProvider providerTestSetRouteOptionsWithEntityTypeUpcasting
*/
public function testSetRouteOptionsWithEntityTypeUpcasting($controller) {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_controller' => $controller,
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'entity_test' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Data provider for testSetRouteOptionsWithEntityTypeUpcasting.
*/
public function providerTestSetRouteOptionsWithEntityTypeUpcasting() {
return array(
array(
'Drupal\\Tests\\Core\\Entity\\BasicControllerClass::exampleControllerWithEntityUpcasting',
),
array(
'test_function_controller_entity_upcasting',
),
);
}
/**
* Tests setRouteOptions() with an entity type parameter form.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
*/
public function testSetRouteOptionsWithEntityFormUpcasting() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_form' => 'Drupal\\Tests\\Core\\Entity\\BasicForm',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'entity_test' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Tests setRouteOptions() with entity form upcasting, no create method.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
*/
public function testSetRouteOptionsWithEntityUpcastingNoCreate() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_form' => 'Drupal\\Tests\\Core\\Entity\\BasicFormNoContainerInjectionInterface',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'entity_test' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Tests setRouteOptions() with an form parameter without interface.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
*/
public function testSetRouteOptionsWithEntityFormNoUpcasting() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_form' => 'Drupal\\Tests\\Core\\Entity\\BasicFormNoUpcasting',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$this
->assertEmpty($route
->getOption('parameters'));
}
/**
* Tests setRouteOptions() with an _entity_view route.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityViewRouteAndManualParameters() {
$this
->setupEntityTypes();
$route = new Route('/example/{foo}', array(
'_entity_view' => 'entity_test.view',
), array(), array(
'parameters' => array(
'foo' => array(
'type' => 'entity:entity_test',
),
),
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'foo' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Tests setRouteOptions() with an _entity_view route.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityViewRoute() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_entity_view' => 'entity_test.view',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'entity_test' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Tests setRouteOptions() with an _entity_list route.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityListRoute() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_entity_list' => 'entity_test',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertNull($parameters);
}
/**
* Tests setRouteOptions() with an _entity_form route.
*
* @covers ::setRouteOptions
* @covers ::getControllerClass
* @covers ::getEntityTypes
* @covers ::setParametersFromReflection
* @covers ::setParametersFromEntityInformation
*/
public function testSetRouteOptionsWithEntityFormRoute() {
$this
->setupEntityTypes();
$route = new Route('/example/{entity_test}', array(
'_entity_form' => 'entity_test.edit',
));
$defaults = $route
->getDefaults();
$this->entityResolverManager
->setRouteOptions($route);
$this
->assertEquals($defaults, $route
->getDefaults());
$parameters = $route
->getOption('parameters');
$this
->assertEquals(array(
'entity_test' => array(
'type' => 'entity:entity_test',
),
), $parameters);
}
/**
* Creates the entity manager mock returning entity type objects.
*/
protected function setupEntityTypes() {
$definition = $this
->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
$definition
->expects($this
->any())
->method('getClass')
->will($this
->returnValue('Drupal\\Tests\\Core\\Entity\\SimpleTestEntity'));
$this->entityManager
->expects($this
->any())
->method('getDefinitions')
->will($this
->returnValue(array(
'entity_test' => $definition,
)));
$this->entityManager
->expects($this
->any())
->method('getDefinition')
->will($this
->returnCallback(function ($entity_type) use ($definition) {
if ($entity_type == 'entity_test') {
return $definition;
}
else {
return NULL;
}
}));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityResolverManagerTest:: |
protected | property | The mocked class resolver. | |
EntityResolverManagerTest:: |
protected | property | The mocked dependency injection container. | |
EntityResolverManagerTest:: |
protected | property | The mocked entity manager. | |
EntityResolverManagerTest:: |
protected | property | The tested entity resolver manager. | |
EntityResolverManagerTest:: |
public | function | Data provider for testSetRouteOptionsWithContentController. | |
EntityResolverManagerTest:: |
public | function | Data provider for testSetRouteOptionsWithEntityTypeNoUpcasting. | |
EntityResolverManagerTest:: |
public | function | Data provider for testSetRouteOptionsWithEntityTypeUpcasting. | |
EntityResolverManagerTest:: |
public | function | Data provider for testSetRouteOptionsWithStandardRoute. | |
EntityResolverManagerTest:: |
public | function | Data provider for testSetRouteOptionsWithStandardRouteWithArgument. | |
EntityResolverManagerTest:: |
protected | function |
@covers ::__construct Overrides UnitTestCase:: |
|
EntityResolverManagerTest:: |
protected | function | Creates the entity manager mock returning entity type objects. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with a _content default. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an form parameter without interface. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an _entity_form route. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an entity type parameter form. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an _entity_list route. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an entity type parameter. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an entity type parameter, upcasting. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with entity form upcasting, no create method. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an _entity_view route. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with an _entity_view route. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with no parameter. | |
EntityResolverManagerTest:: |
public | function | Tests setRouteOptions() with a controller with a non entity argument. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |