/**
  * run multiple async jobs parallel
  */
 public static function triggerAsyncEvents($numOfParallels = 5)
 {
     $cmd = realpath(__DIR__ . "/../../../tine20/tine20.php") . ' --method Tinebase.triggerAsyncEvents';
     $cmd = TestServer::assembleCliCommand($cmd);
     // start multiple cronruns at the same time
     // NOTE: we don't use pnctl as we don't need it here and it's not always available
     for ($i = 0; $i < 5; $i++) {
         $tempNames[] = $fileName = tempnam(Tinebase_Core::getTempDir(), 'asynctest');
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Starting async job: ' . $cmd);
         $result = exec("{$cmd} > {$fileName} 2> /dev/null &");
     }
     // wait for processes to complete
     for ($i = 0; $i < count($tempNames) * 5; $i++) {
         sleep(1);
         $allJobsDone = TRUE;
         foreach ($tempNames as $fileName) {
             $output = file_get_contents($fileName);
             $allJobsDone &= (bool) preg_match('/complete.$/m', $output);
         }
         if ($allJobsDone) {
             break;
         }
     }
     // cleanup
     foreach ($tempNames as $fileName) {
         //echo 'removing ' . $fileName . "\n";
         unlink($fileName);
     }
     if (!$allJobsDone) {
         throw new Exception('jobs did not complete');
     }
 }
    public function setUp()
    {
        $this->_defaultConfig = Tinebase_Redis_Worker_Daemon::getDefaultConfig();
        // config actionqueue
        $this->_actionQueueConfigBackup = Tinebase_Core::getConfig()->actionqueue;
        Tinebase_Core::getConfig()->actionqueue = array('adapter' => 'Redis');
        $this->_redis = new Redis();
        $this->_redis->connect($this->_defaultConfig['host'], $this->_defaultConfig['port'], $this->_defaultConfig['timeout']);
        // start daemon
        $this->_daemonLog = tempnam("/tmp", "tine20daemonttestdaemonlog_");
        $this->_daemonPid = tempnam("/tmp", "tine20daemonttestdaemonpid_");
        $this->_configIni = tempnam("/tmp", "tine20daemontestconfigini_");
        file_put_contents($this->_configIni, <<<EOT
loglevel = 7
EOT
);
        $cmd = realpath(__DIR__ . '/../../../../../tine20/Tinebase/Redis/Worker/Daemon.php') . " -v -d -p {$this->_daemonPid} --config {$this->_configIni} > {$this->_daemonLog} 2>&1 &";
        $cmd = TestServer::assembleCliCommand($cmd);
        exec($cmd);
        sleep(1);
    }
 /**
  * testImportTwice (forceUpdateExisting)
  * 
  * @see 0008652: Import von .ics-Dateien in Kalender schlägt fehl
  */
 public function testImportTwice()
 {
     $this->_testNeedsTransaction();
     $cmd = realpath(__DIR__ . "/../../../../tine20/tine20.php") . ' --method Calendar.import ' . 'plugin=Calendar_Import_Ical forceUpdateExisting=1 container_id=' . $this->_getTestCalendar()->getId() . ' ' . dirname(__FILE__) . '/files/termine.ics';
     $cmd = TestServer::assembleCliCommand($cmd, TRUE);
     exec($cmd, $output);
     $failMessage = print_r($output, TRUE);
     $this->_checkImport($failMessage);
     // second time
     exec($cmd, $output);
     $failMessage = print_r($output, TRUE);
     $this->_checkImport($failMessage);
 }
 /**
  * test ical cli export
  * 
  */
 public function testCliExport()
 {
     $eventData = $this->_getEvent(TRUE)->toArray();
     $this->_uit = new Calendar_Frontend_Json();
     $this->_uit->saveEvent($eventData);
     $this->_testNeedsTransaction();
     $cmd = realpath(__DIR__ . "/../../../../tine20/tine20.php") . ' --method Calendar.exportICS ' . $this->_getTestCalendar()->getId();
     $cmd = TestServer::assembleCliCommand($cmd, TRUE);
     exec($cmd, $output);
     $result = implode(',', $output);
     $failMessage = print_r($output, TRUE);
     $this->assertEquals(1, preg_match("/SUMMARY:{$eventData['summary']}/", $result), 'DESCRIPTION not correct: ' . $failMessage);
 }
 /**
  * check if lang helper is outputting usage information
  *
  * TODO add more langHelper functionality tests
  */
 public function testLangHelperUsageInfo()
 {
     $cmd = realpath(__DIR__ . '/../../../tine20/langHelper.php');
     $cmd = TestServer::assembleCliCommand($cmd);
     exec($cmd, $output);
     $this->assertContains('langHelper.php [ options ]', $output[0]);
 }