You are here

class DeprecatedClassesTest in Drupal 8

Tests deprecation of path alias core service classes.

@group path_alias @group legacy

Hierarchy

Expanded class hierarchy of DeprecatedClassesTest

File

core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php, line 34

Namespace

Drupal\Tests\path_alias\Unit
View source
class DeprecatedClassesTest extends UnitTestCase {

  /**
   * @var \Drupal\path_alias\AliasManagerInterface
   */
  protected $aliasManager;

  /**
   * @var \Drupal\path_alias\AliasRepositoryInterface
   */
  protected $aliasRepository;

  /**
   * @var \Drupal\path_alias\AliasWhitelistInterface
   */
  protected $aliasWhitelist;

  /**
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cache;

  /**
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  protected $currentPathStack;

  /**
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * @var \Drupal\Core\Lock\LockBackendInterface
   */
  protected $lock;

  /**
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * {@inheritdoc}
   */
  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();

    /** @var \Prophecy\Prophecy\ObjectProphecy $container */
    $container = $this
      ->prophesize(ContainerBuilder::class);
    $container
      ->get('path_alias.manager')
      ->willReturn($this->aliasManager);
    \Drupal::setContainer($container
      ->reveal());
  }

  /**
   * @covers \Drupal\Core\EventSubscriber\PathSubscriber::__construct
   *
   * @expectedDeprecation The \Drupal\Core\EventSubscriber\PathSubscriber class is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \Drupal\path_alias\EventSubscriber\PathAliasSubscriber. See https://drupal.org/node/3092086
   */
  public function testPathSubscriber() {
    new PathSubscriber($this->aliasManager, $this->currentPathStack);
  }

  /**
   * @covers \Drupal\path_alias\EventSubscriber\PathAliasSubscriber::__construct
   */
  public function testPathAliasSubscriber() {
    $object = new PathAliasSubscriber($this->aliasManager, $this->currentPathStack);
    $this
      ->assertInstanceOf(PathSubscriber::class, $object);
  }

  /**
   * @covers \Drupal\Core\PathProcessor\PathProcessorAlias::__construct
   *
   * @expectedDeprecation The \Drupal\Core\PathProcessor\PathProcessorAlias class is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \Drupal\path_alias\PathProcessor\AliasPathProcessor. See https://drupal.org/node/3092086
   */
  public function testPathProcessorAlias() {
    new PathProcessorAlias($this->aliasManager);
  }

  /**
   * @covers \Drupal\path_alias\PathProcessor\AliasPathProcessor::__construct
   */
  public function testAliasPathProcessor() {
    $object = new AliasPathProcessor($this->aliasManager);
    $this
      ->assertInstanceOf(PathProcessorAlias::class, $object);
  }

  /**
   * @covers \Drupal\Core\Path\AliasManager::__construct
   *
   * @expectedDeprecation The \Drupal\Core\Path\AliasManager class is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \Drupal\path_alias\AliasManager. See https://drupal.org/node/3092086
   */
  public function testCoreAliasManager() {
    new CoreAliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);
  }

  /**
   * @covers \Drupal\path_alias\AliasManager::__construct
   */
  public function testAliasManager() {
    $object = new AliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);
    $this
      ->assertInstanceOf(CoreAliasManager::class, $object);
  }

  /**
   * @covers \Drupal\Core\Path\AliasWhitelist::__construct
   *
   * @expectedDeprecation The \Drupal\Core\Path\AliasWhitelist class is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \Drupal\path_alias\AliasWhitelist. See https://drupal.org/node/3092086
   */
  public function testCoreAliasWhitelist() {
    new CoreAliasWhitelist('path_alias_whitelist', $this->cache, $this->lock, $this->state, $this->aliasRepository);
  }

  /**
   * @covers \Drupal\path_alias\AliasWhitelist::__construct
   */
  public function testAliasWhitelist() {
    $object = new AliasWhitelist('path_alias_whitelist', $this->cache, $this->lock, $this->state, $this->aliasRepository);
    $this
      ->assertInstanceOf(CoreAliasWhitelist::class, $object);
  }

  /**
   * @covers \Drupal\system\Form\SiteInformationForm::__construct
   *
   * @expectedDeprecation Calling \Drupal\system\Form\SiteInformationForm::__construct with \Drupal\Core\Path\AliasManagerInterface instead of \Drupal\path_alias\AliasManagerInterface is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086
   */
  public function testDeprecatedSystemInformationFormConstructorParameters() {
    $this
      ->assertDeprecatedConstructorParameter(SiteInformationForm::class);
  }

  /**
   * @covers \Drupal\system\Plugin\Condition\RequestPath::__construct
   *
   * @expectedDeprecation Calling \Drupal\system\Plugin\Condition\RequestPath::__construct with \Drupal\Core\Path\AliasManagerInterface instead of \Drupal\path_alias\AliasManagerInterface is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086
   */
  public function testDeprecatedRequestPathConstructorParameters() {
    $this
      ->assertDeprecatedConstructorParameter(RequestPath::class);
  }

  /**
   * @covers \Drupal\views\Plugin\views\argument_default\Raw::__construct
   *
   * @expectedDeprecation Calling \Drupal\views\Plugin\views\argument_default\Raw::__construct with \Drupal\Core\Path\AliasManagerInterface instead of \Drupal\path_alias\AliasManagerInterface is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086
   */
  public function testDeprecatedRawConstructorParameters() {
    $this
      ->assertDeprecatedConstructorParameter(Raw::class);
  }

  /**
   * Test that deprecation for the \Drupal\Core\Path\AliasManagerInterface.
   *
   * @param string $tested_class_name
   *   The name of the tested class.
   *
   * @dataProvider deprecatedConstructorParametersProvider
   *
   * @expectedDeprecation The \Drupal\Core\Path\AliasManagerInterface interface is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \Drupal\path_alias\AliasManagerInterface. See https://drupal.org/node/3092086
   */
  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));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeprecatedClassesTest::$aliasManager protected property
DeprecatedClassesTest::$aliasRepository protected property
DeprecatedClassesTest::$aliasWhitelist protected property
DeprecatedClassesTest::$cache protected property
DeprecatedClassesTest::$currentPathStack protected property
DeprecatedClassesTest::$languageManager protected property
DeprecatedClassesTest::$lock protected property
DeprecatedClassesTest::$state protected property
DeprecatedClassesTest::assertDeprecatedConstructorParameter public function Test that deprecation for the \Drupal\Core\Path\AliasManagerInterface.
DeprecatedClassesTest::setUp protected function Overrides UnitTestCase::setUp
DeprecatedClassesTest::testAliasManager public function @covers \Drupal\path_alias\AliasManager::__construct
DeprecatedClassesTest::testAliasPathProcessor public function @covers \Drupal\path_alias\PathProcessor\AliasPathProcessor::__construct
DeprecatedClassesTest::testAliasWhitelist public function @covers \Drupal\path_alias\AliasWhitelist::__construct
DeprecatedClassesTest::testCoreAliasManager public function @covers \Drupal\Core\Path\AliasManager::__construct
DeprecatedClassesTest::testCoreAliasWhitelist public function @covers \Drupal\Core\Path\AliasWhitelist::__construct
DeprecatedClassesTest::testDeprecatedRawConstructorParameters public function @covers \Drupal\views\Plugin\views\argument_default\Raw::__construct
DeprecatedClassesTest::testDeprecatedRequestPathConstructorParameters public function @covers \Drupal\system\Plugin\Condition\RequestPath::__construct
DeprecatedClassesTest::testDeprecatedSystemInformationFormConstructorParameters public function @covers \Drupal\system\Form\SiteInformationForm::__construct
DeprecatedClassesTest::testPathAliasSubscriber public function @covers \Drupal\path_alias\EventSubscriber\PathAliasSubscriber::__construct
DeprecatedClassesTest::testPathProcessorAlias public function @covers \Drupal\Core\PathProcessor\PathProcessorAlias::__construct
DeprecatedClassesTest::testPathSubscriber public function @covers \Drupal\Core\EventSubscriber\PathSubscriber::__construct
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.