You are here

public function SpacesVariableControllerTestCase::test in Spaces 7

Same name and namespace in other branches
  1. 6.3 tests/spaces.test \SpacesVariableControllerTestCase::test()
  2. 7.3 tests/spaces.test \SpacesVariableControllerTestCase::test()

Test override inheritance of variable controller.

File

tests/spaces.test, line 34

Class

SpacesVariableControllerTestCase
Unit tests for variable controller

Code

public function test() {
  ctools_include('export');
  $preset = ctools_export_new_object('spaces_presets');
  $preset->name = 'testpreset';
  $preset->title = 'Test preset';
  $preset->space_type = 'user';
  $preset->value = array(
    'variable' => array(
      'foo' => 'bar',
    ),
  );
  spaces_preset_save($preset);
  variable_set('foo', 'foo');

  // Force a cache clear.
  spaces_types(TRUE);
  drupal_static_reset('ctools_plugins');
  ctools_get_plugins_reset();
  $space = spaces_load('user', 0);
  if ($space == FALSE) {
    $this
      ->fail('Could not load user space');

    // return and prevent the test from going haywire.
    return;
  }
  else {
    $this
      ->pass('Loaded user space');
  }

  // Activate space.
  $space
    ->activate();

  // Original
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo') === 'foo', t('Inheritance (Original)'));

  // Preset
  $space->controllers->variable
    ->set('spaces_preset_user', 'testpreset');
  $space
    ->init_overrides();
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo') === 'bar', t('Inheritance (Original > Preset)'));

  // Original > Preset > Space
  $space->controllers->variable
    ->set('foo', 'baz');
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo') === 'baz', t('Inheritance (Original > Preset > Space)'));

  // Original > Space
  $space->controllers->variable
    ->del('spaces_preset_user');
  $space
    ->init_overrides();
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo') === 'baz', t('Inheritance (Original > Space)'));

  // Put the preset back
  $space->controllers->variable
    ->set('spaces_preset_user', 'testpreset');
  $space
    ->init_overrides();

  // Specific environment gets
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo', 'original') === 'foo', t('Environment (Original)'));
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo', 'preset') === 'bar', t('Environment (Preset)'));
  $this
    ->assertTrue($space->controllers->variable
    ->get('foo', 'space') === 'baz', t('Environment (Space)'));

  // Clean up.
  variable_del('foo');
  spaces_delete('user', 0);
  spaces_preset_delete('testpreset');
}