function UpdateContribTest::testUpdateShowDisabledThemes

Same name in other branches
  1. 9 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateShowDisabledThemes()
  2. 8.9.x core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateShowDisabledThemes()
  3. 10 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testUpdateShowDisabledThemes()

Tests that uninstalled themes are only shown when desired.

@todo https://www.drupal.org/node/2338175 extensions can not be hidden and base themes have to be installed.

File

core/modules/update/tests/src/Functional/UpdateContribTest.php, line 341

Class

UpdateContribTest
Tests how the Update Manager handles contributed modules and themes.

Namespace

Drupal\Tests\update\Functional

Code

public function testUpdateShowDisabledThemes() : void {
    $update_settings = $this->config('update.settings');
    // Make sure all the update_test_* themes are uninstalled.
    $extension_config = $this->config('core.extension');
    foreach ($extension_config->get('theme') as $theme => $weight) {
        if (str_starts_with($theme, 'update_test_')) {
            $extension_config->clear("theme.{$theme}");
        }
    }
    $extension_config->save();
    // Define the initial state for core and the test contrib themes.
    $this->mockInstalledExtensionsInfo([
        // The update_test_base_theme should be visible and up to date.
'update_test_base_theme' => [
            'project' => 'update_test_base_theme',
            'version' => '8.x-1.1',
            'hidden' => FALSE,
        ],
        // The update_test_subtheme should be visible and up to date.
'update_test_subtheme' => [
            'project' => 'update_test_subtheme',
            'version' => '8.x-1.0',
            'hidden' => FALSE,
        ],
    ]);
    // When there are contributed modules in the site's file system, the
    // total number of attempts made in the test may exceed the default value
    // of update_max_fetch_attempts. Therefore this variable is set very high
    // to avoid test failures in those cases.
    $update_settings->set('fetch.max_attempts', 99999)
        ->save();
    $xml_mapping = [
        'drupal' => '8.0.0',
        'update_test_subtheme' => '1_0',
        'update_test_base_theme' => '1_1-sec',
    ];
    foreach ([
        TRUE,
        FALSE,
    ] as $check_disabled) {
        $update_settings->set('check.disabled_extensions', $check_disabled)
            ->save();
        $this->refreshUpdateStatus($xml_mapping);
        // In neither case should we see the "Themes" heading for installed
        // themes.
        // Use regex pattern because we need to match 'Themes' case sensitively.
        $this->assertSession()
            ->pageTextNotMatches('/Themes/');
        if ($check_disabled) {
            $this->assertSession()
                ->pageTextContains('Uninstalled themes');
            $this->assertSession()
                ->linkExists('Update test base theme');
            $this->assertSession()
                ->linkByHrefExists('http://example.com/project/update_test_base_theme');
            $this->assertSession()
                ->linkExists('Update test subtheme');
            $this->assertSession()
                ->linkByHrefExists('http://example.com/project/update_test_subtheme');
        }
        else {
            $this->assertSession()
                ->pageTextNotContains('Uninstalled themes');
            $this->assertSession()
                ->linkNotExists('Update test base theme');
            $this->assertSession()
                ->linkByHrefNotExists('http://example.com/project/update_test_base_theme');
            $this->assertSession()
                ->linkNotExists('Update test subtheme');
            $this->assertSession()
                ->linkByHrefNotExists('http://example.com/project/update_test_subtheme');
        }
    }
}

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