features_extra_test_case.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Base class for Features Extra tests.
  5. */
  6. class FeaturesExtraTestCase extends DrupalWebTestCase {
  7. // The installation profile that will be used to run the tests.
  8. protected $profile = 'testing';
  9. public function setUp() {
  10. // Enable the test feature in addition to given modules.
  11. $modules = func_get_args();
  12. $modules = !empty($modules[0]) ? $modules[0] : array();
  13. $modules[] = 'features_extra_test';
  14. parent::setUp($modules);
  15. $admin_user = $this->drupalCreateUser(array('administer features'));
  16. $this->drupalLogin($admin_user);
  17. }
  18. /**
  19. * Test if components can be reverted and that overrides are detected.
  20. */
  21. protected function revertComponents($components = array()) {
  22. module_load_include('inc', 'features', 'features.export');
  23. foreach ($components as $component) {
  24. // Ensure that the component is in its default state initially.
  25. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  26. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_DEFAULT, t('@component state: Default.', array('@component' => $component)));
  27. // Override component and test that Features detects the override.
  28. $callback = "override_{$component}";
  29. $this->$callback();
  30. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  31. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_OVERRIDDEN, t('@component state: Overridden.', array('@component' => $component)));
  32. }
  33. // Revert component and ensure that component has reverted.
  34. features_revert(array('features_extra_test' => $components));
  35. foreach ($components as $component) {
  36. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  37. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_DEFAULT, t('@component reverted successfully.', array('@component' => $component)));
  38. }
  39. }
  40. }