class DrupalGetProfileLegacyTest

Tests drupal_get_profile().

@group Bootstrap @group legacy

@runTestsInSeparateProcesses @preserveGlobalState disabled

Hierarchy

Expanded class hierarchy of DrupalGetProfileLegacyTest

See also

drupal_get_profile()

File

core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileLegacyTest.php, line 17

Namespace

Drupal\Tests\Core\Bootstrap
View source
class DrupalGetProfileLegacyTest extends UnitTestCase {
    
    /**
     * Config storage profile.
     *
     * @var string
     */
    protected $bootstrapConfigStorageProfile;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() {
        parent::setUp();
        include $this->root . '/core/includes/bootstrap.inc';
    }
    
    /**
     * Tests drupal_get_profile() deprecation.
     *
     * @expectedDeprecation drupal_get_profile() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use the install_profile container parameter or \Drupal::installProfile() instead. If you are accessing the value before it is written to configuration during the installer use the $install_state global. If you need to access the value before container is available you can use BootstrapConfigStorageFactory to load the value directly from configuration. See https://www.drupal.org/node/2538996
     * @dataProvider providerDrupalGetProfileInstallState
     */
    public function testDrupalGetProfileLegacyInstallState($expected, array $install_state_array = NULL, $container_parameter = FALSE) {
        // Set up global for install state.
        global $install_state;
        $install_state = $install_state_array;
        // Set up the container.
        $container = new ContainerBuilder();
        $container->setParameter('install_profile', $container_parameter);
        \Drupal::setContainer($container);
        // Do test.
        $this->assertEquals($expected, drupal_get_profile());
    }
    
    /**
     * Data provider for testDrupalGetProfileInstallState().
     *
     * @return array
     *   Test data.
     *
     * @see testDrupalGetProfileInstallState
     */
    public function providerDrupalGetProfileInstallState() {
        $tests = [];
        $tests['install_state_with_profile'] = [
            'test_profile',
            [
                'parameters' => [
                    'profile' => 'test_profile',
                ],
            ],
        ];
        $tests['install_state_with_no_profile_overriding_container_profile'] = [
            NULL,
            [
                'parameters' => [],
            ],
            'test_profile',
        ];
        $tests['no_install_state_with_container_profile'] = [
            'container_profile',
            NULL,
            'container_profile',
        ];
        return $tests;
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DrupalGetProfileLegacyTest::$bootstrapConfigStorageProfile protected property Config storage profile.
DrupalGetProfileLegacyTest::providerDrupalGetProfileInstallState public function Data provider for testDrupalGetProfileInstallState().
DrupalGetProfileLegacyTest::setUp protected function Overrides UnitTestCase::setUp
DrupalGetProfileLegacyTest::testDrupalGetProfileLegacyInstallState public function Tests drupal_get_profile() deprecation.
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.

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