--- system_service/system_service.inc	7 Mar 2009 22:35:04 -0000	1.1.2.5
+++ system_service/system_service.inc	1 Nov 2009 19:15:31 -0000
@@ -1,5 +1,6 @@
 <?php
 // $Id: system_service.inc,v 1.1.2.5 2009/03/07 22:35:04 marcingy Exp $
+
 /**
  * @author Services Dev Team
  * @file
@@ -7,7 +8,7 @@
  */
 
 /**
- * Returns a specified node.
+ * Returns a service connection: current session and user information.
  */
 function system_service_connect() {
   global $user;
@@ -19,6 +20,9 @@
   return $return;
 }
 
+/*
+ * Implements hook_mail().
+ */
 function system_service_mail($mailkey, &$message, $params) {
   $language = $message['language'];
   $variables = user_mail_tokens($params['account'], $language);
@@ -61,16 +65,14 @@
 
 /**
  * Check if a module is enabled. If so, return its version.
+ * @TODO: Returning module version requires mayor rewrite of this function.
  */
 function system_service_module_exists($module) {
-  if (module_exists($module)) {
-    $modules = module_rebuild_cache();
-    if (array_key_exists($module, $modules)) {
-      return (string)$modules[$module]->info['version'];
-    }
-  }
+  $list = module_list();
 
-  return "";
+  // Returning module version if module is enabled.
+  $version = ($list[$module]) ? t('Unkwown version') : '';
+  return $version;
 }
 
 /**
--- system_service/system_service.info	10 Jan 2008 00:35:53 -0000	1.5
+++ system_service/system_service.info	1 Nov 2009 11:27:59 -0000
@@ -3,4 +3,7 @@
 description = Provides system services.
 package = Services - services
 dependencies[] = services
-core = 6.x
\ No newline at end of file
+files[] = system_service.inc
+files[] = system_service.module
+files[] = system_service.test
+core = 7.x
\ No newline at end of file
--- system_service/system_service.module	15 Oct 2009 03:54:05 -0000	1.3.2.20.2.1
+++ system_service/system_service.module	2 Nov 2009 00:18:44 -0000
@@ -1,5 +1,6 @@
 <?php
 // $Id: system_service.module,v 1.3.2.20.2.1 2009/10/15 03:54:05 marcingy Exp $
+
 /**
  * @author Services Dev Team
  * @file
@@ -7,7 +8,7 @@
  */
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function system_service_help($path, $arg) {
   switch ($path) {
@@ -19,14 +20,35 @@
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function system_service_perm() {
-  return array('send mail from remote', 'get variable from remote', 'set variable from remote', 'check module exists from remote', 'clear cache from remote');
+function system_service_permission() {
+  return array(
+    'send mail from remote' =>  array(
+      'title' => t('Send mail from remote'),
+      'description' => t('Send an email using services.'),
+    ),
+    'get variable from remote' =>  array(
+      'title' => t('Get variable from remote'),
+      'description' => t('Get the value of a system variable using services.'),
+    ),
+    'set variable from remote' =>  array(
+      'title' => t('Set variable from remote'),
+      'description' => t('Set the value of a system variable using services.'),
+    ),
+    'check module exists from remote' =>  array(
+      'title' => t('Check module exists from remote'),
+      'description' => t('Check if a module is enabled in the server using services.'),
+    ),
+    'clear cache from remote' =>  array(
+      'title' => t('Clear cache from remote'),
+      'description' => t('Clearh all the cache systems in the server using services.'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_service().
+ * Implements hook_service().
  */
 function system_service_service() {
   return array(
--- system_service/system_service.test
+++ system_service/system_service.test
@@ -0,0 +1,79 @@
+<?php
+// $Id$
+
+/**
+ * @author Services Dev Team
+ * @file
+ *  Test system services implementation.
+ */
+
+class SystemServicesAPITestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'System services',
+      'description' => 'Test system services implementation.',
+      'group' => 'Services - Services',
+    );
+  }
+
+  /*
+   * Enable the module and configure the basics for the test.
+   */
+  function setUp() {
+    parent::setUp('services', 'system_service');
+    module_load_include('inc', 'system_service');
+  }
+
+  /*
+   * Test user_service_connect implementation.
+   */
+  function testSystemServiceConnect() {
+    global $user;
+
+    $result = system_service_connect();
+    $this->assertEqual($result->sessid, session_id(), t('system_service_connect session successfully validated.'));
+    $this->assertEqual($result->user->uid, $user->uid, t('system_service_connect user successfully validated.'));
+  }
+
+  /*
+   * Test user_service_getvariable implementation.
+   */
+  function testSystemServiceGetVariable() {
+    $name  = $this->randomName();
+    $value = $this->randomName();
+
+    variable_set($name, $value);
+    $this->assertEqual($value, system_service_getvariable($name, NULL), t('system_service_getvariable successfully verified.'));
+
+    variable_del($name);
+  }
+
+  /*
+   * Test user_service_setvariable implementation.
+   */
+  function testSystemServiceSetVariable() {
+    $name  = $this->randomName();
+    $value = $this->randomName();
+
+    system_service_setvariable($name, $value);
+    $this->assertEqual($value, variable_get($name, NULL), t('system_service_setvariable successfully verified.'));
+
+    variable_del($name);
+  }
+
+  /*
+   * Test user_service_module_exists implementation.
+   */
+  function testSystemServiceModuleExists() {
+
+    // Try a valid module
+    $version = system_service_module_exists('system_service');
+    $this->assertTrue(!empty($version), t('system_service_module_exists valid module successfully verified.'));
+
+    // Try an invalid module
+    $version = system_service_module_exists($this->randomName());
+    $this->assertTrue(empty($version), t('system_service_module_exists invalid module successfully verified.'));
+  }
+
+}


