1 icon.test protected IconTestCase::testIconHooks()

Tests providing and overriding icons with a module.

The "icon_test_location" state variable is checked in the icon_test.module implementation of hook_icon(). This determines which icon file is currently overriding the default core icon.

File

core/modules/simpletest/tests/icon.test, line 31
Tests for displaying and overriding icons in Backdrop.

Class

IconTestCase
Tests providing and overriding icons from both modules and themes.

Code

protected function testIconHooks() {
  // Default icon location with no overrides.
  $core_path = 'core/misc/icons/gear.svg';
  $this->assertIconsEqual($core_path, 'gear', FALSE, 'Default core icon is correct');

  $module_path = backdrop_get_path('module', 'icon_test');

  // Test an icon with the same name in the default icons directory.
  // Replace the "gear" icon with a duotone variant.
  state_set('icon_test_location', 'default');
  $this->assertIconsEqual($module_path . '/icons/gear.svg', 'gear', FALSE, 'Overridden icon is correct.');

  // Test an icon in a nested directory with the same name.
  // Replace the "gear" icon with a bold variant.
  state_set('icon_test_location', 'directory');
  $this->assertIconsEqual($module_path . '/icons/bold/gear.svg', 'gear', FALSE, 'Overridden icon in a sub-directory is correct.');

  // Test an icon in the default icons directory with a different name.
  // Replace the "gear" icon with a thin variant.
  state_set('icon_test_location', 'renamed');
  $this->assertIconsEqual($module_path . '/icons/gear-thin.svg', 'gear', FALSE, 'Overridden icon with a different name is correct.');

  // Test an icon in a nested directory with a different name.
  // Replace the "gear" icon with a bold variant.
  state_set('icon_test_location', 'renamed_directory');
  $this->assertIconsEqual($module_path . '/icons/bold/gear-bold.svg', 'gear', FALSE, 'Overridden icon with a different name and directory is correct.');

  // Test an icon outside of the module.
  // Replace the "gear" icon with the six-spoke version.
  state_set('icon_test_location', 'outside_module');
  $this->assertIconsEqual('core/misc/icons/gear-six.svg', 'gear', FALSE, 'Overridden icon outside of a module directory is correct.');

  // Test that the immutable version is still provided by core.
  $this->assertIconsEqual($core_path, 'gear', TRUE, 'Immutable icon is still provided from the default location even when overridden.');
}