Hello,
code:

<?php
class MyModuleTestCase extends DrupalUnitTestCase {
  protected $vid;

  public static function getInfo() {
    // Note: getInfo() strings should not be translated.
    return array(
      'name' => 'foo',
      'description' => 'bar',
      'group' => 'baz',
    );
  }

  public function setUp() {
    // Basic setup
    parent::setUp('foo', 'taxonomy');
  }


  protected function addVocabulary() {
    $vocabulary = array(
      'name' => 'foo',
      'description' => '',
      'multiple' => 1,
      'required' => 0,
      'hierarchy' => 2,
      'relations' => 0,
      'tags' => 1,
    );
    taxonomy_save_vocabulary($vocabulary);
    $vocabs = taxonomy_get_vocabularies();
    $this->vid = $vocabulary->vid;
    $this->pass("<pre>" . print_r($vocabulary, 1) . "</pre>");
    $this->pass("<pre>" . print_r($vocabs, 1) . "</pre>");
  }

  function testSomething() {
    $this->addVocabulary();
    $this->assertEqual(1, $this->vid);
  }
}
?>

Problem is, vocabulary seems not to exists after taxonomy_save_vocabulary.
Neither the $vocabulary print_r shows any vid field, nor the $vocabs print_r shows any item.

Am i doing something wrong? I tested this very same code outside the testing sandbox, and it does actually work fine.

Comments

brazorf’s picture

Status: Active » Closed (works as designed)

Whoops.
I just found that DrupalUnitTestCase is not going to setup any database. I should be using DrupalWebTestCase instead.