Add some options to the cli interface. No implementation yet. Fix unit tests.
authorGunnar Wrobel <p@rdus.de>
Tue, 14 Dec 2010 07:58:01 +0000 (08:58 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 14 Dec 2010 17:26:57 +0000 (18:26 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cli.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Autoload.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Server/DriverTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/ModuleTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/OptionsTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CliTest.php

index e87d640..d118a2c 100644 (file)
@@ -50,7 +50,16 @@ class Horde_Kolab_Storage_Cli
             $cli = $parameters['output'];
         }
         list($options, $arguments) = $parser->parseArgs();
-        $cli->message('OK');
+        if (count($arguments) == 0) {
+            $parser->printHelp();
+        } else {
+            switch ($arguments[0]) {
+            case 'folder':
+                break;
+            default:
+                $parser->printHelp();
+            }
+        }
     }
 
     static private function _prepareParser(array $parameters = array())
@@ -60,9 +69,28 @@ class Horde_Kolab_Storage_Cli
         } else {
             $parser_class = $parameters['parser']['class'];
         }
+        $options = array(
+            new Horde_Argv_Option(
+                '-d',
+                '--driver',
+                array(
+                    'action' => 'store',
+                    'choices' => array('horde', 'php', 'pear', 'roundcube', 'mock'),
+                    'help'   => Horde_Kolab_Storage_Translation::t('The IMAP driver that should be used')
+                )
+            ),
+        );
+        $usage = Horde_Kolab_Storage_Translation::t(
+            "[options] MODULE ACTION\nPossible MODULEs and ACTIONs:
+
+  folder - Handle folders.
+    list [default] - List the folders
+"
+        );
         return new $parser_class(
             array(
-                'usage' => '%prog ' . _("[options]")
+                'usage' => '%prog ' . $usage,
+                'optionList' => $options
             )
         );
     }
index 9374960..3ec0be2 100644 (file)
@@ -16,3 +16,6 @@ require_once 'Horde/Test/Autoload.php';
 
 /** Catch strict standards */
 error_reporting(E_ALL | E_STRICT);
+
+/** Load the basic test definition */
+require_once dirname(__FILE__) . '/TestCase.php';
index 87d228e..27b4a4d 100644 (file)
@@ -42,7 +42,7 @@ class Horde_Kolab_Storage_Server_DriverTest extends PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        if ($this->sharedFixture === null) {
+        if (!isset($this->sharedFixture)) {
             $this->markTestSkipped('Testing of a running server skipped. No configuration fixture available.');
             return;
         }
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
new file mode 100644 (file)
index 0000000..9d20936
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Basic test case.
+ *
+ * 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
+ */
+
+/**
+ * Basic test case.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license instorageion (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_TestCase
+extends PHPUnit_Framework_TestCase
+{
+    protected function runCli()
+    {
+        ob_start();
+        Horde_Kolab_Storage_Cli::main(
+            array(
+                'output' => new Horde_Test_Stub_Cli(),
+                'parser' => array('class' => 'Horde_Test_Stub_Parser')
+            )
+        );
+        $output = ob_get_contents();
+        ob_end_clean();
+        return $output;
+    }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/ModuleTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/ModuleTest.php
new file mode 100644 (file)
index 0000000..478e19e
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Test the modules of the CLI interface.
+ *
+ * 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 dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the modules of the CLI interface.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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_Unit_Cli_ModuleTest
+extends Horde_Kolab_Storage_TestCase
+{
+    public function testFolderModule()
+    {
+        $_SERVER['argv'] = array(
+            'kolab-storage'
+        );
+        $this->assertRegExp(
+            '/folder - Handle folders/',
+            $this->runCli()
+        );
+    }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/OptionsTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Cli/OptionsTest.php
new file mode 100644 (file)
index 0000000..7775aa7
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Test the options of the CLI interface.
+ *
+ * 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 dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the options of the CLI interface.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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_Unit_Cli_OptionsTest
+extends Horde_Kolab_Storage_TestCase
+{
+    public function testOptionHelp()
+    {
+        $_SERVER['argv'] = array(
+            'kolab-storage'
+        );
+        $this->assertRegExp(
+            '/-h,[ ]*--help[ ]*show this help message and exit/',
+            $this->runCli()
+        );
+    }
+
+    public function testOptionDriver()
+    {
+        $_SERVER['argv'] = array(
+            'kolab-storage'
+        );
+        $this->assertRegExp(
+            '/-d[ ]*DRIVER,[ ]*--driver=DRIVER/',
+            $this->runCli()
+        );
+    }
+}
index eca945d..938cfad 100644 (file)
@@ -33,21 +33,22 @@ require_once dirname(__FILE__) . '/../Autoload.php';
  * @link       http://pear.horde.org/index.php?package=Kolab_Storage
  */
 class Horde_Kolab_Storage_Unit_CliTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Storage_TestCase
 {
     public function testCli()
     {
         $_SERVER['argv'] = array(
             'kolab-storage'
         );
-        ob_start();
-        Horde_Kolab_Storage_Cli::main(
-            array(
-                'output' => new Horde_Test_Stub_Cli(),
-                'parser' => array('class' => 'Horde_Test_Stub_Parser')
-            )
+        $this->runCli();
+    }
+
+    public function testFolderList()
+    {
+        $_SERVER['argv'] = array(
+            'kolab-storage',
+            'list'
         );
-        $output = ob_get_contents();
-        ob_end_clean();
+        $this->assertContains('INBOX', $this->runCli());
     }
 }