User login

Testing session at Drupal Camp NYC 5

Why click on forums every time?

Why create a user every time to make sure it isn't

Me: And I thought it was just so

  • Functional tests - what users do
  • Unit tests - (not doing so much)
  • Security tests - insert javascript, cross-site scripting, SQL injection, penetration testing on every form field: if it sees the form it

Assertions are the base of any testing framework.

http://drupal.org/project/issues/3060&text=testingparty08

Charlie's going to write a test right in front of us.

Name your test after the module-- if the module is module_name.module,

module_name.test

Unlike most parts of Drupal, SimpleTest is Object Oriented PHP.

All tests extend either DrupalWebTestCase or one of DrupalWebTestCase's descendants.

<?php
// $Id$

class ModuleNameTestCase extends DrupalWebTestCase {

  protected $web_user;

  /**
   * Implementation of getInfo().
   */
  function getInfo() {
    return array(
      'name' => t('DHTML menu functionality'),
      'description' => t('Tests the DHTML menu module and makes sure it works properly');
      'group' => t('DHTML menu'),
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp() {
// ABSOLUTELY CRITICAL!!!!   IF you forget this line it will DESTROY your Drupal site.   MUST WRITE: parent::setUp();  You can enable modules by listing them:
    parent::setUp('module_name', 'other_nonenabled_by_core_modules');

    $web_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration', 'access content', 'administer nodes');
    $this->drupalLogin($web_user);
  }

  /**
   * An actual test function!
   */
  function testModuleName()  {
    $this->drupalGet('<front>');   // this is a member function that just uses the usual drupal get function
    if ($this->parse()) {
      $found = FALSE;
      foreach ($this->elements->x  // something more here using simple XML
        if ($div->attributes['id']
          $found = TRUE;
          break;
        }
      }
    }
  // our first assertion!  The message will print and be green and checked off if the variable passed in first is true.
  $this->assertTrue($found, t('The navigation was found on the page.'));
  $block_title = $div->h2;
//   ->assertIdentical($this->
  }
}
?>

The example was DHTML Menu, which is hard to test. It's adding it's own CSS and JavaScript, though, so you can at least test to see that that is added.

Apparently curl is pronounced "C - URL"

Tests should always be written in the positive, and if it fails it means it didn't happen.

CWGordon's tests failed the first time and he switched them to AssertRaw also!!!

He says SimpleXML is hard to debug (that's thet dependency for the more complicated string assertion tests, then).

Assert functions you can see at http://drupal.org/simpletest

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.