public function testSearchEvents()
 {
     $allUsers = Tinebase_User::getInstance()->getFullUsers('');
     xhprof_enable();
     $numSearches = 0;
     foreach ($allUsers as $user) {
         if ($numSearches > 5) {
             break;
         }
         echo "getting month view for {$user->accountDisplayName}\n";
         $filterData = array(array('field' => 'container_id', 'operator' => 'in', 'value' => array('/personal/' . $user->getId(), '/shared')), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => '2010-03-01 00:00:00', 'until' => '2010-04-01 00:00:00')));
         //            $filter = new Calendar_Model_EventFilter($filterData);
         //            $events = Calendar_Controller_Event::getInstance()->search($filter, NULL, FALSE);
         $this->_json->searchEvents($filterData, NULL);
         $numSearches += 1;
     }
     $xhprof_data = xhprof_disable();
     //Tinebase_Core::getDbProfiling();
     $XHPROF_ROOT = '/opt/local/www/php5-xhprof';
     include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
     include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
     $xhprof_runs = new XHProfRuns_Default();
     $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_tine20");
     echo "http://localhost/xhprof_html/index.php?run={$run_id}&source=xhprof_tine20 \n";
     print_r(Tinebase_Record_Abstract::$cns);
 }
 /**
  * testMeAsAttenderFilter
  */
 public function testMeAsAttenderFilter()
 {
     $eventData = $this->testCreateEvent();
     $filter = array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()), array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => Addressbook_Model_Contact::CURRENTCONTACT)));
     $searchResultData = $this->_uit->searchEvents($filter, array());
     $resultEventData = $searchResultData['results'][0];
     $this->_assertJsonEvent($eventData, $resultEventData, 'failed to filter for me as attender');
 }
 /**
  * trigger caldav import by json frontend
  * 
  * @todo use mock as fallback (if server can not be reached by curl)
  * @todo get servername from unittest config / skip or mock if no servername found
  */
 public function testCalDAVImport()
 {
     // Skip if tine20.com.local could not be resolved
     if (gethostbyname('tine20.com.local') == 'tine20.com.local') {
         $this->markTestSkipped('Can\'t perform test, because instance is not reachable.');
     }
     $this->_testNeedsTransaction();
     $event = $this->testCreateEvent(true);
     $fe = new Calendar_Frontend_Json();
     $testUserCredentials = TestServer::getInstance()->getTestCredentials();
     $fe->importRemoteEvents('http://tine20.com.local/calendars/' . Tinebase_Core::getUser()->contact_id . '/' . $event['container_id']['id'], Tinebase_Model_Import::INTERVAL_DAILY, array('container_id' => 'remote_caldav_calendar', 'sourceType' => 'remote_caldav', 'importFileByScheduler' => false, 'allowDuplicateEvents' => true, 'username' => $testUserCredentials['username'], 'password' => $testUserCredentials['password']));
     $importScheduler = Tinebase_Controller_ScheduledImport::getInstance();
     $record = $importScheduler->runNextScheduledImport();
     $container = Tinebase_Container::getInstance()->getContainerByName('Calendar', 'remote_caldav_calendar', Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser()->getId());
     $this->_testCalendars[] = $container;
     $this->assertTrue($container instanceof Tinebase_Model_Container, 'Container was not created');
     $this->assertNotEquals($record, null, 'The import could not start!');
     $filter = $this->_getEventFilterArray($container->getId());
     $result = $this->_uit->searchEvents($filter, array());
     $this->assertEquals(1, $result['totalcount']);
 }
 /**
  * assert private event
  * 
  * @param string $searchMethod
  * @throws InvalidArgumentException
  */
 protected function _assertPrivateEvent($searchMethod = 'search')
 {
     $persistentEvent = $this->_createEventInPersonasCalendar('pwulf', 'pwulf', 'pwulf', Calendar_Model_Event::CLASS_PRIVATE);
     if ($searchMethod === 'search') {
         $filterData = array(array('field' => 'id', 'operator' => 'equals', 'value' => $persistentEvent->getId()));
         $events = $this->_uit->search(new Calendar_Model_EventFilter($filterData), NULL, FALSE, FALSE);
         // assert json fe does not add history
         $json = new Calendar_Frontend_Json();
         $resolvedEvents = $json->searchEvents($filterData, array());
         $this->assertTrue(empty($resolvedEvents['results'][0]['notes']));
     } else {
         if ($searchMethod === 'getMultiple') {
             $events = $this->_uit->getMultiple(array($persistentEvent->getId()));
         } else {
             throw new InvalidArgumentException('unknown search method: ' . $searchMethod);
         }
     }
     $this->assertTrue($events[0]->summary == '');
 }
 /**
  * search an private event of pwulf
  *  -> test user has no private grant -> must be freebusy cleaned!
  */
 public function testPrivateCleanup()
 {
     $persistentEvent = $this->_createEventInPersonasCalendar('pwulf', 'pwulf', 'pwulf', Calendar_Model_Event::CLASS_PRIVATE);
     $filterData = array(array('field' => 'id', 'operator' => 'equals', 'value' => $persistentEvent->getId()));
     $events = $this->_uit->search(new Calendar_Model_EventFilter($filterData), NULL, FALSE, FALSE);
     $this->assertTrue($events[0]->summary == '');
     // assert json fe does not add history
     $json = new Calendar_Frontend_Json();
     $resolvedEvents = $json->searchEvents($filterData, array());
     $this->assertTrue(empty($resolvedEvents['results'][0]['notes']));
 }