You are here

public function SkinrApiTest::testSkinrSkinInfo in Skinr 8.2

Tests hook_skinr_skin_info().

File

src/Tests/SkinrApiTest.php, line 192
Contains \Drupal\skinr\Tests\SkinrApiTest.

Class

SkinrApiTest
Tests Skinr API functionality.

Namespace

Drupal\skinr\Tests

Code

public function testSkinrSkinInfo() {

  // Verify that skinr_get_skin_info() finds and returns all registered skins
  // in $module.skinr.inc files as well as Skinr plugin files, but does not
  // return skins that are incompatible with the current Skinr API version.
  $skin_info = skinr_get_skin_info();
  $path = drupal_get_path('module', 'skinr_test');

  // skinr_test_font is registered via hook_skinr_skin_info() in
  // skinr_test.skinr.inc.
  $this
    ->assertTrue(isset($skin_info['skinr_test_font']), 'Skin registered in $module.skinr.inc found.');
  $this
    ->assertEqual($skin_info['skinr_test_font']['source']['path'], $path, t('Skin path points to module directory: @path', array(
    '@path' => $skin_info['skinr_test_font']['source']['path'],
  )));
  unset($skin_info['skinr_test_font']);

  // Test that an invalid class is not included.
  $this
    ->assertTrue(isset($skin_info['skinr_test_invalid_class']), 'Skin with invalid class found.');
  $this
    ->assertEqual($skin_info['skinr_test_invalid_class']['options']['invalid_class']['class'], array(), 'Invalid skin class is reset to array.');
  unset($skin_info['skinr_test_invalid_class']);

  // skinr_test_example is registered via hook_skinr_skin_PLUGIN_info() in
  // skins/example.inc.
  $this
    ->assertTrue(isset($skin_info['skinr_test_example']), 'Skin registered in plugin file found.');
  $this
    ->assertEqual($skin_info['skinr_test_example']['source']['path'], $path . '/skins/example', t('Skin path points to plugin directory: @path', array(
    '@path' => $skin_info['skinr_test_example']['source']['path'],
  )));
  unset($skin_info['skinr_test_example']);

  // skinr_test_basetheme is registered via hook_skinr_skin_info() in
  // skinr_test_basetheme.skinr.inc.
  $this
    ->assertTrue(isset($skin_info['skinr_test_basetheme']), 'Skin registered in $basetheme.skinr.inc found.');
  $this
    ->assertEqual($skin_info['skinr_test_basetheme']['source']['path'], $path . '/themes/skinr_test_basetheme', t('Skin path points to basetheme directory: @path', array(
    '@path' => $skin_info['skinr_test_basetheme']['source']['path'],
  )));
  $default_theme = \Drupal::config('system.theme')
    ->get('default');
  $this
    ->assertEqual($skin_info['skinr_test_basetheme']['status'][$default_theme], 0, 'Basetheme skin is disabled for default theme.');
  $this
    ->assertEqual($skin_info['skinr_test_basetheme']['status']['skinr_test_basetheme'], 1, 'Basetheme skin is enabled for Skinr test basetheme.');
  unset($skin_info['skinr_test_basetheme']);

  // skinr_test_subtheme is registered via hook_skinr_skin_info() in
  // skinr_test_subtheme.skinr.inc.
  $this
    ->assertTrue(isset($skin_info['skinr_test_subtheme']), 'Skin registered in $subtheme.skinr.inc found.');
  $this
    ->assertEqual($skin_info['skinr_test_subtheme']['source']['path'], $path . '/themes/skinr_test_subtheme', t('Skin path points to subtheme directory: @path', array(
    '@path' => $skin_info['skinr_test_subtheme']['source']['path'],
  )));
  unset($skin_info['skinr_test_subtheme']);

  // Ensure that skinr_test_incompatible is not contained.
  $this
    ->assertTrue(!isset($skin_info['skinr_test_incompatible']), 'Incompatible skin not found.');

  // After asserting all expected, the list of skins should be empty.
  $this
    ->assertTrue(empty($skin_info), t('No unexpected skins found: <pre>@data</pre>', array(
    '@data' => var_export($skin_info, TRUE),
  )));
}