Hey..
I´m trying to write my first simple tests but it fails just at the beginning. I wrote a module which creates a link in the navigation:

function mymodule_menu() {
  $items['mymodule'] = array(
  'title' => 'MyLink',
  'page callback' => 'mymodule_hello',
  'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

The callback function "mymodule_hello" only displays the word "hello".

Now i wanted to check this link and its output with simpletest.
I wrote the following piece of code:

class MyModuleTest extends DrupalWebTestCase {

  function getInfo() {
    return array(
      'name'  => t('MyModule'),
      'desc'  => t('A simple test.'),
      'group' => t('My tests'),
    );
  }
 
  function setUp() {
    parent::setUp();
    $user = $this->drupalCreateUser(array('administer site configuration'));
    $this->drupalLogin($user);
  }
 
  function testModulLink(){
    $this->drupalGet('');
    $this->clickLink('MyLink');
  }

}

If i now run the test i get the following messages:

12 passes, 1 fail, and 0 exceptions
...
Clicked link "MyLink" () from http://localhost/drupal/	Browser	mytest.test	26	MyModuleTest->testModulLink()

If i use the link "Log out" the test works fine. Only my own links don´t work.

Comments

dave reid’s picture

You are missing the access argument/callback for your menu item. Try using:

function mymodule_menu() {
  $items['mymodule'] = array(
  'title' => 'MyLink',
  'page callback' => 'mymodule_hello',
  'access callback' => TRUE,
  'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
boombatower’s picture

Status: Active » Postponed (maintainer needs more info)

You need to enable your test module in the setup call:

  function setUp() {
    parent::setUp('mymodule');
    $user = $this->drupalCreateUser(array('administer site configuration'));
    $this->drupalLogin($user);
  }

and the getInfo() method should be public static function getInfo()

boombatower’s picture

Status: Postponed (maintainer needs more info) » Fixed

Please rep-open if still having issues.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.