diff --git a/dart.adtest.inc b/dart.adtest.inc
index f1f29a8..7af0bb2 100644
--- a/dart.adtest.inc
+++ b/dart.adtest.inc
@@ -18,8 +18,6 @@ function dart_test_page() {
 
   foreach ($tags as $tag) {
     $tag->mode = 'test';
-    $tag->site = isset($_GET['site']) ? $_GET['site'] : $tag->site;
-    $tag->zone = isset($_GET['zone']) ? $_GET['zone'] : $tag->zone;
 
     $content['ads'][$tag->machinename] = array(
       '#type'   => 'markup',
@@ -55,12 +53,16 @@ function dart_test_page_form($form, &$form_state, $edit = array()) {
   $form['site'] = array(
     '#type' => 'textfield',
     '#title' => t('Site'),
-    '#default_value' => isset($_GET['site']) ? $_GET['site'] : '',
+    '#default_value' => isset($_GET['site']) ? check_plain($_GET['site']) : '',
   );
   $form['zone'] = array(
     '#type' => 'textfield',
     '#title' => t('Zone'),
-    '#default_value' => isset($_GET['zone']) ? $_GET['zone'] : '',
+    '#default_value' => isset($_GET['zone']) ? check_plain($_GET['zone']) : '',
+  );
+  $form['adtest'] = array(
+    '#type' => 'hidden',
+    '#default_value' => 'true',
   );
   $form['submit'] = array(
     '#type' => 'submit',
@@ -76,8 +78,8 @@ function dart_test_page_form($form, &$form_state, $edit = array()) {
 function dart_tag_adtest(&$tag) {
   // If there is an "adtest" query string, show test ad tags instead.
   if (isset($_GET['adtest']) && $_GET['adtest'] == 'true') {
-    $tag->prefix = $_GET['prefix'] ? $_GET['prefix'] : variable_get('dart_test_prefix', '');
-    $tag->site = $_GET['site'] ? $_GET['site'] : variable_get('dart_test_site', '');
-    $tag->zone = $_GET['zone'] ? $_GET['zone'] : variable_get('dart_test_zone', '');
+    $tag->prefix = isset($_GET['prefix']) ? check_plain($_GET['prefix']) : variable_get('dart_test_prefix', '');
+    $tag->site = isset($_GET['site']) ? check_plain($_GET['site']) : variable_get('dart_test_site', '');
+    $tag->zone = isset($_GET['zone']) ? check_plain($_GET['zone']) : variable_get('dart_test_zone', '');
   }
 }
diff --git a/dart.module b/dart.module
index ae40477..258852c 100644
--- a/dart.module
+++ b/dart.module
@@ -232,6 +232,14 @@ function dart_entity_view($entity, $type, $view_mode, $langcode) {
 }
 
 /**
+ * Implements hook_dart_tag_alter();
+ */
+function dart_dart_tag_alter(&$tag) {
+  module_load_include('inc', 'dart', 'dart.adtest');
+  dart_tag_adtest($tag);
+}
+
+/**
  * Wrapper function for outputting a themed dart tag.
  */
 function dart_tag($machinename) {
@@ -294,8 +302,6 @@ function dart_tag_load($machinename = '') {
  * Modify just-loaded DART tags to prepare it for use.
  */
 function dart_tag_prepare(&$tags) {
-  module_load_include('inc', 'dart', 'dart.adtest');
-
   // Unserialize the settings array.
   foreach ($tags as &$tag) {
     if (is_string($tag->settings)) {
@@ -359,9 +365,6 @@ function dart_tag_prepare(&$tags) {
 
     // Build data for the noscript tag.
     $tag->noscript = dart_tag_prepare_noscript($tag);
-
-    // Check if tags should be displayed using test values for prefix.site/zone().
-    dart_tag_adtest($tag);
   }
 }
 
@@ -412,7 +415,6 @@ function dart_tag_prepare_noscript($tag) {
   );
 }
 
-
 /**
  * Change the current active/inactive status for the given tag.
  */
@@ -648,4 +650,5 @@ function template_preprocess_dart_tag(&$variables) {
   $variables['static_tag'] = l(theme('image', array('path' => $tag->noscript['src'])), $tag->noscript['href'], array('html' => TRUE));
   $variables['noscript_tag'] = $variables['show_noscript_tag'] ? '<noscript>' . $variables['static_tag'] . '</noscript>' : '';
   $variables['tag'] = $tag;
+debug($variables);
 }
diff --git a/tests/dart.test b/tests/dart.test
index d33f9bf..adead56 100644
--- a/tests/dart.test
+++ b/tests/dart.test
@@ -32,11 +32,10 @@ class dartBaseTest extends DrupalWebTestCase {
       'dart_global_site' => $this->randomName(8),
       'dart_global_zone' => $this->randomName(8),
       'dart_global_slug' => $this->randomName(8),
-      'dart_load_last' => FALSE,
-      'dart_noscript' => FALSE,
-      'dart_include_taxonomy_terms' => 1,
-      'dart_enable_ad_categories' => 1,
-      'dart_enable_ad_categories_bundles[tags]' => 'tags',
+      'dart_load_last' => 0,
+      'dart_noscript' => 0,
+      'dart_include_taxonomy_terms' => TRUE,
+      'dart_enable_ad_categories' => 0,
       'dart_special_key_vals[tile]' => 'tile',
       'dart_special_key_vals[ord]' => 'ord',
       'dart_special_tile_init' => 0,
@@ -47,9 +46,9 @@ class dartBaseTest extends DrupalWebTestCase {
     );
 
     for ($i = 0; $i < count($key_vals); $i++) {
-      $basic_tag['dart_key_vals[' . $i . '][key]'] = $key_vals[$i]['key'];
-      $basic_tag['dart_key_vals[' . $i . '][val]'] = $key_vals[$i]['val'];
-      $basic_tag['dart_key_vals[' . $i . '][eval]'] = $key_vals[$i]['eval'];
+      $edit['key_vals[' . $i . '][key]'] = $key_vals[$i]['key'];
+      $edit['key_vals[' . $i . '][val]'] = $key_vals[$i]['val'];
+      $edit['key_vals[' . $i . '][eval]'] = $key_vals[$i]['eval'];
     }
 
     $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
@@ -59,7 +58,7 @@ class dartBaseTest extends DrupalWebTestCase {
 
   /**
    * Create a simple $edit array to be used on the DFP tag form to create a new
-   * DFP tag object.
+   * DART tag object.
    */
   function dartTagEditValues() {
     $machinename = drupal_strtolower($this->randomName(8));
@@ -70,9 +69,9 @@ class dartBaseTest extends DrupalWebTestCase {
       'name' => $this->randomName(8),
       'pos' => $this->randomName(8),
       'sz' => implode(',', $this->dartGenerateSize(2)),
-      'site' => $this->randomName(8),
-      'zone' => $this->randomName(8),
-      'slug' => $this->randomName(8),
+      'site' => '',
+      'zone' => '',
+      'slug' => '',
       'block' => 1,
       'scriptless' => FALSE,
       'method' => 'adj',
@@ -225,10 +224,60 @@ class dartKeyValTest extends dartBaseTest {
     );
   }
 
-  // Test gloabl key vals
-  // Test tag specific key vals
-  // Test "special" key vals
-  // Test tokens in key vals
+  // Test gloabl key vals.
+  function testGlobalKeyValPairs() {
+    $tag = $this->createTag();
+    $global_key_vals = variable_get('dart_key_vals', array());
+    foreach ($global_key_vals as $keyval) {
+      $this->assertRaw($keyval['key'], "Global key vals: the key <em>" . $keyval['key'] . "</em> was found");
+      $this->assertRaw($keyval['val'], "Global key vals: the val <em>" . $keyval['val'] . "</em> was found");
+    }
+  }
+
+  // Test "special" key vals.
+  function testSpecialKeyValuePairs() {
+    $this->assertRaw('var tile = ' . variable_get('dart_special_tile_init', 0) . ';', 'The tile value was correctly initiated.');
+    $this->assertRaw('var ord = 1000000000 + Math.floor(Math.random() * 900000000);', 'The ord value was correctly initiated.');
+
+    // Test "special" key vals are not included when they are turned off.
+    $edit = array(
+      'dart_special_key_vals[tile]' => FALSE,
+      'dart_special_key_vals[ord]' => FALSE,
+    );
+    $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
+    $this->assertNoRaw('var tile', 'The tile value was correctly ommitted.');
+    $this->assertNoRaw('var ord', 'The ord value was correctly ommitted.');
+  }
+
+  // Test tokens in key vals.
+  // We must use generic tokens here because the context gets confused when
+  // simpletest is running. For example, it isnt sure which user should be used
+  // for token replacement.
+  function testTokenKeyVals() {
+    $tag = $this->createTag();
+
+    $count = 2;
+    $tokens = array(
+      '[current-date:custom:Ymd]',
+      '[site:name]',
+    );
+    $key_vals = $this->dartGenerateKeyVals($count);
+
+    for ($i = 0; $i < count($key_vals); $i++) {
+      $edit['key_vals[' . $i . '][key]'] = $key_vals[$i]['key'];
+      $edit['key_vals[' . $i . '][val]'] = $tokens[$i];
+      $edit['key_vals[' . $i . '][eval]'] = 0;
+    }
+    $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
+
+    foreach ($tokens as $token) {
+      $value = token_replace($token, _dart_get_token_context(), array(
+        'clear' => 1,
+        'sanitize' => 1,
+      ));
+      $this->assertRaw('"val":"' . $value . '"', 'The key value pair containing the ' . $token . ' (' . $value . ') token were properly rendered.');
+    }
+  }
 }
 
 class dartNoScriptTest extends dartBaseTest {
@@ -244,6 +293,15 @@ class dartNoScriptTest extends dartBaseTest {
   }
 
   // Test noscript tags display properly
+  function testNoScript() {
+    $edit = array(
+      'dart_load_last' => FALSE,
+      'dart_noscript' => TRUE,
+    );
+    $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
+    $tag = $this->createTag();
+    $this->assertRaw('<noscript><a href="http://ad.doubleclick.net/jump/', 'noscript tags are displayed properly.');
+  }
 }
 
 class dartAdCategoriesTest extends dartBaseTest {
@@ -258,10 +316,168 @@ class dartAdCategoriesTest extends dartBaseTest {
     );
   }
 
-  // Test that terms are added to tags properly
-  // Test that Ad Categories are used instead of terms when appropriate
+  function enableAdCategories() {
+    $edit = array(
+      'dart_enable_ad_categories' => TRUE,
+      'dart_enable_ad_categories_bundles[tags]' => 'tags',
+    );
+    $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
+    $this->drupalGet('admin/structure/taxonomy/tags/add');
+  }
+
+  function disableAdCategories($vocab = '') {
+    if (empty($vocab)) {
+      $edit = array(
+        'dart_enable_ad_categories' => 0,
+      );
+    }
+    else {
+      $edit = array(
+        'dart_enable_ad_categories_bundles[tags]' => 0,
+      );
+    }
+    $this->drupalPost('/admin/structure/dart_tags/settings', $edit, t('Save configuration'));
+    $this->drupalGet('admin/structure/taxonomy/tags/add');
+  }
+
+  function testEnableDisableAdCategories() {
+    // Check that enabling DART Ad Categories for the "tags" vocabulary works.
+    $this->enableAdCategories();
+    $this->assertFieldByName('field_dart_ad_categories[und]');
+
+    // Check that disabling DART Ad Categories vocabulary works even when a
+    // bundle is selected.
+    $this->disableAdCategories();
+    $this->assertNoFieldByName('field_dart_ad_categories[und]');
+
+    // Check that disabling DART Ad Categories on a specific vocabulary works.
+    // For this test to be valid, we first need to reenable DART Ad Categories.
+    $this->enableAdCategories();
+    $this->disableAdCategories('tags');
+    $this->assertNoFieldByName('field_dart_ad_categories[und]');
+  }
+
+  // Test that DART Catetories are displayed properly.
+  function testDisplayAdCategories() {
+    $this->enableAdCategories();
+
+    // Create a new DFP Ad Category term.
+    $dart_category = $this->randomName(8); // tid == 1
+    $edit = array(
+      'name' => $dart_category,
+    );
+    $this->drupalPost('admin/structure/taxonomy/dart_ad_categories/add', $edit, t('Save'));
+
+    // Create a new "Article" node with two tags.
+    $control_tag = $this->randomName(8); // tid == 2
+    $test_tag = $this->randomName(8); // tid == 3
+    $edit = array(
+      'title' => $this->randomName(8),
+      'field_tags[und]' => $control_tag . ', ' . $test_tag,
+    );
+    $this->drupalPost('node/add/article', $edit, t('Save'));
+
+    // Edit one the new tags and tag it with a DFP Ad Category.
+    $edit = array(
+      'field_dart_ad_categories[und]' => 1,
+    );
+    $this->drupalPost('taxonomy/term/3/edit', $edit, t('Save'));
+
+    // Create a DFP ad slot that targets the [dfp_tag:ad_categories] token.
+    $edit = $this->dartTagEditValues();
+
+    // Create a tag that uses the dart tag token as a key value.
+    $edit['key_vals[0][val]'] = '[dfp_tag:ad_categories]';
+    $tag = $this->createTag($edit);
+
+    // Check that when we are on the node page, that the DFP Ad Category is used
+    // and that the control tag is also displayed.
+    $this->drupalGet('node/1');
+    $this->assertRaw($dart_category, 'DART Ad Categories work correctly.');
+
+    // Check that when we are on the term page for one of DFP Ad Categories that
+    // it is correctly included.
+    $this->drupalGet('taxonomy/term/1');
+    $this->assertRaw($dart_category, 'DART Ad Categories appear on its own term page correctly.');
+
+    // Check that when we are on a term page for a term with a coresponding
+    // DFP Ad Categories the DFP Ad Category is included.
+    $this->drupalGet('taxonomy/term/3');
+    $this->assertRaw($dart_category, 'DART Ad Categories appear on term pages for terms that have a DART Ad Category correctly.');
+
+  }
+}
+
+class dartOverridesTest extends dartBaseTest {
+  /**
+   * Implements getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('DART Overrides Tests'),
+      'description' => t('Tests that DART Tags overrides work properly.'),
+      'group' => t('DART'),
+    );
+  }
+
+  // Test that tags with override values use them.
+  function testOverrides() {
+    $edit = array(
+      'site' => $this->randomName(8),
+      'zone' => $this->randomName(8),
+      'slug' => $this->randomName(8),
+    );
+    $tag = $this->createTag($edit);
+    $this->assertRaw($edit['site'], 'The site override work properly.');
+    $this->assertRaw($edit['zone'], 'The zone override work properly.');
+    $this->assertText($edit['slug'], 'The slug override works properly.');
+  }
+}
+
+class dartAdTestsTest extends dartBaseTest {
+  /**
+   * Implements getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('DART Ad Test Tests'),
+      'description' => t('Tests that DART test page works properly.'),
+      'group' => t('DART'),
+    );
+  }
+
+  // Test that the test page works
+  function testTestPage() {
+    $tag = $this->createTag();
+    $this->drupalGet('admin/structure/dart_tags/test_page');
+    $this->assertTag($tag);
+
+    $edit = array(
+      'adtest' => 'true',
+      'site' => $this->randomName(8),
+      'zone' => $this->randomName(8),
+    );
+    $this->drupalGet('admin/structure/dart_tags/test_page', array('query' => $edit));
+    $this->assertRaw('"site":"' . $edit['site'] . '","zone":"' . $edit['zone'] . '"');
+  }
+
+  // Test that the ?adtest query string works
+  function testAdTestQueryString() {
+    $tag = $this->createTag();
+    $overrides = array(
+      'adtest' => 'true',
+      'site' => $this->randomName(8),
+      'zone' => $this->randomName(8),
+    );
+
+    $this->drupalGet('<front>', array('query' => $overrides));
+    $this->assertRaw('"site":"' . $overrides['site'] . '","zone":"' . $overrides['zone'] . '"');
+  }
 }
 
 
 
 
+
+
+
