DeprecatedClassesTest.php in Drupal 8
File
core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php
View source
<?php
namespace Drupal\Tests\path_alias\Unit;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\EventSubscriber\PathSubscriber;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Path\AliasManager as CoreAliasManager;
use Drupal\Core\Path\AliasManagerInterface as CoreAliasManagerInterface;
use Drupal\Core\Path\AliasWhitelist as CoreAliasWhitelist;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\PathProcessor\PathProcessorAlias;
use Drupal\Core\State\StateInterface;
use Drupal\path_alias\AliasManager;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\path_alias\AliasRepositoryInterface;
use Drupal\path_alias\AliasWhitelist;
use Drupal\path_alias\AliasWhitelistInterface;
use Drupal\path_alias\EventSubscriber\PathAliasSubscriber;
use Drupal\path_alias\PathProcessor\AliasPathProcessor;
use Drupal\system\Form\SiteInformationForm;
use Drupal\system\Plugin\Condition\RequestPath;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\argument_default\Raw;
class DeprecatedClassesTest extends UnitTestCase {
protected $aliasManager;
protected $aliasRepository;
protected $aliasWhitelist;
protected $cache;
protected $currentPathStack;
protected $languageManager;
protected $lock;
protected $state;
protected function setUp() {
parent::setUp();
$this->aliasManager = $this
->prophesize(AliasManagerInterface::class)
->reveal();
$this->aliasRepository = $this
->prophesize(AliasRepositoryInterface::class)
->reveal();
$this->aliasWhitelist = $this
->prophesize(AliasWhitelistInterface::class)
->reveal();
$this->cache = $this
->prophesize(CacheBackendInterface::class)
->reveal();
$this->currentPathStack = $this
->prophesize(CurrentPathStack::class)
->reveal();
$this->languageManager = $this
->prophesize(LanguageManagerInterface::class)
->reveal();
$this->lock = $this
->prophesize(LockBackendInterface::class)
->reveal();
$this->state = $this
->prophesize(StateInterface::class)
->reveal();
$container = $this
->prophesize(ContainerBuilder::class);
$container
->get('path_alias.manager')
->willReturn($this->aliasManager);
\Drupal::setContainer($container
->reveal());
}
public function testPathSubscriber() {
new PathSubscriber($this->aliasManager, $this->currentPathStack);
}
public function testPathAliasSubscriber() {
$object = new PathAliasSubscriber($this->aliasManager, $this->currentPathStack);
$this
->assertInstanceOf(PathSubscriber::class, $object);
}
public function testPathProcessorAlias() {
new PathProcessorAlias($this->aliasManager);
}
public function testAliasPathProcessor() {
$object = new AliasPathProcessor($this->aliasManager);
$this
->assertInstanceOf(PathProcessorAlias::class, $object);
}
public function testCoreAliasManager() {
new CoreAliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);
}
public function testAliasManager() {
$object = new AliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);
$this
->assertInstanceOf(CoreAliasManager::class, $object);
}
public function testCoreAliasWhitelist() {
new CoreAliasWhitelist('path_alias_whitelist', $this->cache, $this->lock, $this->state, $this->aliasRepository);
}
public function testAliasWhitelist() {
$object = new AliasWhitelist('path_alias_whitelist', $this->cache, $this->lock, $this->state, $this->aliasRepository);
$this
->assertInstanceOf(CoreAliasWhitelist::class, $object);
}
public function testDeprecatedSystemInformationFormConstructorParameters() {
$this
->assertDeprecatedConstructorParameter(SiteInformationForm::class);
}
public function testDeprecatedRequestPathConstructorParameters() {
$this
->assertDeprecatedConstructorParameter(RequestPath::class);
}
public function testDeprecatedRawConstructorParameters() {
$this
->assertDeprecatedConstructorParameter(Raw::class);
}
public function assertDeprecatedConstructorParameter($tested_class_name) {
$tested_class = new \ReflectionClass($tested_class_name);
$parameters = $tested_class
->getConstructor()
->getParameters();
$args = [];
foreach ($parameters as $parameter) {
$name = $parameter
->getName();
if ($name === 'alias_manager') {
$class_name = CoreAliasManagerInterface::class;
}
else {
$type = $parameter
->getType();
$class_name = $type ? (string) $type : NULL;
}
$args[$name] = isset($class_name) && $class_name !== 'array' ? $this
->prophesize($class_name)
->reveal() : [];
}
$instance = $tested_class
->newInstanceArgs($args);
$property = $tested_class
->getProperty('aliasManager');
$property
->setAccessible(TRUE);
$this
->assertInstanceOf(AliasManagerInterface::class, $property
->getValue($instance));
}
}