You are here

public function SkinrContextApiTestCase::testSkinrContextGroupLoadSave in Skinr 8.2

Same name and namespace in other branches
  1. 7.2 skinr_context/tests/skinr_context.test \SkinrContextApiTestCase::testSkinrContextGroupLoadSave()

Test skinr_skin_save() against invalid entries.

File

skinr_context/tests/skinr_context.test, line 76
Tests for the Skinr Context module.

Class

SkinrContextApiTestCase
Tests Skinr Context API functionality.

Code

public function testSkinrContextGroupLoadSave() {

  // @todo Validation for groups.
  // Only save valid groups.
  $group = (object) array(
    'gid' => 'block:system__user-menu:default',
    'module' => 'block',
    'element' => 'system__user-menu',
    'title' => 'Default',
    'description' => '',
    'conditions' => array(
      'sitewide' => array(
        'values' => array(
          1 => 1,
        ),
      ),
    ),
    'condition_mode' => CONTEXT_CONDITION_MODE_OR,
    'weight' => 0,
    'status' => 1,
  );
  $this
    ->assertTrue(skinr_context_group_save($group), 'Skin settings group object saved.');
  $this
    ->assertTrue(isset($group->gid), 'Gid added to skin settings group object.');

  // Test loading a group.
  $loaded_group = skinr_context_group_load($group->gid);
  $this
    ->assertTrue(is_array($loaded_group->conditions), 'Conditions for skin settings group object unserialized.');
  $this
    ->assertTrue($loaded_group->gid == $group->gid && $loaded_group->module == $group->module && $loaded_group->element == $group->element && $loaded_group->title == $group->title && $loaded_group->description == $group->description && $loaded_group->condition_mode == $group->condition_mode && $loaded_group->weight == $group->weight && $loaded_group->status == $group->status && isset($loaded_group->conditions['sitewide']) && isset($loaded_group->conditions['sitewide']['values']) && $loaded_group->conditions['sitewide']['values'][1] == $group->conditions['sitewide']['values'][1], 'Skin settings group object loaded properly.');

  // Save a second group.
  $second_group = (object) array(
    'gid' => 'block:system__main-menu:default',
    'module' => 'block',
    'element' => 'system__main-menu',
    'title' => 'Default',
    'description' => '',
    'conditions' => array(
      'sitewide' => array(
        'values' => array(
          1 => 1,
        ),
      ),
    ),
    'condition_mode' => CONTEXT_CONDITION_MODE_OR,
    'weight' => 0,
    'status' => 1,
  );
  skinr_context_group_save($second_group);

  // Test loading multiple groups.
  $groups = skinr_context_group_load_multiple(array(
    $group->gid,
    $second_group->gid,
  ));
  $this
    ->assertTrue(count($groups) == 2 && isset($groups[$group->gid]->gid) && isset($groups[$second_group->gid]->gid), 'Successfully loaded multiple skin settings groups.');

  // Test loading all skin settings groups.
  drupal_static_reset('skinr_context_group_load_multiple');
  $groups = skinr_context_group_load_multiple(FALSE);
  $this
    ->assertTrue(count($groups) == 2 && isset($groups[$group->gid]->gid) && isset($groups[$second_group->gid]->gid), 'Successfully loaded all skin settings groups.');

  // Test deleting groups.
  $third_group = (object) array(
    'gid' => 'block:system__main-menu:alternate',
    'module' => 'block',
    'element' => 'system__main-menu',
    'title' => 'Alternate',
    'description' => '',
    'conditions' => array(
      'sitewide' => array(
        'values' => array(
          1 => 1,
        ),
      ),
    ),
    'condition_mode' => CONTEXT_CONDITION_MODE_OR,
    'weight' => 0,
    'status' => 1,
  );
  $this
    ->assertTrue(skinr_context_group_save($third_group), 'Skin settings group object saved.');

  // Delete a single group.
  $gid = $third_group->gid;
  skinr_context_group_delete($gid);
  $this
    ->assertFalse(skinr_context_group_load($gid), 'Successfully deleted a skin settings group.');

  // Delete multiple groups.
  skinr_context_group_delete_multiple(array(
    $group->gid,
    $second_group->gid,
  ));
  $groups = skinr_context_group_load_multiple(FALSE);
  $this
    ->assertTrue(count($groups) == 0, 'Successfully deleted multiple skin settings groups.');
}