class CssCollectionGrouperUnitTest

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

Tests the CSS asset collection grouper.

@group Asset

Hierarchy

Expanded class hierarchy of CssCollectionGrouperUnitTest

File

core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php, line 13

Namespace

Drupal\Tests\Core\Asset
View source
class CssCollectionGrouperUnitTest extends UnitTestCase {
    
    /**
     * A CSS asset grouper.
     *
     * @var \Drupal\Core\Asset\CssCollectionGrouper
     */
    protected $grouper;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->grouper = new CssCollectionGrouper();
    }
    
    /**
     * Tests \Drupal\Core\Asset\CssCollectionGrouper.
     */
    public function testGrouper() {
        $css_assets = [
            'system.base.css' => [
                'group' => -100,
                'type' => 'file',
                'weight' => 0.012,
                'media' => 'all',
                'preprocess' => TRUE,
                'data' => 'core/modules/system/system.base.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'system.base.css',
            ],
            'js.module.css' => [
                'group' => -100,
                'type' => 'file',
                'weight' => 0.013,
                'media' => 'all',
                'preprocess' => TRUE,
                'data' => 'core/modules/system/js.module.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'js.module.css',
            ],
            'jquery.ui.core.css' => [
                'group' => -100,
                'type' => 'file',
                'weight' => 0.004,
                'media' => 'all',
                'preprocess' => TRUE,
                'data' => 'core/misc/ui/themes/base/jquery.ui.core.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'jquery.ui.core.css',
            ],
            'field.css' => [
                'group' => 0,
                'type' => 'file',
                'weight' => 0.011,
                'media' => 'all',
                'preprocess' => TRUE,
                'data' => 'core/modules/field/theme/field.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'field.css',
            ],
            'external.css' => [
                'group' => 0,
                'type' => 'external',
                'weight' => 0.008999999999999999,
                'media' => 'all',
                'preprocess' => TRUE,
                'data' => 'http://example.com/external.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'external.css',
            ],
            'elements.css' => [
                'group' => 100,
                'media' => 'all',
                'type' => 'file',
                'weight' => 0.001,
                'preprocess' => TRUE,
                'data' => 'core/themes/example/css/base/elements.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'elements.css',
            ],
            'print.css' => [
                'group' => 100,
                'media' => 'print',
                'type' => 'file',
                'weight' => 0.003,
                'preprocess' => TRUE,
                'data' => 'core/themes/example/css/print.css',
                'browsers' => [
                    'IE' => TRUE,
                    '!IE' => TRUE,
                ],
                'basename' => 'print.css',
            ],
        ];
        $groups = $this->grouper
            ->group($css_assets);
        $this->assertCount(5, $groups, "5 groups created.");
        // Check group 1.
        $group = $groups[0];
        $this->assertSame(-100, $group['group']);
        $this->assertSame('file', $group['type']);
        $this->assertSame('all', $group['media']);
        $this->assertTrue($group['preprocess']);
        $this->assertCount(3, $group['items']);
        $this->assertContainsEquals($css_assets['system.base.css'], $group['items']);
        $this->assertContainsEquals($css_assets['js.module.css'], $group['items']);
        // Check group 2.
        $group = $groups[1];
        $this->assertSame(0, $group['group']);
        $this->assertSame('file', $group['type']);
        $this->assertSame('all', $group['media']);
        $this->assertTrue($group['preprocess']);
        $this->assertCount(1, $group['items']);
        $this->assertContainsEquals($css_assets['field.css'], $group['items']);
        // Check group 3.
        $group = $groups[2];
        $this->assertSame(0, $group['group']);
        $this->assertSame('external', $group['type']);
        $this->assertSame('all', $group['media']);
        $this->assertTrue($group['preprocess']);
        $this->assertCount(1, $group['items']);
        $this->assertContainsEquals($css_assets['external.css'], $group['items']);
        // Check group 4.
        $group = $groups[3];
        $this->assertSame(100, $group['group']);
        $this->assertSame('file', $group['type']);
        $this->assertSame('all', $group['media']);
        $this->assertTrue($group['preprocess']);
        $this->assertCount(1, $group['items']);
        $this->assertContainsEquals($css_assets['elements.css'], $group['items']);
        // Check group 5.
        $group = $groups[4];
        $this->assertSame(100, $group['group']);
        $this->assertSame('file', $group['type']);
        $this->assertSame('print', $group['media']);
        $this->assertTrue($group['preprocess']);
        $this->assertCount(1, $group['items']);
        $this->assertContainsEquals($css_assets['print.css'], $group['items']);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
CssCollectionGrouperUnitTest::$grouper protected property A CSS asset grouper.
CssCollectionGrouperUnitTest::setUp protected function Overrides UnitTestCase::setUp
CssCollectionGrouperUnitTest::testGrouper public function Tests \Drupal\Core\Asset\CssCollectionGrouper.
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.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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.
UnitTestCase::setUpBeforeClass public static function

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