public function SkinrContextApiTestCase::testSkinrContextGroupDefaults in Skinr 7.2
Same name and namespace in other branches
- 8.2 skinr_context/tests/skinr_context.test \SkinrContextApiTestCase::testSkinrContextGroupDefaults()
Test default skin settings groups (in code).
File
- skinr_context/
tests/ skinr_context.test, line 175 - Tests for the Skinr Context module.
Class
- SkinrContextApiTestCase
- Tests Skinr Context API functionality.
Code
public function testSkinrContextGroupDefaults() {
$gid = 'block:system__user-menu:default';
$uuid = '501ff0c3-db03-0944-9910-3a788f38097a';
// Default skin configuration object should not exist yet.
$this
->assertFalse(skinr_context_group_load($gid), 'Default skin settings group does not exist.');
module_enable(array(
'skinr_context_test_default',
));
// Test loading raw defaults.
$default_groups = _skinr_context_group_get_defaults();
// Skin configuration object provided via hook_skinr_context_group_defaults()
// in skinr_context_test_default.skinr_default.inc.
$this
->assertTrue(isset($default_groups[$gid]), 'Skin settings group in skinr_context_test_default.skinr_default.inc found.');
unset($default_groups[$gid]);
// After asserting all expected, the list of default skins should be empty.
$this
->assertTrue(empty($default_groups), t('No unexpected settings groups found: <pre>@data</pre>', array(
'@data' => var_export($default_groups, TRUE),
)));
// Load a default skin settings group object.
$group = skinr_context_group_load($gid);
$this
->assertTrue($group && $group->gid == $gid, 'Successfully loaded default skin settings group.');
// Test storage indicator.
$this
->assertTrue(skinr_context_group_storage($group) == SKINR_STORAGE_IN_CODE, 'Storage indicator indicates stored in code.');
// Test that skin configuration has valid gid. If load order is wrong, it
// will be missing.
$default_skin = skinr_skin_load_by_uuid('501ff0c3-db03-0944-9910-3a788f38097a');
$this
->verbose(highlight_string(print_r($default_skin, TRUE), TRUE));
$this
->assertTrue($default_skin->gid == $group->gid, 'Valid GID found for default skin configuration.');
// Overridden status should not change storage indicator.
$group->status = 0;
skinr_context_group_save($group);
$this
->assertTrue(skinr_context_group_storage($group) == SKINR_STORAGE_IN_CODE, 'Storage indicator indicates stored in code.');
// Override a default skin configuration object.
$group->status = 1;
$group->conditions['sitewide']['values'] = array(
0 => 0,
);
skinr_context_group_save($group);
// Test storage indicator.
$this
->assertTrue(skinr_context_group_storage($group) == SKINR_STORAGE_IN_CODE_OVERRIDDEN, 'Storage indicator indicates stored in code, but overridden in database.');
// Revert a default skin settings group object.
$this
->assertTrue(skinr_context_group_revert($group->gid), 'Successfully reverted skin settings group to default.');
// Refresh skin settings group data.
$group = skinr_context_group_load($gid);
// Test storage indicator.
$this
->assertTrue(skinr_context_group_storage($group) == 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 settings group.
$group->conditions['sitewide']['values'] = array(
0 => 0,
);
skinr_context_group_save($group);
// Disable, then re-enable module containing defaults.
module_disable(array(
'skinr_context_test_default',
));
module_enable(array(
'skinr_context_test_default',
));
// Refresh skin settings group data.
$group = skinr_context_group_load($gid);
// Test storage indicator.
$this
->assertTrue(skinr_context_group_storage($group) == 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_groups = _skinr_context_group_get_defaults();
$default_group = $default_groups[$gid];
$this
->assertTrue(skinr_context_group_import($default_group, TRUE), 'Successfully forced import of existing skin settings group.');
// Refresh skin settings group data.
$group = skinr_context_group_load($gid);
// Test storage indicator.
$this
->assertTrue(skinr_context_group_storage($group) == SKINR_STORAGE_IN_CODE, 'After forcing import of existing default skin settings group, storage indicator indicates stored in code again.');
// Test creation of default skin settings group when a default skin doesn't
// include one.
$groupless_skin = skinr_skin_load_by_uuid('20cc8380-d1d5-11e3-9c1a-0800200c9a66');
$this
->verbose(highlight_string(print_r($groupless_skin, TRUE), TRUE));
$this
->assertTrue($groupless_skin->gid == 'block:system__help:default', 'Valid GID found for default skin configuration without gid.');
}