I am building SimpleTests for my modules:

It seems like the standard procedure for enabling modules it doesn't work for me:

function setUp() {

I constantly get a stupid error code: Duplicate entry 'bartik-system-main' for key 'tmd': INSERT INTO {block}

As I am using profiles I used the $profile variable:

protected $profile = 'myprofilename';

I have forced this by using a Drupal function:

module_enable(array('mymodule'), $enable_dependencies = TRUE);

In this final case the error that persists is

Undefined property: stdClass::$name

Here below is a sample of my code:

class mymoduleWebTestCase extends DrupalWebTestCase {

  protected $privileged_user;

  protected $profile = 'myprofile';

  public static function getInfo() {
    return array(
        'name' => 'mymodule',
        'description' => 'mydescription.',
        'group' => 'mygroup',

  function setUp() {
    $this->privileged_user = new stdClass();
   // Login a user that has access to the content sync server admin settings
    $this->privileged_user = $this->drupalCreate();

  function testMyModule() {

    //Create content of community type
    $settings = array(
      'type' => 'mycontenttype',
      'title' => 'Sample Content',
      'link' => 'http://www.google.com',
      'body' => array(LANGUAGE_NONE => array(array('body'))),
      'moderate' => 1,
      'status' => 1,
      'revisions' => NULL,
      'taxonomy' => NULL,
    $node = $this->drupalCreateNode($settings);
    $this->assertRaw('Sample Content', t('Content created.'));

    $node = $this->drupalCreateNode($settings);

   //This if we have a valid link inside


You should make triple-sure that your module declares all of its dependencies properly. Even if it does, Simpletest struggles with dependencies and you may have luck if you enable them explicitly in setUp() before your module.

Also, not sure if it's the contributing your error, but instead of $this->privileged_user = new stdClass(); I would use DrupalWebTestCase::drupalCreateUser like so: $this->privileged_user = $this->drupalCreateUser(). I might also declare it after setup() but I'm not sure that's significant.

|improve this answer|||||

The Duplicate entry 'bartik-system-main' for key 'tmd' seems to be the same as an error caused by using fe_block module, reported here Simpletest: database exception during setUp

The solution proposed for that question was to enable modules after the main setup was complete. It worked for me when I had the same exception. Using an installation profile makes it more difficult, but assuming it is the same case, perhaps there is a way to make a simplified test profile with the features module disabled, and re-enable it manually?

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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