EntityRevisionParamConverterTest.php in Entity API 8.0
File
tests/src/Unit/ParamConverter/EntityRevisionParamConverterTest.php
View source
<?php
namespace Drupal\Tests\entity\Unit\ParamConverter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\entity\ParamConverter\EntityRevisionParamConverter;
use Symfony\Component\Routing\Route;
class EntityRevisionParamConverterTest extends \PHPUnit_Framework_TestCase {
protected $entityTypeManager;
protected $converter;
protected function setUp() {
parent::setUp();
$this->converter = new EntityRevisionParamConverter($this
->prophesize(EntityTypeManagerInterface::class)
->reveal());
}
protected function getTestRoute() {
$route = new Route('/test/{test_revision}');
$route
->setOption('parameters', [
'test_revision' => [
'type' => 'entity_revision:test',
],
]);
return $route;
}
public function testNonApplyingRoute() {
$route = new Route('/test');
$this
->assertFalse($this->converter
->applies([], 'test_revision', $route));
}
public function testApplyingRoute() {
$route = $this
->getTestRoute();
$this
->assertTrue($this->converter
->applies($route
->getOption('parameters')['test_revision'], 'test_revision', $route));
}
public function testConvert() {
$entity = $this
->prophesize(EntityInterface::class)
->reveal();
$storage = $this
->prophesize(EntityStorageInterface::class);
$storage
->loadRevision(1)
->willReturn($entity);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('test')
->willReturn($storage
->reveal());
$converter = new EntityRevisionParamConverter($entity_type_manager
->reveal());
$route = $this
->getTestRoute();
$converter
->convert(1, $route
->getOption('parameters')['test_revision'], 'test_revision', [
'test_revision' => 1,
]);
}
}