You are here

public function SkinrApiTestCase::testSkinrSkinDefaults in Skinr 8.2

Test default skin configurations (in code).

File

src/Tests/skinr.test, line 630
Tests for the Skinr module.

Class

SkinrApiTestCase
Tests API functionality.

Namespace

Drupal\tracker\Tests

Code

public function testSkinrSkinDefaults() {
  $uuid = '501ff0c3-db03-0944-9910-3a788f38097a';

  // Default skin configuration object should not exist yet.
  $this
    ->assertFalse(skinr_skin_uuid_to_sid($uuid), 'Default skin configuration does not exist.');
  module_enable(array(
    'skinr_test_default',
  ));

  // Test loading raw defaults.
  $default_skins = _skinr_skin_get_defaults();

  // Skin configuration object provided via hook_skinr_skin_defaults() in
  // skinr_test.skinr_default.inc.
  $this
    ->assertTrue(isset($default_skins[$uuid]), 'Skin configuration in skinr_test.skinr_default.inc found.');
  unset($default_skins[$uuid]);

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

  // Load a default skin configuration object.
  $skin = skinr_skin_load_by_uuid($uuid);
  $this
    ->assertTrue($skin && $skin->uuid == $uuid, 'Successfully loaded default skin configuration.');

  // Test storage indicator.
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE, 'Storage indicator indicates stored in code.');

  // Overridden status should not change storage indicator.
  $skin->status = 0;
  skinr_skin_save($skin);
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE, 'Storage indicator indicates stored in code.');

  // Override a default skin configuration object.
  $skin->status = 1;
  $skin->options = array(
    'option3',
  );
  skinr_skin_save($skin);

  // Test storage indicator.
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE_OVERRIDDEN, 'Storage indicator indicates stored in code, but overridden in database.');

  // Revert a default skin configuration object.
  $this
    ->assertTrue(skinr_skin_revert($skin->sid), 'Successfully reverted skin configuration to default.');

  // Refresh skin configuration data.
  $skin = skinr_skin_load_by_uuid($uuid);

  // Test storage indicator.
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE, 'Storage indicator indicates stored in code.');

  // Test re-enabling module containing defaults; re-importing an existing
  // skin configuration.
  // Override default skin configuration.
  $skin->options = array(
    'option3',
  );
  skinr_skin_save($skin);

  // Disable, then re-enable module containing defaults.
  module_disable(array(
    'skinr_test_default',
  ));
  module_enable(array(
    'skinr_test_default',
  ));

  // Refresh skin configuration data.
  $skin = skinr_skin_load_by_uuid($uuid);

  // Test storage indicator.
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE_OVERRIDDEN, 'After enabling module containing already existing default skin configuration, storage indicator indicates stored in code, but overridden in database.');

  // Now test forced import.
  $default_skins = _skinr_skin_get_defaults();
  $default_skin = $default_skins[$uuid];
  $this
    ->assertTrue(skinr_skin_import($default_skin, TRUE), 'Successfully forced import of existing skin configuration.');

  // Refresh skin configuration data.
  $skin = skinr_skin_load_by_uuid($uuid);

  // Test storage indicator.
  $this
    ->assertTrue(skinr_skin_storage($skin) == SKINR_STORAGE_IN_CODE, 'After forcing import of existing default skin configuration, storage indicator indicates stored in code again.');
}