Commit 8d989075 authored by catch's avatar catch
Browse files

Issue #3281430 by Spokje, deviantintegral, lauriii: Update non-migration Color...

Issue #3281430 by Spokje, deviantintegral, lauriii: Update non-migration Color tests to not use Bartik
parent 4ab64866
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" width="57" height="66" viewBox="471.5 467 57 66" enable-background="new 471.5 467 57 66"><path opacity=".2" fill="#303030" d="M528.5 504.965c0 16.634-13.123 27.615-28.24 27.615-10.29 0-19.894-5.523-24.978-14.167l.605-.027c1.313 1.192 3.39 2.58 7.404 2.515 4.77-.064 5.645-.875 9.855-2.756 22.716-10.17 26.925-19.457 27.736-21.59s2.013-5.587.756-9.415c-.242-.737-.42-1.333-.54-1.808-3.018-3.372-6.017-5.225-6.92-5.784-.14-.093-.29-.177-.43-.26l.44.26c2.01 1.247 14.314 8.782 14.314 25.417z"/><path fill="#fff" d="M509.09 518.507c1.006 0 2.077.065 2.83.568.756.503 1.193 1.63 1.445 2.263.25.634 0 1.006-.503 1.258-.438.25-.503.12-.94-.69-.44-.81-.82-1.63-3.01-1.63s-2.887.755-3.948 1.63c-1.062.876-1.443 1.193-1.825.69s-.253-1.006.437-1.63 1.825-1.63 2.888-2.077c1.06-.45 1.62-.383 2.625-.383zm-10.413 7.152c1.257 1.005 3.14 1.825 7.153 1.825 4.015 0 6.836-1.137 8.094-2.077.568-.438.82-.065.875.187.056.25.186.624-.252 1.07-.316.317-3.194 2.33-6.594 2.636-3.4.31-7.964.504-10.73-2.01-.438-.44-.316-1.07 0-1.323.317-.25.568-.438.94-.438.374.008.317.008.513.13z"/><path opacity=".2" fill="#aaa" d="M520.89 496.545c-.81 2.133-5.02 11.42-27.735 21.59-4.21 1.88-5.085 2.69-9.854 2.756-4.013.066-6.09-1.32-7.403-2.514l-.605.028h-.01c-2.393-4.042-3.78-8.783-3.78-13.952 0-7.852 2.97-13.654 6.287-17.687.11-.13.213-.26.325-.382 2.683-3.148 5.55-5.17 7.218-6.203.038-.028.075-.047.112-.065.42-.25.754-.447.987-.568 2.757-1.51 4.77-2.263 7.963-4.77.12-.092.242-.186.354-.288l.008-.01c.875-.754 1.64-1.76 2.18-3.4v-.008c.325-.97.567-2.16.716-3.65l.02.018c2.253 2.69 4.954 5.886 6.89 7.144.69.447 1.38.848 2.068 1.202l.3.15c2.243 1.126 4.507 1.945 6.807 3.333l.428.26c.903.56 3.902 2.412 6.92 5.784.12.475.298 1.07.54 1.807 1.274 3.837.073 7.292-.737 9.425z"/><path opacity=".5" fill="#333" d="M514.176 479.538c-3.26-2.077-6.464-2.887-9.603-4.955-1.938-1.267-4.64-4.47-6.893-7.162-.438 4.332-1.686 6.148-3.26 7.35-3.195 2.515-5.207 3.26-7.963 4.77-2.338 1.256-14.958 8.726-14.958 24.913 0 5.17 1.387 9.91 3.77 13.96 5.077 8.635 14.68 14.158 24.97 14.158 15.126 0 28.24-10.98 28.24-27.614 0-9.127-3.707-15.526-7.386-19.633-3.016-3.382-6.015-5.217-6.918-5.785zm7.627 7.34c4.117 5.15 6.213 11.23 6.213 18.077 0 3.968-.755 7.712-2.245 11.148-1.414 3.25-3.444 6.13-6.053 8.56-5.15 4.806-12.062 7.45-19.475 7.45-3.67 0-7.265-.698-10.692-2.086-3.372-1.36-6.398-3.297-9.016-5.774-5.532-5.225-8.57-12.257-8.57-19.8 0-6.716 2.18-12.695 6.483-17.753 3.288-3.865 6.836-6.007 8.196-6.743.67-.363 1.285-.69 1.89-.997 1.892-.97 3.68-1.89 6.14-3.818 1.312-.997 2.71-2.58 3.305-6.585 2.077 2.468 4.48 5.234 6.314 6.426 1.63 1.08 3.307 1.835 4.918 2.562 1.527.69 3.11 1.406 4.676 2.403l.056.037c4.62 2.84 7.06 5.896 7.86 6.892z"/><path opacity=".5" fill="#fff" d="M497.98 468.678c.874 2.58.753 3.893.753 4.452 0 .56-.307 2.077-1.313 2.832-.438.317-.568.568-.568.624 0 .25.568.438.568 1.006 0 .69-.317 2.077-3.642 5.393-3.325 3.316-8.103 6.278-11.8 8.103-3.698 1.826-5.468 1.686-5.97.81s.185-2.83 2.514-5.392l9.667-6.278 9.164-6.398.503-2.44"/><path fill="#fff" d="M497.98 468.613c-.57 4.145-1.826 5.393-3.512 6.715-2.83 2.133-5.588 3.446-6.212 3.763-1.63.82-7.535 4.08-10.608 8.784-.94 1.444 0 2.012.186 2.133.187.12 2.33.372 6.9-2.385 4.574-2.757 6.595-4.387 9.175-7.078 1.377-1.444 1.573-2.263 1.573-2.636 0-.438-.316-.624-.82-.754-.25-.065-.316-.187 0-.373.317-.186 1.622-.82 1.938-1.07.318-.25 1.827-1.257 1.882-2.887.065-1.63-.056-2.766-.503-4.21zm-14.112 45.628c.065-4.898 4.648-9.472 10.422-9.536 7.348-.065 12.424 7.283 16.13 7.208 3.14-.064 9.166-6.212 12.118-6.212 3.14 0 4.014 3.26 4.014 5.206 0 1.938-.623 5.458-2.133 7.656-1.51 2.198-2.44 3.008-4.2 2.888-2.264-.187-6.78-7.21-9.67-7.35-3.64-.12-11.547 7.6-17.75 7.6-3.763 0-4.9-.567-6.147-1.378-1.92-1.312-2.85-3.315-2.785-6.08z"/></svg>
+11 −0
Original line number Diff line number Diff line
@@ -29,5 +29,16 @@
  'css' => [
    'css/colors.css',
  ],
  'copy' => [
    'logo.svg',
  ],
  'preview_html' => 'color/preview.html',
  '#attached' => [
    'drupalSettings' => [
      'color' => [
        // Put the logo path into JavaScript for the live preview.
        'logo' => theme_get_setting('logo.url', 'color_test_theme'),
      ],
    ],
  ],
];
+5 −5
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\Tests\color\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\UserInterface;

/**
 * Ensures the color config schema is correct.
@@ -22,21 +23,20 @@ class ColorConfigSchemaTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  protected $defaultTheme = 'color_test_theme';

  /**
   * A user with administrative permissions.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;
  protected UserInterface $adminUser;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    \Drupal::service('theme_installer')->install(['bartik']);

    // Create user.
    $this->adminUser = $this->drupalCreateUser(['administer themes']);
@@ -46,8 +46,8 @@ protected function setUp(): void {
  /**
   * Tests whether the color config schema is valid.
   */
  public function testValidColorConfigSchema() {
    $settings_path = 'admin/appearance/settings/bartik';
  public function testValidColorConfigSchema(): void {
    $settings_path = 'admin/appearance/settings/color_test_theme';
    $edit['scheme'] = '';
    $edit['palette[bg]'] = '#123456';
    $this->drupalGet($settings_path);
+62 −110
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
namespace Drupal\Tests\color\Functional;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\UserInterface;

/**
 * Modify the Bartik theme colors and make sure the changes are reflected on the
 * frontend.
 * Modify theme colors and make sure the changes are reflected on the frontend.
 *
 * @group color
 * @group legacy
@@ -23,31 +23,14 @@ class ColorTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  protected $defaultTheme = 'color_test_theme';

  /**
   * A user with administrative permissions.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $bigUser;

  /**
   * An associative array of settings for themes.
   *
   * @var array
   */
  protected $themes;

  /**
   * Associative array of hex color strings to test.
   *
   * Keys are the color string and values are a Boolean set to TRUE for valid
   * colors.
   *
   * @var array
   */
  protected $colorTests;
  protected UserInterface $bigUser;

  /**
   * {@inheritdoc}
@@ -58,90 +41,50 @@ protected function setUp(): void {
    // Create user.
    $this->bigUser = $this->drupalCreateUser(['administer themes']);

    // This tests the color module in Bartik.
    $this->themes = [
      'bartik' => [
        'palette_input' => 'palette[bg]',
        'scheme' => 'slate',
        'scheme_color' => '#3b3b3b',
      ],
      'color_test_theme' => [
        'palette_input' => 'palette[bg]',
        'scheme' => 'custom',
        'scheme_color' => '#3b3b3b',
      ],
    ];
    \Drupal::service('theme_installer')->install(array_keys($this->themes));

    // Array filled with valid and not valid color values.
    $this->colorTests = [
      '#000' => TRUE,
      '#123456' => TRUE,
      '#abcdef' => TRUE,
      '#0' => FALSE,
      '#00' => FALSE,
      '#0000' => FALSE,
      '#00000' => FALSE,
      '123456' => FALSE,
      '#00000g' => FALSE,
    ];
    // Set 'color_test_theme' as the default theme.
    $this->config('system.theme')
      ->set('default', 'color_test_theme')
      ->save();
  }

  /**
   * Tests the Color module functionality.
   */
  public function testColor() {
    foreach ($this->themes as $theme => $test_values) {
      $this->_testColor($theme, $test_values);
    }
  }

  /**
   * Tests the Color module functionality using the given theme.
   *
   * @param string $theme
   *   The machine name of the theme being tested.
   * @param array $test_values
   *   An associative array of test settings (i.e. 'Main background', 'Text
   *   color', 'Color set', etc) for the theme which being tested.
   */
  public function _testColor($theme, $test_values) {
    $this->config('system.theme')
      ->set('default', $theme)
      ->save();
    $settings_path = 'admin/appearance/settings/' . $theme;
  public function testColor(): void {
    $settings_path = 'admin/appearance/settings/color_test_theme';
    $assert_session = $this->assertSession();

    $this->drupalLogin($this->bigUser);
    $this->drupalGet($settings_path);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContainsOnce('Color set');
    $assert_session->statusCodeEquals(200);
    $assert_session->pageTextContainsOnce('Color set');
    $edit['scheme'] = '';
    $edit[$test_values['palette_input']] = '#123456';
    $edit['palette[bg]'] = '#123456';
    $this->drupalGet($settings_path);
    $this->submitForm($edit, 'Save configuration');

    $this->drupalGet('<front>');
    $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
    $stylesheets = $this->config('color.theme.color_test_theme')
      ->get('stylesheets');
    /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
    $file_url_generator = \Drupal::service('file_url_generator');
    // Make sure the color stylesheet is included in the content.
    foreach ($stylesheets as $stylesheet) {
      $this->assertSession()->responseMatches('|' . $file_url_generator->generateString($stylesheet) . '|');
      $assert_session->responseMatches('|' . $file_url_generator->generateString($stylesheet) . '|');
      $stylesheet_content = implode("\n", file($stylesheet));
      $this->assertStringContainsString('color: #123456', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
      $this->assertStringContainsString('color: #123456', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet.');
    }

    $this->drupalGet($settings_path);
    $this->assertSession()->statusCodeEquals(200);
    $edit['scheme'] = $test_values['scheme'];
    $edit['scheme'] = 'custom';
    $this->drupalGet($settings_path);
    $this->submitForm($edit, 'Save configuration');

    $this->drupalGet('<front>');
    $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
    $stylesheets = $this->config('color.theme.color_test_theme')
      ->get('stylesheets');
    foreach ($stylesheets as $stylesheet) {
      $stylesheet_content = implode("\n", file($stylesheet));
      $this->assertStringContainsString('color: ' . $test_values['scheme_color'], $stylesheet_content, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
      $this->assertStringContainsString('color: #3b3b3b', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet.');
    }

    // Test with aggregated CSS turned on.
@@ -152,35 +95,45 @@ public function _testColor($theme, $test_values) {
    $stylesheets = \Drupal::state()->get('drupal_css_cache_files', []);
    $stylesheet_content = '';
    foreach ($stylesheets as $uri) {
      $stylesheet_content .= implode("\n", file(\Drupal::service('file_system')->realpath($uri)));
      $stylesheet_content .= implode("\n", file(\Drupal::service('file_system')
        ->realpath($uri)));
    }
    $this->assertStringNotContainsString('public://', $stylesheet_content, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
    $config->set('css.preprocess', 0);
    $config->save();
    $this->assertStringNotContainsString('public://', $stylesheet_content, 'Make sure the color paths have been translated to local paths.');
  }

  /**
   * Tests whether the provided color is valid.
   */
  public function testValidColor() {
    $this->config('system.theme')
      ->set('default', 'bartik')
      ->save();
    $settings_path = 'admin/appearance/settings/bartik';
  public function testValidColor(): void {
    $settings_path = 'admin/appearance/settings/color_test_theme';
    $assert_session = $this->assertSession();

    // Array filled with valid and not valid color values.
    $colorTests = [
      '#000' => TRUE,
      '#123456' => TRUE,
      '#abcdef' => TRUE,
      '#0' => FALSE,
      '#00' => FALSE,
      '#0000' => FALSE,
      '#00000' => FALSE,
      '123456' => FALSE,
      '#00000g' => FALSE,
    ];

    $this->drupalLogin($this->bigUser);
    $edit['scheme'] = '';

    foreach ($this->colorTests as $color => $is_valid) {
    foreach ($colorTests as $color => $is_valid) {
      $edit['palette[bg]'] = $color;
      $this->drupalGet($settings_path);
      $this->submitForm($edit, 'Save configuration');

      if ($is_valid) {
        $this->assertSession()->pageTextContains('The configuration options have been saved.');
        $assert_session->pageTextContains('The configuration options have been saved.');
      }
      else {
        $this->assertSession()->pageTextContains('You must enter a valid hexadecimal color value for Main background.');
        $assert_session->pageTextContains('You must enter a valid hexadecimal color value for Main background.');
      }
    }
  }
@@ -188,7 +141,7 @@ public function testValidColor() {
  /**
   * Tests whether the custom logo is used in the color preview.
   */
  public function testLogoSettingOverride() {
  public function testLogoSettingOverride(): void {
    $this->drupalLogin($this->bigUser);
    $edit = [
      'default_logo' => FALSE,
@@ -197,32 +150,31 @@ public function testLogoSettingOverride() {
    $this->drupalGet('admin/appearance/settings');
    $this->submitForm($edit, 'Save configuration');

    // Ensure that the overridden logo is present in Bartik, which is colorable.
    $this->drupalGet('admin/appearance/settings/bartik');
    // Ensure that the overridden logo is present in color_test_theme, which is
    // colorable.
    $this->drupalGet('admin/appearance/settings/color_test_theme');
    $this->assertSame($GLOBALS['base_path'] . 'core/misc/druplicon.png', $this->getDrupalSettings()['color']['logo']);
  }

  /**
   * Tests whether the scheme can be set, viewed anonymously and reset.
   */
  public function testOverrideAndResetScheme() {
    $settings_path = 'admin/appearance/settings/bartik';
    $this->config('system.theme')
      ->set('default', 'bartik')
      ->save();
  public function testOverrideAndResetScheme(): void {
    $settings_path = 'admin/appearance/settings/color_test_theme';
    $assert_session = $this->assertSession();

    // Place branding block with site name and slogan into header region.
    $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);

    $this->drupalGet('');
    // Make sure the color logo is not being used.
    $this->assertSession()->responseNotContains('files/color/bartik-');
    // Make sure the original bartik logo exists.
    $this->assertSession()->responseContains('bartik/logo.svg');
    $assert_session->responseNotContains('files/color/color_test_theme-');
    // Make sure the original color_test_theme logo exists.
    $assert_session->responseContains('color_test_theme/logo.svg');

    // Log in and set the color scheme to 'slate'.
    // Log in and set the color scheme to 'custom'.
    $this->drupalLogin($this->bigUser);
    $edit['scheme'] = 'slate';
    $edit['scheme'] = 'custom';
    $this->drupalGet($settings_path);
    $this->submitForm($edit, 'Save configuration');

@@ -230,9 +182,9 @@ public function testOverrideAndResetScheme() {
    $this->drupalLogout();
    $this->drupalGet('');
    // Make sure the color logo is being used.
    $this->assertSession()->responseContains('files/color/bartik-');
    // Make sure the original bartik logo does not exist.
    $this->assertSession()->responseNotContains('bartik/logo.svg');
    $assert_session->responseContains('files/color/color_test_theme-');
    // Make sure the original color_test_theme logo does not exist.
    $assert_session->responseNotContains('color_test_theme/logo.svg');

    // Log in and set the color scheme back to default (delete config).
    $this->drupalLogin($this->bigUser);
@@ -244,9 +196,9 @@ public function testOverrideAndResetScheme() {
    $this->drupalLogout();
    $this->drupalGet('');
    // Make sure the color logo is not being used.
    $this->assertSession()->responseNotContains('files/color/bartik-');
    // Make sure the original bartik logo exists.
    $this->assertSession()->responseContains('bartik/logo.svg');
    $assert_session->responseNotContains('files/color/color_test_theme-');
    // Make sure the original color_test_theme logo exists.
    $assert_session->responseContains('color_test_theme/logo.svg');
  }

}