function InstalledPackagesListTest::testCorePackages

@covers ::getCorePackages

File

core/modules/package_manager/tests/src/Unit/InstalledPackagesListTest.php, line 95

Class

InstalledPackagesListTest
@coversDefaultClass \Drupal\package_manager\InstalledPackagesList

Namespace

Drupal\Tests\package_manager\Unit

Code

public function testCorePackages() : void {
    $data = [
        'drupal/core' => InstalledPackage::createFromArray([
            'name' => 'drupal/core',
            'version' => \Drupal::VERSION,
            'type' => 'drupal-core',
            'path' => __DIR__,
        ]),
        'drupal/core-dev' => InstalledPackage::createFromArray([
            'name' => 'drupal/core-dev',
            'version' => \Drupal::VERSION,
            'type' => 'metapackage',
            'path' => NULL,
        ]),
        'drupal/core-dev-pinned' => InstalledPackage::createFromArray([
            'name' => 'drupal/core-dev-pinned',
            'version' => \Drupal::VERSION,
            'type' => 'metapackage',
            'path' => NULL,
        ]),
        'drupal/core-composer-scaffold' => InstalledPackage::createFromArray([
            'name' => 'drupal/core-composer-scaffold',
            'version' => \Drupal::VERSION,
            'type' => 'composer-plugin',
            'path' => __DIR__,
        ]),
        'drupal/core-project-message' => [
            'name' => 'drupal/core-project-message',
            'version' => \Drupal::VERSION,
            'type' => 'composer-plugin',
            'path' => __DIR__,
        ],
        'drupal/core-vendor-hardening' => InstalledPackage::createFromArray([
            'name' => 'drupal/core-vendor-hardening',
            'version' => \Drupal::VERSION,
            'type' => 'composer-plugin',
            'path' => __DIR__,
        ]),
        'drupal/not-core' => InstalledPackage::createFromArray([
            'name' => 'drupal/not-core',
            'version' => '1.0.0',
            'type' => 'drupal-module',
            'path' => __DIR__,
        ]),
    ];
    $list = new InstalledPackagesList($data);
    $this->assertArrayNotHasKey('drupal/not-core', $list->getCorePackages());
    // Tests that we don't get core packages intended for development when
    // include_dev is set to FALSE.
    $core_packages_no_dev = $list->getCorePackages(FALSE);
    $this->assertArrayNotHasKey('drupal/core-dev', $core_packages_no_dev);
    $this->assertArrayNotHasKey('drupal/core-dev-pinned', $core_packages_no_dev);
    // We still get other packages as intended.
    $this->assertArrayHasKey('drupal/core', $core_packages_no_dev);
    // If drupal/core-recommended is in the list, it should supersede
    // drupal/core.
    $this->assertArrayHasKey('drupal/core', $list->getCorePackages());
    $data['drupal/core-recommended'] = InstalledPackage::createFromArray([
        'name' => 'drupal/core-recommended',
        'version' => \Drupal::VERSION,
        'type' => 'metapackage',
        'path' => NULL,
    ]);
    $list = new InstalledPackagesList($data);
    $this->assertArrayNotHasKey('drupal/core', $list->getCorePackages());
}

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