I have created a feature module with a basic content type called Message board and a views that displays the content of this message board. the views has a block on top that holds the links to node/add/message
I then created a TestCase that tests node create.

When I run this testcase, the following error occurs:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /localhost/batch?id=3&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'bartik-system-main' for key 'tmd': INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7), (:db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15), (:db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23), (:db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27, :db_insert_placeholder_28, :db_insert_placeholder_29, :db_insert_placeholder_30, :db_insert_placeholder_31), (:db_insert_placeholder_32, :db_insert_placeholder_33, :db_insert_placeholder_34, :db_insert_placeholder_35, :db_insert_placeholder_36, :db_insert_placeholder_37, :db_insert_placeholder_38, :db_insert_placeholder_39); Array ( [:db_insert_placeholder_0] => system [:db_insert_placeholder_1] => main [:db_insert_placeholder_2] => bartik [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => content [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => -1 [:db_insert_placeholder_8] => user [:db_insert_placeholder_9] => login [:db_insert_placeholder_10] => bartik [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => sidebar_first [:db_insert_placeholder_14] => [:db_insert_placeholder_15] => -1 [:db_insert_placeholder_16] => system [:db_insert_placeholder_17] => navigation [:db_insert_placeholder_18] => bartik [:db_insert_placeholder_19] => 1 [:db_insert_placeholder_20] => 0 [:db_insert_placeholder_21] => sidebar_first [:db_insert_placeholder_22] => [:db_insert_placeholder_23] => -1 [:db_insert_placeholder_24] => system [:db_insert_placeholder_25] => management [:db_insert_placeholder_26] => bartik [:db_insert_placeholder_27] => 1 [:db_insert_placeholder_28] => 1 [:db_insert_placeholder_29] => sidebar_first [:db_insert_placeholder_30] => [:db_insert_placeholder_31] => -1 [:db_insert_placeholder_32] => system [:db_insert_placeholder_33] => help [:db_insert_placeholder_34] => bartik [:db_insert_placeholder_35] => 1 [:db_insert_placeholder_36] => 0 [:db_insert_placeholder_37] => help [:db_insert_placeholder_38] => [:db_insert_placeholder_39] => -1 ) in minimal_install() (line 73 of /www/localhost/profiles/minimal/minimal.install). Fatal error: Class 'Database' not found in /www/localhost/includes/database/database.inc on line 2567

Please note that I tested this without the fe_block.
In the module.info, I commented out the dependencies[] = fe_block. After that, the test run just fine.

Comments

primerg’s picture

Investigating further, I found that line 457 in fe_block.module is causing this issue:

      // Rehash if we did not yet.
      if (empty($themes_rehashed[$theme])) {
        _block_rehash($theme);  // <---- causing issue
        $themes_rehashed[$theme] = TRUE;
      }

this line specifically in block.module is the problem Line 459.
drupal_write_record('block', $block, $primary_keys);

I still don't understand why it is causing the Class 'Database' not found error. I'll try to report in the main drupal issue page.

My question though, why is the _block_rehash() needed?

pfrenssen’s picture

One of the blocks you are saving is probably present in the "minimal" install profile. Did you export any of these blocks in a feature? See minimal_install(). This function does not check if the blocks it tries to write to the database might already be present.

pfrenssen’s picture

Answering your second question: the _block_rehash() function creates the entries for the blocks in the database. Without it you wouldn't be able to revert any blocks, they would not be created.

primerg’s picture

OK. Looking into that, my block is a custom menu block. Here is my message_board.features.fe_block_settings.inc

function message_board_default_fe_block_settings() {
  $export = array();

  $export['version'] = '2.0';

  $export['menu-menu-message-board'] = array(
    'cache' => -1,
    'custom' => 0,
    'delta' => 'menu-message-board',
    'module' => 'menu',
    'node_types' => array(),
    'pages' => 'messages
messages/*',
    'roles' => array(),
    'themes' => array(
      'bartik' => array(
        'region' => '',
        'status' => 0,
        'theme' => 'bartik',
        'weight' => 0,
      ),
      'mytheme' => array(
        'region' => 'content',
        'status' => 1,
        'theme' => 'mytheme',
        'weight' => 0,
      ),
    ),
    'title' => '<none>',
    'visibility' => 1,
  );

  return $export;
}

Please also note that even without the mytheme, the error still occurs.

I could provide the whole feature module in a private message if this would help.

pfrenssen’s picture

It are the blocks that are saved in minimal_install() for the Bartik theme that are causing the problem. All dependencies are enabled before the installer runs, and at the moment your feature becomes enabled it creates the block entries in the database - not only the ones defined in your feature, but all of them. The installer expects the blocks table to be empty and blindly tries to insert some blocks, but this fails as they are already present. It will always throw this error when any of these blocks are present at install time. Creating blocks is FE Block's core functionality, so I'm afraid that FE Block is simply not compatible with the 'minimal' or 'standard' profiles during testing.

There are a couple of workarounds you could try:

  • Use the 'testing' profile instead of the minimal profile if possible. The 'testing' profile does not have this problem.
  • Create your own installation profile for testing. You could base it on the 'minimal' profile, but change the db_insert() to db_update().
  • Wait with enabling your feature until the installation has finished:
      /**
       * Sets up a Drupal site for running functional and integration tests.
       */
      protected function setUp() {
        // Do not enable features that contain FE Block components when installing.
        $modules = array('views', 'ctools');
        parent::setUp($modules);
    
        // Now that the installation has finished we can enable the features.
        module_enable(array('my_block_feature'));
      }
    
primerg’s picture

Status: Active » Closed (fixed)

the testing profile works! thanks!