class LibraryDependencyResolverTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php \Drupal\Tests\Core\Asset\LibraryDependencyResolverTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php \Drupal\Tests\Core\Asset\LibraryDependencyResolverTest
  3. 11.x core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php \Drupal\Tests\Core\Asset\LibraryDependencyResolverTest

@coversDefaultClass \Drupal\Core\Asset\LibraryDependencyResolver @group Asset

Hierarchy

Expanded class hierarchy of LibraryDependencyResolverTest

File

core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php, line 14

Namespace

Drupal\Tests\Core\Asset
View source
class LibraryDependencyResolverTest extends UnitTestCase {
    
    /**
     * The tested library dependency resolver.
     *
     * @var \Drupal\Core\Asset\LibraryDependencyResolver
     */
    protected $libraryDependencyResolver;
    
    /**
     * The mocked library discovery service.
     *
     * @var \Drupal\Core\Asset\LibraryDiscoveryInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $libraryDiscovery;
    
    /**
     * The mocked module handler.
     *
     * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $moduleHandler;
    
    /**
     * Test library data.
     *
     * @var array
     */
    protected $libraryData = [
        'no_deps_a' => [
            'js' => [],
            'css' => [],
        ],
        'no_deps_b' => [
            'js' => [],
            'css' => [],
        ],
        'no_deps_c' => [
            'js' => [],
            'css' => [],
        ],
        'no_deps_d' => [
            'js' => [],
            'css' => [],
        ],
        'deps_a' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/no_deps_a',
            ],
        ],
        'deps_b' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/no_deps_a',
                'test/no_deps_b',
            ],
        ],
        'deps_c' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/no_deps_b',
                'test/no_deps_a',
            ],
        ],
        'deps_d' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/no_deps_d',
            ],
        ],
        'nested_deps_a' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/deps_a',
            ],
        ],
        'nested_deps_b' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/nested_deps_a',
            ],
        ],
        'nested_deps_c' => [
            'js' => [],
            'css' => [],
            'dependencies' => [
                'test/nested_deps_b',
            ],
        ],
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->libraryDiscovery = $this->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')
            ->disableOriginalConstructor()
            ->onlyMethods([
            'getLibrariesByExtension',
        ])
            ->getMock();
        $this->libraryDiscovery
            ->expects($this->any())
            ->method('getLibrariesByExtension')
            ->with('test')
            ->willReturn($this->libraryData);
        $this->libraryDependencyResolver = new LibraryDependencyResolver($this->libraryDiscovery);
    }
    
    /**
     * Provides test data for ::testGetLibrariesWithDependencies().
     */
    public static function providerTestGetLibrariesWithDependencies() {
        return [
            // Empty list of libraries.
[
                [],
                [],
            ],
            // Without dependencies.
[
                [
                    'test/no_deps_a',
                ],
                [
                    'test/no_deps_a',
                ],
            ],
            [
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                ],
            ],
            [
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                ],
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                ],
            ],
            // Single-level (direct) dependencies.
[
                [
                    'test/deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                ],
            ],
            [
                [
                    'test/deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                    'test/deps_b',
                ],
            ],
            [
                [
                    'test/deps_c',
                ],
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/no_deps_b',
                    'test/deps_b',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/no_deps_b',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_b',
                    'test/deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/no_deps_b',
                    'test/deps_b',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_b',
                    'test/deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                    'test/deps_b',
                    'test/deps_a',
                ],
            ],
            [
                [
                    'test/deps_b',
                    'test/deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                    'test/deps_b',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_c',
                    'test/deps_b',
                ],
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                    'test/deps_c',
                    'test/deps_b',
                ],
            ],
            // Multi-level (indirect) dependencies.
[
                [
                    'test/nested_deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
            ],
            // Complex dependencies, combining the above, with many intersections.
[
                [
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                    'test/deps_c',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/no_deps_a',
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                    'test/deps_c',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/deps_c',
                    'test/no_deps_c',
                ],
                [
                    'test/no_deps_a',
                    'test/deps_a',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/no_deps_b',
                    'test/deps_c',
                    'test/no_deps_c',
                ],
            ],
        ];
    }
    
    /**
     * @covers ::getLibrariesWithDependencies
     *
     * @dataProvider providerTestGetLibrariesWithDependencies
     */
    public function testGetLibrariesWithDependencies(array $libraries, array $expected) : void {
        $this->assertEquals($expected, $this->libraryDependencyResolver
            ->getLibrariesWithDependencies($libraries));
    }
    
    /**
     * Provides test data for ::testGetMinimalRepresentativeSubset().
     */
    public static function providerTestGetMinimalRepresentativeSubset() {
        return [
            // Empty list of libraries.
[
                [],
                [],
            ],
            // Without dependencies.
[
                [
                    'test/no_deps_a',
                ],
                [
                    'test/no_deps_a',
                ],
            ],
            [
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                ],
                [
                    'test/no_deps_a',
                    'test/no_deps_b',
                ],
            ],
            [
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                ],
                [
                    'test/no_deps_b',
                    'test/no_deps_a',
                ],
            ],
            // Single-level (direct) dependencies.
[
                [
                    'test/deps_a',
                ],
                [
                    'test/deps_a',
                ],
            ],
            [
                [
                    'test/deps_b',
                ],
                [
                    'test/deps_b',
                ],
            ],
            [
                [
                    'test/deps_c',
                ],
                [
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_b',
                ],
                [
                    'test/deps_a',
                    'test/deps_b',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_c',
                ],
                [
                    'test/deps_a',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_b',
                    'test/deps_c',
                ],
                [
                    'test/deps_a',
                    'test/deps_b',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_b',
                    'test/deps_a',
                ],
                [
                    'test/deps_b',
                    'test/deps_a',
                ],
            ],
            [
                [
                    'test/deps_b',
                    'test/deps_c',
                ],
                [
                    'test/deps_b',
                    'test/deps_c',
                ],
            ],
            [
                [
                    'test/deps_c',
                    'test/deps_b',
                ],
                [
                    'test/deps_c',
                    'test/deps_b',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_d',
                    'test/no_deps_a',
                ],
                [
                    'test/deps_a',
                    'test/deps_d',
                ],
            ],
            [
                [
                    'test/deps_a',
                    'test/deps_d',
                    'test/no_deps_d',
                ],
                [
                    'test/deps_a',
                    'test/deps_d',
                ],
            ],
            // Multi-level (indirect) dependencies.
[
                [
                    'test/nested_deps_a',
                ],
                [
                    'test/nested_deps_a',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                ],
                [
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
                [
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                ],
                [
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                    'test/nested_deps_c',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_a',
                    'test/nested_deps_b',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            [
                [
                    'test/nested_deps_c',
                    'test/nested_deps_b',
                    'test/nested_deps_a',
                ],
                [
                    'test/nested_deps_c',
                ],
            ],
            // Complex dependencies, combining the above, with many intersections.
[
                [
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/no_deps_a',
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
                [
                    'test/deps_c',
                    'test/nested_deps_b',
                ],
            ],
            [
                [
                    'test/nested_deps_b',
                    'test/deps_c',
                    'test/no_deps_c',
                ],
                [
                    'test/nested_deps_b',
                    'test/deps_c',
                    'test/no_deps_c',
                ],
            ],
        ];
    }
    
    /**
     * @covers ::getMinimalRepresentativeSubset
     *
     * @dataProvider providerTestGetMinimalRepresentativeSubset
     */
    public function testGetMinimalRepresentativeSubset(array $libraries, array $expected) : void {
        $this->assertEquals($expected, $this->libraryDependencyResolver
            ->getMinimalRepresentativeSubset($libraries));
    }
    
    /**
     * @covers ::getMinimalRepresentativeSubset
     */
    public function testGetMinimalRepresentativeSubsetInvalidInput() : void {
        $this->expectException(\AssertionError::class);
        $this->expectExceptionMessage('$libraries can\'t contain duplicate items.');
        $this->libraryDependencyResolver
            ->getMinimalRepresentativeSubset([
            'test/no_deps_a',
            'test/no_deps_a',
        ]);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
LibraryDependencyResolverTest::$libraryData protected property Test library data.
LibraryDependencyResolverTest::$libraryDependencyResolver protected property The tested library dependency resolver.
LibraryDependencyResolverTest::$libraryDiscovery protected property The mocked library discovery service.
LibraryDependencyResolverTest::$moduleHandler protected property The mocked module handler.
LibraryDependencyResolverTest::providerTestGetLibrariesWithDependencies public static function Provides test data for ::testGetLibrariesWithDependencies().
LibraryDependencyResolverTest::providerTestGetMinimalRepresentativeSubset public static function Provides test data for ::testGetMinimalRepresentativeSubset().
LibraryDependencyResolverTest::setUp protected function Overrides UnitTestCase::setUp
LibraryDependencyResolverTest::testGetLibrariesWithDependencies public function @covers ::getLibrariesWithDependencies
LibraryDependencyResolverTest::testGetMinimalRepresentativeSubset public function @covers ::getMinimalRepresentativeSubset
LibraryDependencyResolverTest::testGetMinimalRepresentativeSubsetInvalidInput public function @covers ::getMinimalRepresentativeSubset
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 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::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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