You are here

public function FusionApplyApiTestCase::testFusionApplySkinLoadSave in Fusion Accelerator 7

Same name and namespace in other branches
  1. 7.2 fusion_apply/tests/fusion_apply.test \FusionApplyApiTestCase::testFusionApplySkinLoadSave()

Test fusion_apply_skin_save() against invalid entries.

File

fusion_apply/tests/fusion_apply.test, line 365
Tests for the Fusion Apply module.

Class

FusionApplyApiTestCase
Tests API functionality.

Code

public function testFusionApplySkinLoadSave() {

  // Only save valid skins.
  $skin = (object) array(
    'theme' => '',
    'module' => 'block',
    'element' => 'system__user-menu',
    'skin' => 'fusion_apply_test_subtheme',
    'options' => array(
      'option1',
      'option2',
    ),
    'status' => 1,
  );
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->theme was empty.');
  $skin->theme = 'fusion_apply_test_subtheme';
  $skin->module = '';
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->module was empty.');
  $skin->module = 'block';
  $skin->element = '';
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->element was empty.');
  $skin->element = 'system-user-menu';
  $skin->skin = '';
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->skin was empty.');
  $skin->skin = 'fusion_apply_test_subtheme';
  $skin->options = '';
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->options was not an array.');
  $skin->options = array();
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->options was an empty array.');
  $skin->options = array(
    'option1' => 0,
    'option2' => 0,
  );
  $this
    ->assertFalse(fusion_apply_skin_save($skin), 'Skin configuration object was not saved when $skin->options was a complex empty array.');
  $skin->options = array(
    'option1',
    'option2',
  );
  $this
    ->assertTrue(fusion_apply_skin_save($skin), 'Skin configuration object was saved.');
  $this
    ->assertTrue(isset($skin->sid), 'The sid was added to the skin configuration object.');

  // Test loading a skin configuration.
  $loaded_skin = fusion_apply_skin_load($skin->sid);
  $this
    ->assertTrue(is_array($skin->options), 'Options for the skin configuration object were unserialized.');
  $this
    ->assertTrue($loaded_skin->theme == $skin->theme && $loaded_skin->module == $skin->module && $loaded_skin->element == $skin->element && $loaded_skin->status == $skin->status && $loaded_skin->options[0] == $skin->options[0] && $loaded_skin->options[1] == $skin->options[1], 'Skin configuration object was loaded properly.');

  // Save a second skin.
  $second_skin = (object) array(
    'theme' => 'fusion_apply_test_subtheme',
    'module' => 'block',
    'element' => 'system__main',
    'skin' => 'fusion_apply_test_subtheme',
    'options' => array(
      'option3',
    ),
    'status' => 1,
  );
  fusion_apply_skin_save($second_skin);

  // Test loading multiple skin configurations.
  $skins = fusion_apply_skin_load_multiple(array(
    $skin->sid,
    $second_skin->sid,
  ));
  $this
    ->assertTrue(count($skins) == 2 && isset($skins[$skin->sid]->sid) && isset($skins[$second_skin->sid]->sid), 'Successfully loaded multiple skins.');

  // Test loading all skin configurations.
  $skins = fusion_apply_skin_load_multiple();
  $this
    ->assertTrue(count($skins) == 2 && isset($skins[$skin->sid]->sid) && isset($skins[$second_skin->sid]->sid), 'Successfully loaded all skins.');
}