0

I'm writing lots and lots of test cases for different modules and have come across a rather strange error about which I'm hoping others may have more insight. In my setUp function override, the first thing I'm doing is parent::setUp('my_module'). Whenever I run a test case that part fails with a PDOException inserting (duplicate) entries into the {block} table. This is the entire stack trace:

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), (:db_insert_placeholder_40, :db_insert_placeholder_41, :db_insert_placeholder_42, :db_insert_placeholder_43, :db_insert_placeholder_44, :db_insert_placeholder_45, :db_insert_placeholder_46, :db_insert_placeholder_47), (:db_insert_placeholder_48, :db_insert_placeholder_49, :db_insert_placeholder_50, :db_insert_placeholder_51, :db_insert_placeholder_52, :db_insert_placeholder_53, :db_insert_placeholder_54, :db_insert_placeholder_55), (:db_insert_placeholder_56, :db_insert_placeholder_57, :db_insert_placeholder_58, :db_insert_placeholder_59, :db_insert_placeholder_60, :db_insert_placeholder_61, :db_insert_placeholder_62, :db_insert_placeholder_63), (:db_insert_placeholder_64, :db_insert_placeholder_65, :db_insert_placeholder_66, :db_insert_placeholder_67, :db_insert_placeholder_68, :db_insert_placeholder_69, :db_insert_placeholder_70, :db_insert_placeholder_71), (:db_insert_placeholder_72, :db_insert_placeholder_73, :db_insert_placeholder_74, :db_insert_placeholder_75, :db_insert_placeholder_76, :db_insert_placeholder_77, :db_insert_placeholder_78, :db_insert_placeholder_79), (:db_insert_placeholder_80, :db_insert_placeholder_81, :db_insert_placeholder_82, :db_insert_placeholder_83, :db_insert_placeholder_84, :db_insert_placeholder_85, :db_insert_placeholder_86, :db_insert_placeholder_87), (:db_insert_placeholder_88, :db_insert_placeholder_89, :db_insert_placeholder_90, :db_insert_placeholder_91, :db_insert_placeholder_92, :db_insert_placeholder_93, :db_insert_placeholder_94, :db_insert_placeholder_95); 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] => search
[:db_insert_placeholder_9] => form
[:db_insert_placeholder_10] => bartik
[:db_insert_placeholder_11] => 1
[:db_insert_placeholder_12] => -1
[:db_insert_placeholder_13] => sidebar_first
[:db_insert_placeholder_14] => 
[:db_insert_placeholder_15] => -1
[:db_insert_placeholder_16] => node
[:db_insert_placeholder_17] => recent
[:db_insert_placeholder_18] => seven
[:db_insert_placeholder_19] => 1
[:db_insert_placeholder_20] => 10
[:db_insert_placeholder_21] => dashboard_main
[:db_insert_placeholder_22] => 
[:db_insert_placeholder_23] => -1
[:db_insert_placeholder_24] => user
[:db_insert_placeholder_25] => login
[:db_insert_placeholder_26] => bartik
[:db_insert_placeholder_27] => 1
[:db_insert_placeholder_28] => 0
[:db_insert_placeholder_29] => sidebar_first
[:db_insert_placeholder_30] => 
[:db_insert_placeholder_31] => -1
[:db_insert_placeholder_32] => system
[:db_insert_placeholder_33] => navigation
[:db_insert_placeholder_34] => bartik
[:db_insert_placeholder_35] => 1
[:db_insert_placeholder_36] => 0
[:db_insert_placeholder_37] => sidebar_first
[:db_insert_placeholder_38] => 
[:db_insert_placeholder_39] => -1
[:db_insert_placeholder_40] => system
[:db_insert_placeholder_41] => powered-by
[:db_insert_placeholder_42] => bartik
[:db_insert_placeholder_43] => 1
[:db_insert_placeholder_44] => 10
[:db_insert_placeholder_45] => footer
[:db_insert_placeholder_46] => 
[:db_insert_placeholder_47] => -1
[:db_insert_placeholder_48] => system
[:db_insert_placeholder_49] => help
[:db_insert_placeholder_50] => bartik
[:db_insert_placeholder_51] => 1
[:db_insert_placeholder_52] => 0
[:db_insert_placeholder_53] => help
[:db_insert_placeholder_54] => 
[:db_insert_placeholder_55] => -1
[:db_insert_placeholder_56] => system
[:db_insert_placeholder_57] => main
[:db_insert_placeholder_58] => seven
[:db_insert_placeholder_59] => 1
[:db_insert_placeholder_60] => 0
[:db_insert_placeholder_61] => content
[:db_insert_placeholder_62] => 
[:db_insert_placeholder_63] => -1
[:db_insert_placeholder_64] => system
[:db_insert_placeholder_65] => help
[:db_insert_placeholder_66] => seven
[:db_insert_placeholder_67] => 1
[:db_insert_placeholder_68] => 0
[:db_insert_placeholder_69] => help
[:db_insert_placeholder_70] => 
[:db_insert_placeholder_71] => -1
[:db_insert_placeholder_72] => user
[:db_insert_placeholder_73] => login
[:db_insert_placeholder_74] => seven
[:db_insert_placeholder_75] => 1
[:db_insert_placeholder_76] => 10
[:db_insert_placeholder_77] => content
[:db_insert_placeholder_78] => 
[:db_insert_placeholder_79] => -1
[:db_insert_placeholder_80] => user
[:db_insert_placeholder_81] => new
[:db_insert_placeholder_82] => seven
[:db_insert_placeholder_83] => 1
[:db_insert_placeholder_84] => 0
[:db_insert_placeholder_85] => dashboard_sidebar
[:db_insert_placeholder_86] => 
[:db_insert_placeholder_87] => -1
[:db_insert_placeholder_88] => search
[:db_insert_placeholder_89] => form
[:db_insert_placeholder_90] => seven
[:db_insert_placeholder_91] => 1
[:db_insert_placeholder_92] => -10
[:db_insert_placeholder_93] => dashboard_sidebar
[:db_insert_placeholder_94] => 
[:db_insert_placeholder_95] => -1
)
in standard_install() (line 201 of /Library/WebServer/Documents/drupal7/profiles/standard/standard.install).

#0 /Library/WebServer/Documents/drupal7/includes/database/database.inc(2171): PDOStatement->execute(Array)
#1 /Library/WebServer/Documents/drupal7/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array)
#2 /Library/WebServer/Documents/drupal7/includes/database/mysql/query.inc(36): DatabaseConnection->query('INSERT INTO {bl...', Array, Array)
#3 /Library/WebServer/Documents/drupal7/profiles/standard/standard.install(201): InsertQuery_mysql->execute()
#4 [internal function]: standard_install()
#5 /Library/WebServer/Documents/drupal7/includes/module.inc(866): call_user_func_array('standard_instal...', Array)
#6 /Library/WebServer/Documents/drupal7/includes/module.inc(477): module_invoke('standard', 'install')
#7 /Library/WebServer/Documents/drupal7/modules/simpletest/drupal_web_test_case.php(1498): module_enable(Array, false)
#8 /Library/WebServer/Documents/drupal7/sites/all/modules/my_module/my_module.test(26): DrupalWebTestCase->setUp('my_module')
#9 /Library/WebServer/Documents/drupal7/modules/simpletest/drupal_web_test_case.php(501): MyModuleMenuBlockTestCase->setUp()
#10 /Library/WebServer/Documents/drupal7/modules/simpletest/simpletest.module(178): DrupalTestCase->run()
#11 [internal function]: _simpletest_batch_operation(Array, '118', Array)
#12 /Library/WebServer/Documents/drupal7/includes/batch.inc(284): call_user_func_array('_simpletest_bat...', Array)
#13 /Library/WebServer/Documents/drupal7/includes/batch.inc(161): _batch_process()
#14 /Library/WebServer/Documents/drupal7/includes/batch.inc(80): _batch_do()
#15 /Library/WebServer/Documents/drupal7/modules/system/system.admin.inc(2373): _batch_page()
#16 [internal function]: system_batch_page()
#17 /Library/WebServer/Documents/drupal7/includes/menu.inc(517): call_user_func_array('system_batch_pa...', Array)
#18 /Library/WebServer/Documents/drupal7/index.php(21): menu_execute_active_handler()
#19 {main}

The error only happens if my module is enabled, which is particularly strange because the error occurs in DrupalWebTestCase::setUp prior to any non-core modules being installed. Could something in my module be causing it to setUp more than once or loop back on itself somehow? My module implements the following hooks:

  • hook_install
  • hook_uninstall
  • hook_menu
  • hook_block_list_alter
  • hook_drupal_goto_alter
  • hook_theme
  • hook_theme_registry_alter

My module also uses features to install certain block settings with the fe_block module in features_extras and has the following dependencies:

  • fe_block
  • features
  • menu
  • some other custom modules

The other custom modules are all thoroughly tested now and this issue does not occur if only they are installed. They include an implementation of hook_watchdog, hook_element_info, various additional API for forms, API for communication with an external web service, and account object manipulation using the latter API (primarily with hook_user_presave).

Has anybody got an idea what is causing my error?

1 Answer 1

3

To really figure out what's going on I'd have to dig deep into the features and fe_block modules, which I started to do and decided I could spend the next week digging and still not find any answers. So I tried enabling the module with the fe_block feature after setup, like so:

class MyModuleTestCase extends DrupalWebTestCase {

  // ...

  function setUp() {
    parent::setUp();
    // Enable my_module.module after setup is finished to avoid problems
    // with fe_block being enabled during initial installation.
    $success = module_enable(array('my_module'), TRUE);
    $this->assertTrue($success, 'Enabled modules: my_module');
    $this->resetAll();

    // ...
  }

Doing it this way got rid of the error, although for some reason one of the tests is taking forever to execute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.