Index: xero.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xero/xero.admin.inc,v
retrieving revision 1.1
diff -u -p -r1.1 xero.admin.inc
--- xero.admin.inc	28 Sep 2010 00:32:17 -0000	1.1
+++ xero.admin.inc	2 Nov 2010 19:23:51 -0000
@@ -30,6 +30,7 @@ function xero_admin_settings() {
     '#title' => t('Xero Certificate Path'),
     '#description' => t('Provide the full path and file name to your Xero certificate.'),
     '#default_value' => variable_get('xero_cert_path', ''),
+    '#element_validate' => array('xero_admin_settings_validate_exists'),
   );
 
   $form['xero_key_path'] = array(
@@ -37,12 +38,22 @@ function xero_admin_settings() {
     '#title' => t('Xero Key Path'),
     '#description' => t('Provide the full path and file name to your Xero certificate private key.'),
     '#default_value' => variable_get('xero_key_path', ''),
+    '#element_validate' => array('xero_admin_settings_validate_exists'),
   );
 
   return system_settings_form($form);
 }
 
 /**
+ * Validation callback for xero_admin_settings().  Verifies that the field's file exists and is readable.
+ */
+function xero_admin_settings_validate_exists($element, &$form_state) {
+  if (!@file_exists($element['#value'])) {
+    form_error($element, t('The specified file either does not exist, or is not accessible to the web server.'));
+  }
+}
+
+/**
  * Xero Autocomplete Contacts page callback
  * @param $string the string to search
  */
Index: xero.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xero/xero.module,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 xero.module
--- xero.module	21 Oct 2010 19:17:29 -0000	1.1.2.2
+++ xero.module	2 Nov 2010 19:23:53 -0000
@@ -154,7 +154,18 @@ function xero_php_load() {
   $cert = variable_get('xero_cert_path', '');
   $cert_key = variable_get('xero_key_path', '');
 
-  return new Xero($key, $secret, $cert, $cert_key, 'json');
+  $key = ($key <> '') ? $key : FALSE;
+  $secret = ($secret <> '') ? $secret : FALSE;
+  $cert = (file_exists($cert)) ? $cert : FALSE;
+  $cert_key = (file_exists($cert_key)) ? $cert_key : FALSE;
+
+  $xero = new Xero($key, $secret, $cert, $cert_key, 'json');
+
+  if ($xero->verify()) {
+    return $xero;
+  }
+
+  return NULL;
 }
 
 /**
Index: tests/xero-connection.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xero/tests/xero-connection.test,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 xero-connection.test
--- tests/xero-connection.test	2 Nov 2010 16:41:13 -0000	1.1.2.1
+++ tests/xero-connection.test	2 Nov 2010 19:23:53 -0000
@@ -34,34 +34,33 @@ class XeroConnectionTest extends DrupalU
     );
   }
 
-  public function testXeroRequirements() {
-   //We need to load the install file
-   require_once './includes/install.inc';
-   module_load_include('install', 'xero', 'xero');
+  public function setUp() {
+    parent::setup('xero');
 
-   $key = variable_get('xero_consumer_key', '');
-   $secret = variable_get('xero_consumer_secret', '');
-   $requirements = module_invoke('xero', 'requirements', 'runtime');
+    $key = variable_get('xero_consumer_key', '');
+    $secret = variable_get('xero_consumer_secret', '');
+    $cert = variable_get('xero_cert_path', '');
+    $priv = variable_get('xero_key_path', '');
+    $xerolib = drupal_get_path('module', 'xero') . '/include/xero.php';
+
+    $this->assertNotEqual($key, '', t('OAuth consumer key is not empty.'));
+    $this->assertNotEqual($secret, '', t('OAuth consumer secret is not empty.'));
+    $this->assert(file_exists($cert), t('OAuth public cert file exists.'));
+    $this->assert(file_exists($priv), t('OAuth private key file exists.'));
+    $this->assert(file_exists($xerolib), t('PHP-Xero Library installed correctly.'));
 
-   // title is already passed through t()
-   foreach ($requirements as $key => $requirement) {
-     $this->assertNotEqual($requirement['severity'], REQUIREMENT_ERROR, t('Requirement passed: !title', array('!title' => $requirement['title'])));
-   }
-
-   $this->assertNotEqual($key, '', t('Xero Consumer Key is not empty.'));
-   $this->assertNotEqual($secret, '', t('Xero Consumer Secret is not empty.'));
+    $this->xero = xero_php_load();
+    $this->assertNotNull($this->xero, t('PHP-Xero object initialized successfully.'));
   }
 
-// @todo This test is broken
-/*
   public function testXeroConnection() {
-    $xero = xero_php_load();
-
-    $this->assertNotNull($xero, t('Sucessfully initialized the PHP-Xero library.'));
-
-    $result = $xero->Accounts;
-
-    $this->assertNotNull($result['Accounts']['Account'][0]['Name'], t('Successfully queried xero for accounts. Found an account named @name', array('@name' => $result['Accounts']['Account'][0]['Name'])));
+    if (is_object($this->xero)) {
+      $result = $this->xero->Accounts;
+      $this->assertNotNull($result['Accounts']['Account'][0]['Name'], t('Found a valid account, @name.', array('@name' => $result['Accounts']['Account'][0]['Name'])));
+    }
+    else {
+      $this->assert(FALSE, t('Could not connect to xero.'));
+    }
   }
-*/
+
 }
