Commits

Ivica Nedeljkovic committed 83b88e5 Merge

Merge with commandLineTests

Comments (0)

Files changed (10)

app/protected/commands/DatabaseCommand.php

         {
             return <<<EOD
     USAGE
-      zurmoc database <action> <filePath>
+      zurmoc database <action> <filePath> <databaseType> <databaseHost> <databaseName> <databasePort> <databaseUsername> <databasePassword>
 
     DESCRIPTION
       This command is used to backup or restore the Zurmo database.
                    a. For backup, filepath where the database backup will be stored
                    b. For restore, path to file from which database will be restored
 
+     Optional Parameters(please note that if you want to use optional parameters, you must use all them):
+     * databaseType, for example mysql, oracle...
+     * databaseHost
+     * databaseName
+     * databasePort
+     * databaseUsername
+     * databasePassword
+
 EOD;
     }
 
                 $filePath = $args[1];
             }
 
+            if (count($args) != 2 && count($args) != 8)
+            {
+                $this->usageError('Invalid number of arguments.');
+            }
+
+            if (count($args) == 8)
+            {
+                $databaseType     = $args[2];
+                $databaseHost     = $args[3];
+                $databaseName     = $args[4];
+                $databasePort     = $args[5];
+                $databaseUsername = $args[6];
+                $databasePassword = $args[7];
+            }
+            else
+            {
+                $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString);
+
+                $databaseType     = $databaseConnectionInfo['databaseType'];
+                $databaseHost     = $databaseConnectionInfo['databaseHost'];
+                $databaseName     = $databaseConnectionInfo['databaseName'];
+                $databasePort     = $databaseConnectionInfo['databasePort'];
+                $databaseUsername = Yii::app()->db->username;
+                $databasePassword = Yii::app()->db->password;
+            }
+
             if (!Yii::app()->isApplicationInMaintenanceMode())
             {
                 $this->usageError('Please set $maintenanceMode = true in the perInstance.php config file.');
 
                 if ($action == 'backup')
                 {
-                    $this->backupDatabase($filePath, $messageStreamer);
+                    $this->backupDatabase($filePath,
+                                          $messageStreamer,
+                                          $databaseType,
+                                          $databaseHost,
+                                          $databaseName,
+                                          $databasePort,
+                                          $databaseUsername,
+                                          $databasePassword);
                 }
                 elseif ($action == 'restore')
                 {
-                    $this->restoreDatabase($filePath, $messageStreamer);
+                    $this->restoreDatabase($filePath,
+                                           $messageStreamer,
+                                           $databaseType,
+                                           $databaseHost,
+                                           $databaseName,
+                                           $databasePort,
+                                           $databaseUsername,
+                                           $databasePassword);
                 }
                 else
                 {
          * Backup database
          * @param string $filePath
          * @param MessageStreamer $messageStreamer
+         * @param $databaseType
+         * @param $databaseHost
+         * @param $databaseName
+         * @param $databasePort
+         * @param $databaseUsername
+         * @param $databasePassword
          */
-        protected function backupDatabase($filePath, $messageStreamer)
+        protected function backupDatabase($filePath,
+                                          $messageStreamer,
+                                          $databaseType,
+                                          $databaseHost,
+                                          $databaseName,
+                                          $databasePort,
+                                          $databaseUsername,
+                                          $databasePassword)
         {
             // If file already exist, ask user to confirm that want to overwrite it.
             if (file_exists($filePath))
             }
 
             $messageStreamer->add(Zurmo::t('Commands', 'Starting database backup process.'));
-            $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString);
 
-            $result = DatabaseCompatibilityUtil::backupDatabase($databaseConnectionInfo['databaseType'],
-                                                                $databaseConnectionInfo['databaseHost'],
-                                                                Yii::app()->db->username,
-                                                                Yii::app()->db->password,
-                                                                $databaseConnectionInfo['databasePort'],
-                                                                $databaseConnectionInfo['databaseName'],
+            $result = DatabaseCompatibilityUtil::backupDatabase($databaseType,
+                                                                $databaseHost,
+                                                                $databaseUsername,
+                                                                $databasePassword,
+                                                                $databasePort,
+                                                                $databaseName,
                                                                 $filePath);
             if ($result)
             {
          * Database must be empty before restore starts.
          * @param string $filePath
          * @param MessageStreamer $messageStreamer
+         * @param $databaseType
+         * @param $databaseHost
+         * @param $databaseName
+         * @param $databasePort
+         * @param $databaseUsername
+         * @param $databasePassword
          */
-        protected function restoreDatabase($filePath, $messageStreamer)
+        protected function restoreDatabase($filePath,
+                                           $messageStreamer,
+                                           $databaseType,
+                                           $databaseHost,
+                                           $databaseName,
+                                           $databasePort,
+                                           $databaseUsername,
+                                           $databasePassword)
         {
             $messageStreamer->add(Zurmo::t('Commands', 'Starting database restore process.'));
-            $databaseConnectionInfo = RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString);
 
-            $tables = DatabaseCompatibilityUtil::getAllTableNames();
-            if (!empty($tables))
-            {
-                $messageStreamer->add(Zurmo::t('Commands', 'Database needs to be empty.'));
-                $messageStreamer->add(Zurmo::t('Commands', 'Database is not restored.'));
-                Yii::app()->end();
-            }
-            $result = DatabaseCompatibilityUtil::restoreDatabase($databaseConnectionInfo['databaseType'],
-                                                                 $databaseConnectionInfo['databaseHost'],
-                                                                 Yii::app()->db->username,
-                                                                 Yii::app()->db->password,
-                                                                 $databaseConnectionInfo['databasePort'],
-                                                                 $databaseConnectionInfo['databaseName'],
+            $result = DatabaseCompatibilityUtil::restoreDatabase($databaseType,
+                                                                 $databaseHost,
+                                                                 $databaseUsername,
+                                                                 $databasePassword,
+                                                                 $databasePort,
+                                                                 $databaseName,
                                                                  $filePath);
             if ($result)
             {

app/protected/commands/ManageMetadataCommand.php

                 }
                 elseif ($action == 'getAllMetadata')
                 {
-                        $this->getAllMetadata();
+                    $this->getAllMetadata();
                 }
                 else
                 {
 
         protected function getAllMetadata()
         {
+            throw new NotImplementedException();
         }
     }
 ?>

app/protected/commands/tests/unit/DatabaseCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class DatabaseCommandTest extends ZurmoBaseTest
+    {
+        protected $temporaryDatabaseHostname;
+        protected $temporaryDatabasePort = 3306;
+        protected $temporaryDatabaseUsername;
+        protected $temporaryDatabasePassword;
+        protected $temporaryDatabaseName;
+        protected $superUserPassword;
+        protected $databaseBackupTestFile;
+
+        public function __construct()
+        {
+            parent::__construct();
+            list(, $this->temporaryDatabaseHostname, $this->temporaryDatabasePort, $this->temporaryDatabaseName) =
+                array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->tempDb->connectionString));
+            $this->temporaryDatabaseUsername = Yii::app()->tempDb->username;
+            $this->temporaryDatabasePassword = Yii::app()->tempDb->password;
+            $this->superUserPassword = 'super';
+            $this->databaseBackupTestFile = INSTANCE_ROOT . '/protected/runtime/databaseBackupTest.sql';
+        }
+
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            $contents = file_get_contents(INSTANCE_ROOT . '/protected/config/perInstanceTest.php');
+            $contents = preg_replace('/\$maintenanceMode\s*=\s*false;/',
+                                     '$maintenanceMode = true;',
+                                     $contents);
+            file_put_contents(INSTANCE_ROOT . '/protected/config/perInstanceTest.php', $contents);
+        }
+
+        public static function tearDownAfterClass()
+        {
+            $contents = file_get_contents(INSTANCE_ROOT . '/protected/config/perInstanceTest.php');
+            $contents = preg_replace('/\$maintenanceMode\s*=\s*true;/',
+                                     '$maintenanceMode = false;',
+                                     $contents);
+            file_put_contents(INSTANCE_ROOT . '/protected/config/perInstanceTest.php', $contents);
+            parent::tearDownAfterClass();
+        }
+
+
+
+        public function setup()
+        {
+            if (is_file($this->databaseBackupTestFile))
+            {
+                unlink($this->databaseBackupTestFile);
+            }
+        }
+
+        public function tearDown()
+        {
+            if (is_file($this->databaseBackupTestFile))
+            {
+                unlink($this->databaseBackupTestFile);
+            }
+        }
+
+        public function testBackupAndRestoreDatabase()
+        {
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+
+            // Create new database (zurmo_temp).
+            if (RedBeanDatabase::getDatabaseType() == 'mysql')
+            {
+                $this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql',
+                    $this->temporaryDatabaseHostname,
+                    $this->temporaryDatabaseUsername,
+                    $this->temporaryDatabasePassword,
+                    $this->temporaryDatabasePort,
+                    $this->temporaryDatabaseName));
+                $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort,
+                    $this->temporaryDatabaseUsername,
+                    $this->temporaryDatabasePassword);
+                $this->assertTrue(is_resource($connection));
+
+                @mysql_select_db($this->temporaryDatabaseName);
+                @mysql_query("create table temptable (temptable_id int(11) unsigned not null)", $connection);
+                @mysql_query("insert into temptable values ('5')", $connection);
+                @mysql_query("insert into temptable values ('10')", $connection);
+                $result = @mysql_query("SELECT count(*) from temptable");
+                $totalRows = mysql_fetch_row($result);
+                @mysql_close($connection);
+
+                $this->assertEquals(2, $totalRows[0]);
+
+                $command = "php zurmocTest.php database backup {$this->databaseBackupTestFile} mysql ";
+                $command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
+                $command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
+
+                if (!IS_WINNT)
+                {
+                    $command .= ' 2>&1';
+                }
+
+                exec($command, $output);
+                sleep(2);
+
+                $this->assertTrue(is_file($this->databaseBackupTestFile));
+
+                //Drop database, and restore it from backup.
+                $this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql',
+                    $this->temporaryDatabaseHostname,
+                    $this->temporaryDatabaseUsername,
+                    $this->temporaryDatabasePassword,
+                    $this->temporaryDatabasePort,
+                    $this->temporaryDatabaseName));
+
+                // Ensure that database don't exist
+                $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort,
+                    $this->temporaryDatabaseUsername,
+                    $this->temporaryDatabasePassword);
+                $this->assertTrue(is_resource($connection));
+
+                @mysql_select_db($this->temporaryDatabaseName, $connection);
+                $result = @mysql_query("SELECT count(*) from temptable", $connection);
+                $this->assertFalse($result);
+
+                // Now restore database
+                $command = "php zurmocTest.php database restore {$this->databaseBackupTestFile} mysql ";
+                $command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
+                $command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
+                if (!IS_WINNT)
+                {
+                    $command .= ' 2>&1';
+                }
+
+                exec($command, $output);
+                sleep(2);
+
+                $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort,
+                    $this->temporaryDatabaseUsername,
+                    $this->temporaryDatabasePassword);
+
+                $this->assertTrue(is_resource($connection));
+
+                $result = @mysql_select_db($this->temporaryDatabaseName, $connection);
+                $this->assertTrue($result);
+
+                $result = @mysql_query("SELECT count(*) from temptable", $connection);
+                $this->assertTrue(is_resource($result));
+                $totalRows = mysql_fetch_row($result);
+
+                $result = @mysql_query("SELECT * from temptable", $connection);
+                $rows1 = mysql_fetch_row($result);
+                $rows2 = mysql_fetch_row($result);
+
+                @mysql_close($connection);
+
+                $this->assertEquals(2, $totalRows[0]);
+                $this->assertEquals(5,  $rows1[0]);
+                $this->assertEquals(10, $rows2[0]);
+            }
+        }
+    }
+?>

app/protected/commands/tests/unit/EmailCommandTest.php

      * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
      ********************************************************************************/
 
-/*********************************************************************************
- * Zurmo is a customer relationship management program developed by
- * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
- *
- * Zurmo is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License version 3 as published by the
- * Free Software Foundation with the addition of the following permission added
- * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
- * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
- * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
- *
- * Zurmo is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, see http://www.gnu.org/licenses or write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- *
- * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
- * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
- ********************************************************************************/
+    class EmailCommandTest extends ZurmoBaseTest
+    {
+        public static $emailHelperSendEmailThroughTransport;
 
-class EmailCommandTest extends ZurmoBaseTest
-{
-    public static $emailHelperSendEmailThroughTransport;
+        public static $userImap;
 
-    public static $userImap;
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+            SecurityTestHelper::createUsers();
 
-    public static function setUpBeforeClass()
-    {
-        parent::setUpBeforeClass();
-        SecurityTestHelper::createSuperAdmin();
-        SecurityTestHelper::createUsers();
+            $imap = new ZurmoImap();
+            $imap->imapHost        = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapHost'];
+            $imap->imapUsername    = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
+            $imap->imapPassword    = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPassword'];
+            $imap->imapPort        = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPort'];
+            $imap->imapSSL         = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapSSL'];
+            $imap->imapFolder      = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapFolder'];
+            $imap->init();
+            $imap->connect();
 
-        $imap = new ZurmoImap();
-        $imap->imapHost        = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapHost'];
-        $imap->imapUsername    = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
-        $imap->imapPassword    = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPassword'];
-        $imap->imapPort        = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPort'];
-        $imap->imapSSL         = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapSSL'];
-        $imap->imapFolder      = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapFolder'];
-        $imap->init();
-        $imap->connect();
+            self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
+            self::$userImap = $imap;
+        }
 
-        self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
-        self::$userImap = $imap;
-    }
+        public static function tearDownAfterClass()
+        {
+            Yii::app()->emailHelper->sendEmailThroughTransport = self::$emailHelperSendEmailThroughTransport;
+            parent::tearDownAfterClass();
+        }
 
-    public static function tearDownAfterClass()
-    {
-        Yii::app()->emailHelper->sendEmailThroughTransport = self::$emailHelperSendEmailThroughTransport;
-        parent::tearDownAfterClass();
-    }
+        public function testActionSend()
+        {
+            if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration())
+            {
+                $super                      = User::getByUsername('super');
+                Yii::app()->user->userModel = $super;
 
-    public function testActionSend()
-    {
-        if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration())
-        {
-            $super                      = User::getByUsername('super');
-            Yii::app()->user->userModel = $super;
+                chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
 
-            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+                $outboundHost     = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundHost'];
+                $outboundPort     = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPort'];
+                $outboundUsername = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundUsername'];
+                $outboundPassword = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPassword'];
+                $outboundSecurity = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundSecurity'];
 
-            $outboundHost     = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundHost'];
-            $outboundPort     = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPort'];
-            $outboundUsername = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundUsername'];
-            $outboundPassword = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPassword'];
-            $outboundSecurity = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundSecurity'];
+                $toAddress = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
 
-            $toAddress = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
+                $subject          = 'A test email from Zurmo';
+                $textContent      = 'A test text message from Zurmo.';
+                $htmlContent      = 'A test html message from Zurmo.';
 
-            $subject          = 'A test email from Zurmo';
-            $textContent      = 'A test text message from Zurmo.';
-            $htmlContent      = 'A test html message from Zurmo.';
+                self::$userImap->deleteMessages(true);
+                self::$userImap->connect();
+                $imapStats = self::$userImap->getMessageBoxStatsDetailed();
+                $this->assertEquals(0, $imapStats->Nmsgs);
 
-            self::$userImap->deleteMessages(true);
-            self::$userImap->connect();
-            $imapStats = self::$userImap->getMessageBoxStatsDetailed();
-            $this->assertEquals(0, $imapStats->Nmsgs);
+                // Begin Not Coding Standard
+                $command = "php zurmocTest.php email send --username=super --toAddress=$toAddress --subject='$subject' --textContent='$textContent' " .
+                           "--htmlContent='$htmlContent' --host=$outboundHost --port=$outboundPort --outboundUsername=$outboundUsername " .
+                           "--outboundPassword=$outboundPassword";
+                // End Not Coding Standard
+                if (isset($outboundSecurity) && $outboundSecurity != false)
+                {
+                    $command .= " --outboundSecurity=$outboundSecurity"; // Not Coding Standard
+                }
+                if (!IS_WINNT)
+                {
+                    $command .= ' 2>&1';
+                }
 
-            // Begin Not Coding Standard
-            $command = "php zurmocTest.php email send --username=super --toAddress=$toAddress --subject='$subject' --textContent='$textContent' " .
-                       "--htmlContent='$htmlContent' --host=$outboundHost --port=$outboundPort --outboundUsername=$outboundUsername " .
-                       "--outboundPassword=$outboundPassword";
-            // End Not Coding Standard
-            if (isset($outboundSecurity) && $outboundSecurity != false)
-            {
-                $command .= " --outboundSecurity=$outboundSecurity"; // Not Coding Standard
+                exec($command, $output);
+
+                // Check if user got email
+                sleep(30);
+                self::$userImap->connect();
+                $imapStats = self::$userImap->getMessageBoxStatsDetailed();
+                $this->assertEquals(1, $imapStats->Nmsgs);
+                $messages = self::$userImap->getMessages();
+                $this->assertEquals(1, count($messages));
+                $this->assertEquals('A test email from Zurmo', trim($messages[0]->subject));
+                $this->assertEquals('A test html message from Zurmo.', trim($messages[0]->htmlBody));
+                $this->assertEquals('A test text message from Zurmo.', trim($messages[0]->textBody));
+                $this->assertEquals(strval(Yii::app()->user->userModel), trim($messages[0]->fromName));
+                $this->assertEquals(Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel), trim($messages[0]->fromEmail));
+                $this->assertTrue(empty($messages[0]->attachments));
             }
-            if (!IS_WINNT)
-            {
-                $command .= ' 2>&1';
-            }
-
-            exec($command, $output);
-
-            // Check if user got email
-            sleep(30);
-            self::$userImap->connect();
-            $imapStats = self::$userImap->getMessageBoxStatsDetailed();
-            $this->assertEquals(1, $imapStats->Nmsgs);
-            $messages = self::$userImap->getMessages();
-            $this->assertEquals(1, count($messages));
-            $this->assertEquals('A test email from Zurmo', trim($messages[0]->subject));
-            $this->assertEquals('A test html message from Zurmo.', trim($messages[0]->htmlBody));
-            $this->assertEquals('A test text message from Zurmo.', trim($messages[0]->textBody));
-            $this->assertEquals(strval(Yii::app()->user->userModel), trim($messages[0]->fromName));
-            $this->assertEquals(Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel), trim($messages[0]->fromEmail));
-            $this->assertTrue(empty($messages[0]->attachments));
         }
     }
-}
 ?>

app/protected/commands/tests/unit/ImportCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class ImportCommandTest extends ZurmoBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+        }
+
+        public function testRun()
+        {
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+
+            $command = "php zurmocTest.php import super testImport";
+
+            if (!IS_WINNT)
+            {
+                $command .= ' 2>&1';
+            }
+
+            exec($command, $output);
+
+            $this->assertTrue(array_search('Error - No import processes found.', $output) !== false);
+            $this->assertTrue(array_search('Error - CustomManagement class needs to be extended.', $output) !== false);
+        }
+    }
+?>

app/protected/commands/tests/unit/InstallCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class InstallCommandTest extends ZurmoBaseTest
+    {
+        protected $temporaryDatabaseHostname;
+        protected $temporaryDatabasePort = 3306;
+        protected $temporaryDatabaseUsername;
+        protected $temporaryDatabasePassword;
+        protected $temporaryDatabaseName;
+        protected $superUserPassword;
+        protected $databaseBackupTestFile;
+
+        protected $originalPerInstanceConfiguration;
+        protected $originalDebugConfiguration;
+
+        public function setUp()
+        {
+            parent::setUp();
+            $instanceRoot = INSTANCE_ROOT;
+            $perInstanceConfigFile      = "$instanceRoot/protected/config/perInstanceTest.php";
+            $debugConfigFile            = "$instanceRoot/protected/config/debugTest.php";
+            if (is_file($perInstanceConfigFile))
+            {
+                $this->originalPerInstanceConfiguration = file_get_contents($perInstanceConfigFile);
+                unlink($perInstanceConfigFile);
+            }
+            if (is_file($debugConfigFile))
+            {
+                $this->originalDebugConfiguration = file_get_contents($debugConfigFile);
+                unlink($debugConfigFile);
+            }
+            $this->assertTrue(!is_file($perInstanceConfigFile));
+            $this->assertTrue(!is_file($debugConfigFile));
+        }
+
+        public function tearDown()
+        {
+            RedBeanDatabase::close();
+            RedBeanDatabase::setup(Yii::app()->db->connectionString,
+                Yii::app()->db->username,
+                Yii::app()->db->password,
+                true);
+
+            $instanceRoot = INSTANCE_ROOT;
+            $perInstanceConfigFile      = "$instanceRoot/protected/config/perInstanceTest.php";
+            $debugConfigFile            = "$instanceRoot/protected/config/debugTest.php";
+
+            // Restore original config files.
+            unlink($debugConfigFile);
+            unlink($perInstanceConfigFile);
+            file_put_contents($perInstanceConfigFile, $this->originalPerInstanceConfiguration);
+            file_put_contents($debugConfigFile, $this->originalDebugConfiguration);
+            parent::tearDown();
+        }
+
+        public function __construct()
+        {
+            parent::__construct();
+            list(, $this->temporaryDatabaseHostname, $this->temporaryDatabasePort, $this->temporaryDatabaseName) =
+                array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->tempDb->connectionString));
+            $this->temporaryDatabaseUsername = Yii::app()->tempDb->username;
+            $this->temporaryDatabasePassword = Yii::app()->tempDb->password;
+            $this->superUserPassword = 'super';
+            $this->databaseBackupTestFile = INSTANCE_ROOT . '/protected/runtime/databaseBackupTest.sql';
+        }
+
+        public function testRun()
+        {
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+
+            $command = "php zurmocTest.php install {$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
+            $command .= "{$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword} {$this->temporaryDatabasePort} ";
+            $command .= "{$this->superUserPassword} 'http://sampleHost' 'app/index.php' demodata 1";
+
+            if (!IS_WINNT)
+            {
+                $command .= ' 2>&1';
+            }
+
+            exec($command, $output);
+
+            $instanceRoot = INSTANCE_ROOT;
+            $perInstanceConfigFile      = "$instanceRoot/protected/config/perInstanceTest.php";
+            $debugConfigFile            = "$instanceRoot/protected/config/debugTest.php";
+            $perInstanceConfiguration = file_get_contents($perInstanceConfigFile);
+            $debugConfiguration = file_get_contents($debugConfigFile);
+
+            //Check if config files is updated.
+            $this->assertRegExp('/\$connectionString = \'mysql:host='.
+                    $this->temporaryDatabaseHostname . ';port=' . $this->temporaryDatabasePort .
+                    ';dbname=' . $this->temporaryDatabaseName . '\';/', // Not Coding Standard
+                $perInstanceConfiguration);
+            $this->assertRegExp('/\$username         = \''.$this->temporaryDatabaseUsername.'\';/',  // Not Coding Standard
+                $perInstanceConfiguration);
+            $this->assertRegExp('/\$password         = \''.$this->temporaryDatabasePassword.'\';/',  // Not Coding Standard
+                $perInstanceConfiguration);
+
+            RedBeanDatabase::close();
+            RedBeanDatabase::setup(Yii::app()->tempDb->connectionString,
+                                   Yii::app()->tempDb->username,
+                                   Yii::app()->tempDb->password,
+                                   true);
+            $count   = R::getRow('select count(*) count from _user');
+            $this->assertEquals(9, $count['count']);
+        }
+    }
+?>

app/protected/commands/tests/unit/JobManagerCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class JobManagerCommandTest extends ZurmoBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+        }
+
+        public function testRun()
+        {
+            $this->assertTrue(ContactsModule::loadStartingData());
+            $messageLogger              = new MessageLogger();
+            InstallUtil::autoBuildDatabase($messageLogger);
+
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+
+            $command = "php zurmocTest.php jobManager super ExportCleanup";
+
+            if (!IS_WINNT)
+            {
+                $command .= ' 2>&1';
+            }
+
+            exec($command, $output);
+            $this->assertTrue(array_search('Info - Job completed successfully', $output) !== false);
+        }
+    }
+?>

app/protected/commands/tests/unit/ManageMetadataCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class ManageMetadataCommandTest extends ZurmoBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+        }
+
+        public function testSaveAllMetadata()
+        {
+            $super                      = User::getByUsername('super');
+            Yii::app()->user->userModel = $super;
+            $this->assertTrue(ContactsModule::loadStartingData());
+            $messageLogger              = new MessageLogger();
+            InstallUtil::autoBuildDatabase($messageLogger);
+
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+            $command = "php zurmocTest.php manageMetadata super saveAllMetadata";
+            if (!IS_WINNT)
+            {
+                $command .= ' 2>&1';
+            }
+
+            exec($command, $output);
+
+            // Check if data are saved for some specific View
+            $moduleMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='NotesModule'");
+            $this->assertTrue($moduleMetadata['id'] > 0);
+            $this->assertTrue(strlen($moduleMetadata['serializedmetadata']) > 0);
+
+            // Check if data are saved for some specific View
+            $modelMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='Note'");
+            $this->assertTrue($modelMetadata['id']> 0);
+            $this->assertTrue(strlen($modelMetadata['serializedmetadata']) > 0);
+
+            // Check if data are saved for some specific View
+            $viewMetadata = R::getRow("SELECT * FROM globalmetadata WHERE classname='ContactsListView'");
+            $this->assertTrue($viewMetadata['id'] > 0);
+            $this->assertTrue(strlen($viewMetadata['serializedmetadata']) > 0);
+        }
+    }
+?>

app/protected/commands/tests/unit/UpdateSchemaCommandTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class UpdateSchemaCommandTest extends ZurmoBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+        }
+
+        public function testRun()
+        {
+            $this->assertTrue(ContactsModule::loadStartingData());
+            $messageLogger              = new MessageLogger();
+            InstallUtil::autoBuildDatabase($messageLogger);
+
+            chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
+
+            $command = "php zurmocTest.php updateSchema super";
+
+            if (!IS_WINNT)
+            {
+                $command .= ' 2>&1';
+            }
+
+            exec($command, $output);
+            $this->assertTrue(array_search('Info - Auto built Account saved.', $output) !== false);
+            $this->assertTrue(array_search('Schema update complete.', $output) !== false);
+        }
+    }
+?>

app/protected/tests/unit/TestSuite.php

             if (!$freeze)
             {
                 self::buildAndAddSuiteFromDirectory($suite, 'Misc',            COMMON_ROOT . '/protected/tests/unit',                     $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
+                self::buildAndAddSuiteFromDirectory($suite, 'Commands',        COMMON_ROOT . '/protected/commands/tests/unit',             $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
 ////////////////////////////////////////////////////////////////////////////////
 // Temporary - See Readme.txt in the notSupposedToBeHere directory.
                 self::buildAndAddSuiteFromDirectory($suite, 'BadDependencies', COMMON_ROOT . '/protected/tests/unit/notSupposedToBeHere', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
 ////////////////////////////////////////////////////////////////////////////////
             }
-            else
-            {
-                self::buildAndAddSuiteFromDirectory($suite, 'Commands',        COMMON_ROOT . '/protected/commands/tests/unit',             $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
-            }
+
             if ($suite->count() == 0)
             {
                 echo $usage;