fe_block.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Features Extra Block module.
  5. */
  6. /**
  7. * Tests the custom block functionality.
  8. */
  9. class FeaturesExtraBlockTestCase extends DrupalWebTestCase {
  10. // The installation profile that will be used to run the tests.
  11. protected $profile = 'testing';
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Install, revert and override',
  15. 'description' => 'Tests if a feature containing blocks and block settings can be installed, reverted and detected as being overridden.',
  16. 'group' => 'Features Extra',
  17. );
  18. }
  19. public function setUp() {
  20. parent::setUp(array(
  21. 'features_extra_test',
  22. ));
  23. $admin_user = $this->drupalCreateUser(array('administer features'));
  24. $this->drupalLogin($admin_user);
  25. }
  26. /**
  27. * Check that all modules that are required for the test suite are available.
  28. */
  29. public function testRequiredModules() {
  30. $required_modules = array(
  31. 'block',
  32. 'ctools',
  33. 'features',
  34. 'fe_block',
  35. 'features_extra_test',
  36. );
  37. foreach ($required_modules as $module) {
  38. $this->assertTrue(module_exists($module), format_string('The required module @module exists.', array('@module' => $module)));
  39. }
  40. }
  41. /**
  42. * Test if custom blocks can be reverted and that overrides are detected.
  43. */
  44. public function testBlockRevert() {
  45. module_load_include('inc', 'features', 'features.export');
  46. // Ensure that the exported custom block is properly available.
  47. $bid = fe_block_get_bid('features_extra_test_block');
  48. $block = block_load('block', $bid);
  49. $this->assertTrue(!empty($block), 'The reverted block is present.');
  50. $components = array(
  51. 'fe_block_boxes',
  52. 'fe_block_settings',
  53. );
  54. foreach ($components as $component) {
  55. // Ensure that the component is in its default state initially.
  56. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  57. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_DEFAULT, t('@component state: Default.', array('@component' => $component)));
  58. // Override component and test that Features detects the override.
  59. $callback = "override_{$component}";
  60. $this->$callback($block);
  61. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  62. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_OVERRIDDEN, t('@component state: Overridden.', array('@component' => $component)));
  63. }
  64. // Revert component and ensure that component has reverted.
  65. features_revert(array('features_extra_test' => $components));
  66. drupal_flush_all_caches();
  67. foreach ($components as $component) {
  68. $states = features_get_component_states(array('features_extra_test'), FALSE, TRUE);
  69. $this->assertTrue($states['features_extra_test'][$component] === FEATURES_DEFAULT, t('@component reverted successfully.', array('@component' => $component)));
  70. }
  71. }
  72. /**
  73. * Change the content of the test block so the component becomes overridden.
  74. */
  75. protected function override_fe_block_boxes($block) {
  76. db_update('block_custom')
  77. ->fields(array('body' => 'overridden'))
  78. ->condition('bid', $block->bid)
  79. ->execute();
  80. }
  81. /**
  82. * Change a setting of the test block so the component becomes overridden.
  83. */
  84. protected function override_fe_block_settings($block) {
  85. db_update('block')
  86. ->fields(array('region' => 'footer'))
  87. ->condition('bid', $block->bid)
  88. ->condition('theme', 'bartik')
  89. ->execute();
  90. }
  91. }