Test fixes.
authorGunnar Wrobel <p@rdus.de>
Tue, 27 Apr 2010 09:46:01 +0000 (11:46 +0200)
committerGunnar Wrobel <wrobel@temple.(none)>
Tue, 27 Apr 2010 09:54:09 +0000 (11:54 +0200)
framework/Kolab_Storage/test/Horde/Kolab/Storage/AttachmentTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Autoload.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/DataTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/FolderTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/StorageTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/TriggerTest.php [new file with mode: 0644]

index 1adff99..db69c36 100644 (file)
@@ -32,7 +32,7 @@ require_once 'Autoload.php';
  * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link       http://pear.horde.org/index.php?package=Kolab_Storage
  */
-class Horde_Kolab_Storage_AttachmentTest extends Horde_Kolab_Storage_Scenario
+class Horde_Kolab_Storage_AttachmentTest extends PHPUnit_Framework_TestCase
 {
     /**
      * Test setup.
index a3652c4..2f1677b 100644 (file)
@@ -5,47 +5,24 @@
  * PHP version 5
  *
  * @category Kolab
- * @package  Kolab_Server
+ * @package  Kolab_Session
  * @author   Gunnar Wrobel <wrobel@pardus.de>
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ * @link     http://pear.horde.org/index.php?package=Kolab_Session
  */
 
-/**
- * The Autoloader allows us to omit "require/include" statements.
- */
-require_once 'Horde/Autoloader.php';
-
-if (!defined('HORE_KOLAB_SERVER_TESTS')) {
-    $test_dir = '@test_dir@/Kolab_Server';
-
-    if (substr($test_dir, 0, 1) == '@') {
-        /**
-         * Assume we are working in development mode and this package resides in
-         * 'framework'.
-         */
-        define('HORE_KOLAB_SERVER_TESTS', dirname(__FILE__) . '/../../../../../Kolab_Server/test');
-    } else {
-        define('HORE_KOLAB_SERVER_TESTS', $test_dir);
-    }
-
-    Horde_Autoloader::addClassPath(HORE_KOLAB_SERVER_TESTS);
-}
-
-if (!defined('HORE_KOLAB_STORAGE_TESTS')) {
-    $test_dir = '@test_dir@/Kolab_Storage';
-
-    if (substr($test_dir, 0, 1) == '@') {
-        /**
-         * Assume we are working in development mode and this package resides in
-         * 'framework'.
-         */
-        define('HORE_KOLAB_STORAGE_TESTS', dirname(__FILE__) . '/../../..');
-    } else {
-        define('HORE_KOLAB_STORAGE_TESTS', $test_dir);
-    }
-
-    Horde_Autoloader::addClassPath(HORE_KOLAB_STORAGE_TESTS);
+if (!spl_autoload_functions()) {
+    spl_autoload_register(
+        create_function(
+            '$class', 
+            '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);'
+            . '$err_mask = E_ALL ^ E_WARNING;'
+            . '$oldErrorReporting = error_reporting($err_mask);'
+            . 'include "$filename.php";'
+            . 'error_reporting($oldErrorReporting);'
+        )
+    );
 }
 
-require_once 'Horde/Group.php';
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
index abaeef3..3e83752 100644 (file)
@@ -32,6 +32,11 @@ require_once 'Autoload.php';
  */
 class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
 {
+    public function setUp()
+    {
+        $this->cache = new Horde_Cache_Mock();
+    }
+
     /**
      * Test cleaning the cache.
      *
@@ -39,7 +44,7 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
      */
     public function testReset()
     {
-        $cache = new Horde_Kolab_Storage_Cache();
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->reset();
         $this->assertEquals(-1, $cache->validity);
         $this->assertEquals(-1, $cache->nextid);
@@ -54,7 +59,7 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
      */
     public function testStore()
     {
-        $cache = new Horde_Kolab_Storage_Cache();
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->reset();
         $item = array(1);
         $cache->store(10, 1, $item);
@@ -71,7 +76,7 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
      */
     public function testIgnore()
     {
-        $cache = new Horde_Kolab_Storage_Cache();
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->reset();
         $cache->ignore(11);
         $this->assertEquals(false, $cache->uids[11]);
@@ -84,7 +89,7 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
      */
     public function testAttachments()
     {
-        $cache = new Horde_Kolab_Storage_Cache();
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->storeAttachment('a', 'attachment');
         $this->assertEquals('attachment', $cache->loadAttachment('a'));
         $cache->storeAttachment('b', 'b');
@@ -94,45 +99,13 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test configration.
-     *
-     * @return NULL
-     */
-    public function testConfigruation()
-    {
-        $cache = new Horde_Kolab_Storage_Cache();
-
-        $GLOBALS['conf']['kolab']['storage']['cache']['data']['driver'] = 'file';
-
-        $cache2 = new Horde_Kolab_Storage_Cache();
-
-        $GLOBALS['conf']['kolab']['storage']['cache']['data']['params'] = array('prefix' => 'kolab_cache',
-                                                                                'dir' => Horde::getTempDir());
-
-        $cache3 = new Horde_Kolab_Storage_Cache();
-    }
-    /**
-     * Test creating the cache singleton.
-     *
-     * @return NULL
-     */
-    public function testSingleton()
-    {
-        $cache  = Horde_Kolab_Storage_Cache::singleton();
-        $cache2 = new Horde_Kolab_Storage_Cache();
-        $this->assertTrue($cache !== $cache2);
-        $cache3 = Horde_Kolab_Storage_Cache::singleton();
-        $this->assertTrue($cache === $cache3);
-    }
-
-    /**
      * Test loading/saving the cache.
      *
      * @return NULL
      */
     public function testLoadSave()
     {
-        $cache = new Horde_Kolab_Storage_Cache();
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->load('test', 1);
         /**
          * Loading a second time should return immediately (see code
index d97edb2..4b79439 100644 (file)
@@ -30,24 +30,13 @@ require_once 'Autoload.php';
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
-class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
+class Horde_Kolab_Storage_DataTest extends PHPUnit_Framework_TestCase
 {
     /**
      * Test setup.
      */
     public function setUp()
     {
-        // No 'auth' in world, so this won't work yet. Skip it.
-        $this->markTestSkipped();
-
-        $world = $this->prepareBasicSetup();
-
-        $this->storage = $this->authenticate($world['auth'],
-                         'wrobel@example.org',
-                         'none');
-
-        $this->folder = $this->prepareNewFolder($this->storage, 'Contacts', 'contact', true);
-        $this->prepareNewFolder($this->storage, 'NewContacts', 'contact');
     }
 
     /**
@@ -55,10 +44,6 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
      */
     public function tearDown()
     {
-        Horde_Imap_Client_Mock::clean();
-        if ($this->storage) {
-            $this->storage->clean();
-        }
     }
 
     /**
@@ -68,7 +53,7 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
     {
         $data = new Horde_Kolab_Storage_Data('test');
 
-        $folder = new Horde_Kolab_Storage_Folder('INBOX/Test');
+        $folder = new Horde_Kolab_Storage_Folder_Base('INBOX/Test');
         $data->setFolder($folder);
         $this->assertEquals('user/wrobel/Test', $data->getCacheKey());
     }
@@ -78,6 +63,8 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
      */
     public function testDelete()
     {
+        $this->markTestIncomplete();
+
         $data = new Horde_Kolab_Storage_Data('contact');
         $data->setFolder($this->folder);
 
@@ -114,6 +101,8 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
      */
     public function testMove()
     {
+        $this->markTestIncomplete();
+
         $data = new Horde_Kolab_Storage_Data('contact');
         $folder = $this->storage->getFolder('INBOX/Contacts');
         $data->setFolder($folder);
@@ -166,21 +155,14 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
      */
     public function testSave()
     {
-        $data = new Horde_Kolab_Storage_Data('contact');
-        $data->setFolder($this->folder);
-        /**
-         * During testing we want to ensure that we do not access any
-         * old, cached data. The cache gets loaded when calling
-         * getObjectIds and is manually expired afterwards.
-         */
-        $result = $data->getObjectIds();
-        $data->expireCache();
-        $object = array(
-            'uid' => '1',
-            'given-name' => 'Gunnar',
-            'full-name' => 'Gunnar Wrobel',
-            'email' => 'p@rdus.de'
-        );
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+
+        $group = new Group_mock();
+        $driver = new Horde_Kolab_Storage_Driver_Mock($group);
+        $cache = new Horde_Cache_Mock();
+        $storage = new Horde_Kolab_Storage($driver, $cache);
+        $data = $storage->getFolderData('INBOX/Contacs');
 
         try {
             $result = $data->save($object, '1000');
@@ -231,6 +213,8 @@ class Horde_Kolab_Storage_DataTest extends Horde_Kolab_Storage_Scenario
      */
     public function testObjectDeleteAll()
     {
+        $this->markTestIncomplete();
+
         $data = new Horde_Kolab_Storage_Data('contact');
         $data->setFolder($this->folder);
         /**
index 32531fb..5c6b9fe 100644 (file)
@@ -30,7 +30,7 @@ require_once 'Autoload.php';
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
-class Horde_Kolab_Storage_FolderTest extends Horde_Kolab_Storage_Scenario
+class Horde_Kolab_Storage_FolderTest extends PHPUnit_Framework_TestCase
 {
     /**
      * Test setup.
index 2d79bbb..8feadf0 100644 (file)
@@ -32,7 +32,7 @@ require_once 'Autoload.php';
  * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link       http://pear.horde.org/index.php?package=Kolab_Storage
  */
-class Horde_Kolab_Storage_StorageTest extends Horde_Kolab_Storage_Scenario
+class Horde_Kolab_Storage_StorageTest extends PHPUnit_Framework_TestCase
 {
     /**
      * Test setup.
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/TriggerTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/TriggerTest.php
new file mode 100644 (file)
index 0000000..20d1adc
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Test the triggering mechanism.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Autoload.php';
+
+/**
+ * Test the triggering mechanism.
+ *
+ * Copyright 2010 Klarälvdalens Datakonsult AB
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_TriggerTest extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->_storage = $this->getMock('Horde_Kolab_Storage', array(), array(), '', false, false);
+        $this->_connection = $this->getMock('Horde_Kolab_Storage_Driver');
+    }
+
+}
\ No newline at end of file