function LibraryDiscoveryTest::testAssetLibraryDeprecation

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryTest::testAssetLibraryDeprecation()
  2. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryTest::testAssetLibraryDeprecation()
  3. 11.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryTest::testAssetLibraryDeprecation()

Tests getting a deprecated library.

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php, line 105

Class

LibraryDiscoveryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Asset%21LibraryDiscovery.php/class/LibraryDiscovery/9" title="Discovers available asset libraries in Drupal." class="local">\Drupal\Core\Asset\LibraryDiscovery</a> @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testAssetLibraryDeprecation() {
    $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
        // Convert deprecation error into a catchable exception.
        if ($severity === E_USER_DEPRECATED) {
            throw new \ErrorException($message, 0, $severity, $file, $line);
        }
        if ($previous_error_handler) {
            return $previous_error_handler($severity, $message, $file, $line);
        }
    });
    try {
        $this->libraryDiscovery
            ->getLibraryByName('test', 'test_3');
        $this->fail('No deprecation error triggered.');
    } catch (\ErrorException $e) {
        $this->assertSame('The "test/test_3" asset library is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the test_2 library instead. See https://www.example.com', $e->getMessage());
    }
    restore_error_handler();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.