/**
  * test timeaccount - sales contract filter
  * also tests Tinebase_Model_Filter_ExplicitRelatedRecord
  */
 public function testTimeaccountContractFilter()
 {
     $this->_getTimeaccount(array('title' => 'TA1', 'number' => 12345, 'description' => 'UnitTest'), true);
     $ta1 = $this->_timeaccountController->get($this->_lastCreatedRecord['id']);
     $this->_getTimeaccount(array('title' => 'TA2', 'number' => 12346, 'description' => 'UnitTest'), true);
     $ta2 = $this->_timeaccountController->get($this->_lastCreatedRecord['id']);
     $cId = Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId();
     $contract = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('title' => 'testRelateTimeaccount', 'number' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $cId)));
     $ta1->relations = array($this->_getRelation($contract, $ta1));
     $this->_timeaccountController->update($ta1);
     // search by contract
     $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $contract->getId())))));
     $filterArray = $f->toArray();
     $this->assertEquals($contract->getId(), $filterArray[0]['value'][0]['value']['id']);
     $result = $this->_timeaccountController->search($f);
     $this->assertEquals(1, $result->count());
     $this->assertEquals('TA1', $result->getFirstRecord()->title);
     // test empty filter (without contract)
     $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => null))), array('field' => 'description', 'operator' => 'equals', 'value' => 'UnitTest')));
     $result = $this->_timeaccountController->search($f);
     $this->assertEquals(1, $result->count(), 'Only one record should have been found!');
     $this->assertEquals('TA2', $result->getFirstRecord()->title);
     // test generic relation filter
     $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'foreignRecord', 'operator' => 'AND', 'value' => array('appName' => 'Sales', 'linkType' => 'relation', 'modelName' => 'Contract', 'filters' => array('field' => 'query', 'operator' => 'contains', 'value' => 'TA1')))));
     $result = $this->_timeaccountController->search($f);
     $this->assertEquals(1, $result->count());
     $this->assertEquals('TA1', $result->getFirstRecord()->title);
     // test "not" operator
     $f = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'contract', 'operator' => 'AND', 'value' => array(array('field' => ':id', 'operator' => 'not', 'value' => $contract->getId()))), array('field' => 'description', 'operator' => 'equals', 'value' => 'UnitTest')));
     $result = $this->_timeaccountController->search($f);
     // TODO is this correct? do we expect the timaccount without contract to be missing from results?
     $this->assertEquals(0, $result->count(), 'No record should be found');
 }
 public function __construct(array $_values = array())
 {
     $this->_id = Tinebase_Record_Abstract::generateUID();
     foreach ($_values as $key => $value) {
         $this->{$key} = $value;
     }
 }
 /**
  * set up tests
  *
  */
 protected function setUp()
 {
     parent::setUp();
     $this->_instance = Tinebase_Notes::getInstance();
     $this->_objects['contact'] = new Addressbook_Model_Contact(array('id' => Tinebase_Record_Abstract::generateUID(), 'n_family' => 'phpunit notes contact'));
     $this->_objects['record'] = array('id' => $this->_objects['contact']->getId(), 'model' => 'Addressbook_Model_Contact', 'backend' => 'Sql');
 }
 public function testToArrayJsonNonExisting()
 {
     $nonExistingId = Tinebase_Record_Abstract::generateUID();
     $filter = new Addressbook_Model_ContactIdFilter('id', 'equals', $nonExistingId);
     $filterArray = $filter->toArray(TRUE);
     $this->assertEquals($nonExistingId, $filterArray['value']);
 }
 /**
  * Sets up the fixture.
  * 
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
     // we need that because the voip db tables can have a different prefix
     Tinebase_Core::set('voipdbTablePrefix', SQL_TABLE_PREFIX);
     $phoneId = Tinebase_Record_Abstract::generateUID();
     $this->_objects['location'] = new Voipmanager_Model_Snom_Location(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'registrar' => 'registrar'));
     $this->_objects['software'] = new Voipmanager_Model_Snom_Software(array('id' => Tinebase_Record_Abstract::generateUID()));
     $this->_objects['setting'] = new Voipmanager_Model_Snom_Setting(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => Tinebase_Record_Abstract::generateUID(), 'description' => Tinebase_Record_Abstract::generateUID(), 'language_w' => true));
     $this->_objects['phonesettings'] = new Voipmanager_Model_Snom_PhoneSettings(array('phone_id' => $phoneId, 'language' => 'Deutsch'));
     $this->_objects['template'] = new Voipmanager_Model_Snom_Template(array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => 'phpunit test location', 'software_id' => $this->_objects['software']->getId(), 'setting_id' => $this->_objects['setting']->getId()));
     $this->_objects['phone'] = new Voipmanager_Model_Snom_Phone(array('id' => $phoneId, 'macaddress' => "1234567890cd", 'location_id' => $this->_objects['location']->getId(), 'template_id' => $this->_objects['template']->getId(), 'current_model' => 'snom320', 'redirect_event' => 'none'));
     $this->_objects['phoneOwner'] = array('account_id' => Zend_Registry::get('currentAccount')->getId(), 'account_type' => 'user');
     $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array($this->_objects['phoneOwner']));
     $this->_objects['phone']->rights = $rights;
     // create phone, location, template
     $snomLocationBackend = new Voipmanager_Backend_Snom_Location();
     $snomTemplateBackend = new Voipmanager_Backend_Snom_Template();
     $snomSoftwareBackend = new Voipmanager_Backend_Snom_Software();
     $snomPhoneBackend = new Voipmanager_Backend_Snom_Phone();
     $snomSettingBackend = new Voipmanager_Backend_Snom_Setting();
     $snomPhoneSettingsBackend = new Voipmanager_Backend_Snom_PhoneSettings();
     $snomSoftwareBackend->create($this->_objects['software']);
     $snomLocationBackend->create($this->_objects['location']);
     $snomTemplateBackend->create($this->_objects['template']);
     $snomSettingBackend->create($this->_objects['setting']);
     $snomPhoneBackend->create($this->_objects['phone']);
     $snomPhoneSettingsBackend->create($this->_objects['phonesettings']);
 }
 /**
  * do conversions
  *
  * @param array $_data
  * @return array
  */
 protected function _doConversions($_data)
 {
     $result = parent::_doConversions($_data);
     if ((isset($result['warranty']) || array_key_exists('warranty', $result)) && empty($_data['warranty'])) {
         unset($result['warranty']);
     }
     if ((isset($result['invoice_date']) || array_key_exists('invoice_date', $result)) && empty($_data['invoice_date'])) {
         unset($result['invoice_date']);
     }
     if ((isset($result["name"]) || array_key_exists("name", $result)) && $result['name'] == "") {
         $result['name'] = "!Not defined!";
     }
     if ((isset($result["inventory_id"]) || array_key_exists("inventory_id", $result)) && $result['inventory_id'] == "") {
         $result['inventory_id'] = Tinebase_Record_Abstract::generateUID(40);
     }
     if (isset($result["costcentre"]) || array_key_exists("costcentre", $result)) {
         $result["costcentre"] = $c = Sales_Controller_CostCenter::getInstance()->search(new Sales_Model_CostCenterFilter(array(array('field' => 'number', 'operator' => 'equals', 'value' => $result["costcentre"]))))->getFirstRecord();
     }
     if (isset($result["status"]) || array_key_exists("status", $result)) {
         $statusRecord = Inventory_Config::getInstance()->get(Inventory_Config::INVENTORY_STATUS)->getKeyfieldRecordByValue($result["status"]);
         if (empty($statusRecord)) {
             $statusRecord = Inventory_Config::getInstance()->get(Inventory_Config::INVENTORY_STATUS)->getKeyfieldDefault();
         }
         $result["status"] = $statusRecord['id'];
     }
     return $result;
 }
 /**
  * overwritten parent constructor to load configuration, calls parent constructor
  * 
  * supported configuration keys:
  * logruntime    => prepend time passed since request started
  * logdifftime   => prepend time passed since last log message
  *
  * @param string $format
  */
 function __construct(string $format = null)
 {
     parent::__construct($format);
     if (!self::$_prefix) {
         self::$_prefix = Tinebase_Record_Abstract::generateUID(5);
     }
     if (self::$_starttime === NULL) {
         self::$_starttime = Tinebase_Core::get(Tinebase_Core::STARTTIME);
         if (self::$_starttime === NULL) {
             self::$_starttime = microtime(true);
         }
     }
     if (self::$_logruntime === NULL || self::$_logdifftime === NULL) {
         $config = Tinebase_Core::getConfig();
         if ($config->logger->logruntime) {
             self::$_logruntime = true;
         } else {
             self::$_logruntime = false;
         }
         if ($config->logger->logdifftime) {
             self::$_logdifftime = true;
         } else {
             self::$_logdifftime = false;
         }
     }
 }
Beispiel #8
0
 /**
  * appends sql to given select statement
  *
  * @param  Zend_Db_Select                $_select
  * @param  Tinebase_Backend_Sql_Abstract $_backend
  * @throws Tinebase_Exception_UnexpectedValue
  */
 public function appendFilterSql($_select, $_backend)
 {
     // don't take empty filter into account
     if (empty($this->_value) || !is_array($this->_value) || !isset($this->_value['cfId']) || empty($this->_value['cfId']) || !isset($this->_value['value'])) {
         return;
     } else {
         if ($this->_operator == 'in') {
             throw new Tinebase_Exception_UnexpectedValue('Operator "in" not supported.');
         }
     }
     // make sure $correlationName is a string
     $correlationName = Tinebase_Record_Abstract::generateUID() . $this->_value['cfId'] . 'cf';
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding custom field filter: ' . print_r($this->_value, true));
     }
     $db = Tinebase_Core::getDb();
     $idProperty = $db->quoteIdentifier($this->_options['idProperty']);
     // per left join we add a customfield column named as the customfield and filter this joined column
     // NOTE: we name the column we join like the customfield, to be able to join multiple customfield criteria (multiple invocations of this function)
     $what = array($correlationName => SQL_TABLE_PREFIX . 'customfield');
     $on = $db->quoteIdentifier("{$correlationName}.record_id") . " = {$idProperty} AND " . $db->quoteIdentifier("{$correlationName}.customfield_id") . " = " . $db->quote($this->_value['cfId']);
     $_select->joinLeft($what, $on, array());
     $valueIdentifier = $db->quoteIdentifier("{$correlationName}.value");
     if ($this->_value['value'] === '') {
         $where = $db->quoteInto($valueIdentifier . ' IS NULL OR ' . $valueIdentifier . ' = ?', $this->_value['value']);
     } else {
         $value = $this->_replaceWildcards($this->_value['value']);
         $where = $db->quoteInto($valueIdentifier . $this->_opSqlMap[$this->_operator]['sqlop'], $value);
     }
     $_select->where($where . ' /* add cf filter */');
 }
 /**
  * appends sql to given select statement
  *
  * @param  Zend_Db_Select                    $_select
  * @param  Tinebase_Backend_Sql_Abstract     $_backend
  */
 public function appendFilterSql($_select, $_backend)
 {
     $correlationName = Tinebase_Record_Abstract::generateUID(30);
     $db = $_backend->getAdapter();
     $_select->joinLeft(array($correlationName => $db->table_prefix . 'adb_list_m_role'), $db->quoteIdentifier($correlationName . '.contact_id') . ' = ' . $db->quoteIdentifier('addressbook.id'), array());
     $_select->where($db->quoteIdentifier($correlationName . '.list_role_id') . ' IN (?)', (array) $this->_value);
 }
 /**
  * testBackslashInDescription
  *
  * @see 0009176: iCal adds another backslash to description field
  */
 public function testBackslashInDescription()
 {
     $event = new Calendar_Model_Event(array('summary' => 'CalDAV test', 'dtstart' => Tinebase_DateTime::now(), 'dtend' => Tinebase_DateTime::now()->addHour(1), 'description' => 'lalala \\\\', 'originator_tz' => 'Europe/Berlin', 'creation_time' => Tinebase_DateTime::now(), 'uid' => Tinebase_Record_Abstract::generateUID(), 'seq' => 1));
     $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX);
     $vevent = $converter->fromTine20Model($event)->serialize();
     $convertedEvent = $converter->toTine20Model($vevent);
     $this->assertEquals($event->description, $convertedEvent->description);
 }
 /**
  * Test create a scheduled import
  */
 public function createScheduledImport($source = 'http://localhost/test.ics')
 {
     $id = Tinebase_Record_Abstract::generateUID();
     $import = new Tinebase_Model_Import(array('id' => $id, 'user_id' => $this->_originalTestUser->getId(), 'interval' => Tinebase_Model_Import::INTERVAL_HOURLY, 'model' => Calendar_Controller::getInstance()->getDefaultModel(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'container_id' => $this->_testCalendar->getId(), 'sourcetype' => Tinebase_Model_Import::SOURCETYPE_REMOTE, 'source' => $source, 'options' => json_encode(array('forceUpdateExisting' => TRUE, 'import_defintion' => NULL, 'plugin' => 'Calendar_Import_Ical'))));
     $record = $this->_uit->create($import);
     $this->assertEquals(Calendar_Controller::getInstance()->getDefaultModel(), $this->_uit->get($id)->model);
     return $record;
 }
 /**
  * test to create a new directory
  */
 public function testCreateDirectory()
 {
     $randomName = Tinebase_Record_Abstract::generateUID();
     $collection = new Addressbook_Frontend_WebDAV(\Sabre\CardDAV\Plugin::ADDRESSBOOK_ROOT . '/' . Tinebase_Core::getUser()->contact_id, true);
     $collection->createDirectory($randomName);
     $container = Tinebase_Container::getInstance()->getContainerByName('Addressbook', $randomName, Tinebase_Model_Container::TYPE_PERSONAL, Tinebase_Core::getUser());
     $this->assertTrue($container instanceof Tinebase_Model_Container);
 }
 /**
  * Test create a access log and logout to set logout time
  *
  * @see 0010728: Strange error in tine20 log when performing logout from Web
  */
 public function testSetLogout()
 {
     $accessLog = new Tinebase_Model_AccessLog(array('ip' => '127.0.0.1', 'li' => Tinebase_DateTime::now(), 'result' => Zend_Auth_Result::SUCCESS, 'clienttype' => 'unittest', 'login_name' => 'unittest', 'user_agent' => 'phpunit', 'sessionid' => Tinebase_Record_Abstract::generateUID()), true);
     $this->_uit->setSessionId($accessLog);
     $this->_uit->create($accessLog);
     $accessLog = $this->_uit->setLogout();
     $this->assertEquals(Tinebase_DateTime::now()->toString(), $accessLog->lo->toString(), 'logout time mismatch/empty: ' . print_r($accessLog, true));
 }
Beispiel #14
0
 /**
  * appends sql to given select statement
  *
  * @param  Zend_Db_Select                    $_select
  * @param  Tinebase_Backend_Sql_Abstract     $_backend
  * @throws Tinebase_Exception_NotFound
  */
 public function appendFilterSql($_select, $_backend)
 {
     $db = $_backend->getAdapter();
     $correlationName = Tinebase_Record_Abstract::generateUID() . $this->_value . 'owner';
     $_select->joinLeft(array($correlationName => SQL_TABLE_PREFIX . 'container_acl'), $db->quoteIdentifier("{$correlationName}.container_id") . " = container.id", array());
     // only personal containers have an owner!
     $_select->where("{$db->quoteIdentifier('container.type')} = ?", Tinebase_Model_Container::TYPE_PERSONAL);
     // assure admin grant
     $_select->where($db->quoteIdentifier("{$correlationName}.account_id") . " = " . $db->quote($this->_value) . ' AND ' . $db->quoteIdentifier("{$correlationName}.account_grant") . " = ?", Tinebase_Model_Grants::GRANT_ADMIN);
 }
 /**
  * test create contact with photo
  *
  * @return Addressbook_Frontend_WebDAV_Contact
  */
 public function testCreateContactWithPhoto()
 {
     $vcardStream = fopen(dirname(__FILE__) . '/../../Import/files/jan.vcf', 'r');
     $id = Tinebase_Record_Abstract::generateUID();
     $contact = Addressbook_Frontend_WebDAV_Contact::create($this->objects['initialContainer'], "{$id}.vcf", $vcardStream);
     $record = $contact->getRecord();
     $imgBlob = $record->getSmallContactImage();
     $this->assertTrue(strlen($imgBlob) > 0);
     $this->assertTrue(strlen($imgBlob) < Addressbook_Model_Contact::SMALL_PHOTO_SIZE);
 }
 /**
  * @param $shadowPath
  * @param $newPath
  * @param $oldPath
  * @param $newShadowPath
  * @param $oldShadowPath
  */
 public function copyTreeByShadowPath($shadowPath, $newPath, $oldPath, $newShadowPath, $oldShadowPath)
 {
     $select = $this->_db->select()->from($this->_tablePrefix . $this->_tableName, array('path' => new Zend_Db_Expr($this->_db->quoteInto($this->_db->quoteInto('REPLACE(path, ?', $oldPath) . ', ?)', $newPath)), 'shadow_path' => new Zend_Db_Expr($this->_db->quoteInto($this->_db->quoteInto('REPLACE(shadow_path, ?', $oldShadowPath) . ', ?)', $newShadowPath)), 'record_id' => 'record_id', 'creation_time' => new Zend_Db_Expr('NOW()')))->where($this->_db->quoteInto($this->_db->quoteIdentifier('shadow_path') . ' like ?', $shadowPath . '/%'));
     $stmt = $this->_db->query($select);
     $entries = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     foreach ($entries as $entry) {
         $entry['id'] = Tinebase_Record_Abstract::generateUID();
         $this->_db->insert($this->_tablePrefix . $this->_tableName, $entry);
     }
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     parent::setUp();
     $this->objects['initialContainer'] = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => Tinebase_Record_Abstract::generateUID(), 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId())));
     $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root());
     $this->plugin = new Tinebase_WebDav_Plugin_Inverse();
     $this->server->addPlugin($this->plugin);
     $this->response = new Sabre\HTTP\ResponseMock();
     $this->server->httpResponse = $this->response;
 }
Beispiel #18
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array    $event    event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     if (!self::$_sessionId) {
         self::$_sessionId = substr(Tinebase_Record_Abstract::generateUID(), 0, 5);
     }
     $user = Tinebase_Core::getUser();
     $userName = $user && is_object($user) ? $user->accountDisplayName : '-- none --';
     $output = parent::format($event);
     return self::$_sessionId . " {$userName} - {$output}";
 }
 /**
  * tests the correct replacement of markers with different contents
  */
 public function testMarkerReplacement()
 {
     $doc = new OpenDocument_Document(OpenDocument_Document::SPREADSHEET);
     $table = $doc->getBody()->appendTable('UNITTEST');
     $titleText = 'Hello unittest!';
     $row = $table->appendRow();
     $cell = $row->appendCell($titleText);
     $row = $table->appendRow();
     $row = $table->appendRow();
     $cell = $row->appendCell('###MATRIX###');
     $row = $table->appendRow();
     $row = $table->appendRow();
     $cell = $row->appendCell('###MARKER###');
     $filename = Tinebase_Config::getInstance()->get('tmpdir') . DIRECTORY_SEPARATOR . Tinebase_Record_Abstract::generateUID(4) . '-ods-unittest.ods';
     $ccc = Sales_Controller_CostCenter::getInstance();
     $cc1 = $ccc->create(new Sales_Model_CostCenter(array('number' => 'cc1', 'remark' => 'unittest-cc1')));
     $cc2 = $ccc->create(new Sales_Model_CostCenter(array('number' => 'cc2', 'remark' => 'unittest-cc2')));
     $colInfo = array();
     $colInfo[$cc1->getId()] = $cc1->number;
     $colInfo[$cc2->getId()] = $cc2->number;
     $matrixArray = array($cc1->getId() => array($cc2->getId() => '100'), $cc2->getId() => array($cc1->getId() => '200'));
     $matrix = new OpenDocument_Matrix($matrixArray, $colInfo, $colInfo, OpenDocument_Matrix::TYPE_FLOAT);
     $matrix->setColumnLegendDescription('Cat');
     $matrix->setRowLegendDescription('Dog');
     $markerText = 'unittest-marker';
     $doc->replaceMarker('marker', $markerText)->replaceMatrix('matrix', $matrix);
     $doc->getDocument($filename);
     $contentXml = file_get_contents('zip://' . $filename . '#content.xml');
     $xml = simplexml_load_string($contentXml);
     unlink($filename);
     $spreadSheets = $xml->xpath('//office:body/office:spreadsheet');
     $this->assertEquals(1, count($spreadSheets));
     $spreadSheet = $spreadSheets[0];
     $results = $spreadSheet->xpath("//text()[contains(., '{$markerText}')]");
     $this->assertEquals(1, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '{$titleText}')]");
     $this->assertEquals(1, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '{$cc1->number}')]");
     $this->assertEquals(2, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '{$cc2->number}')]");
     $this->assertEquals(2, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., 'Sum')]");
     $this->assertEquals(2, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., 'Cat')]");
     $this->assertEquals(1, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., 'Dog')]");
     $this->assertEquals(1, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '100')]");
     $this->assertEquals(3, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '200')]");
     $this->assertEquals(3, count($results));
     $results = $spreadSheet->xpath("//text()[contains(., '300')]");
     $this->assertEquals(1, count($results));
 }
 /**
  * set up tests
  *
  */
 public function setUp()
 {
     $user = Tinebase_Core::getUser();
     $container = $user->getPersonalContainer('Tasks', $user, Tinebase_Model_Grants::GRANT_ADMIN);
     $container_id = $container[0]->getId();
     $backend = new Tasks_Backend_Sql();
     $testTask1 = new Tasks_Model_Task(array('uid' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $container_id, 'created_by' => 6, 'creation_time' => '2009-03-31 17:35:00', 'is_deleted' => 0, 'deleted_time' => NULL, 'deleted_by' => NULL, 'percent' => 70, 'completed' => NULL, 'due' => '2009-04-30 17:35:00', 'description' => "Test Task", 'geo' => 0.2345, 'location' => 'here and there', 'organizer' => Tinebase_Core::getUser()->getId(), 'priority' => 2, 'status' => 'NEEDS-ACTION', 'summary' => 'our first test task', 'url' => 'http://www.testtask.com'));
     $backend->create($testTask1);
     $pfe = new Tinebase_PersistentFilter_Backend_Sql();
     $pfe->create(new Tinebase_Model_PersistentFilter(array('name' => Tasks_Preference::DEFAULTPERSISTENTFILTER_NAME, 'description' => "All my tasks", 'account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId(), 'model' => 'Tasks_Model_TaskFilter', 'filters' => array(array('condition' => 'OR', 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => '/personal/' . Tinebase_Model_User::CURRENTACCOUNT), array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT)))))));
 }
 protected function setupCalendarContent()
 {
     $eventController = Calendar_Controller_Event::getInstance();
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $this->objects['initialContainer']->id, 'summary' => 'change socks', 'dtstart' => '1979-06-05 07:55:00', 'dtend' => '1979-06-05 08:00:00', 'rrule' => 'FREQ=DAILY;INTERVAL=2;UNTIL=2009-04-01 08:00:00', 'exdate' => '2009-03-31 07:00:00', 'originator_tz' => 'Europe/Berlin', 'rrule_until' => '2009-04-01 08:00:00', Tinebase_Model_Grants::GRANT_EDIT => true));
     $eventController->create($event);
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $this->objects['initialContainer']->id, 'summary' => 'change t-shirt', 'dtstart' => '1979-06-05 08:00:00', 'dtend' => '1979-06-05 08:05:00', 'rrule' => 'FREQ=DAILY;INTERVAL=2;UNTIL=2009-04-01 08:00:00', 'exdate' => '2009-03-31 07:00:00', 'originator_tz' => 'Europe/Berlin', 'rrule_until' => '2009-04-01 08:00:00', Tinebase_Model_Grants::GRANT_EDIT => true));
     $persistentEvent = $eventController->create($event);
     $exception = clone $persistentEvent;
     $exception->summary = 'use blue t-shirt today';
     $eventController->createRecurException($exception);
 }
 /**
  * test if config from config.inc.php overwrites config in db
  *
  */
 public function testConfigFromFileOverwrites()
 {
     $configData = (include 'config.inc.php');
     if (!(isset($configData['Overwrite Test']) || array_key_exists('Overwrite Test', $configData))) {
         $this->markTestSkipped('config.inc.php has no test key "Overwrite Test"');
         return;
     }
     $overwrittenValue = Tinebase_Record_Abstract::generateUID();
     $this->_instance->{'Overwrite Test'} = $overwrittenValue;
     $this->assertEquals($configData['Overwrite Test'], $this->_instance->{'Overwrite Test'});
     $this->_instance->delete('Overwrite Test');
 }
 protected function _createFailingContracts()
 {
     // add contract not to bill
     $this->_contractRecords->addRecord($this->_contractController->create(new Sales_Model_Contract(array('number' => 5, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '5 unittest no auto', 'container_id' => $this->_sharedContractsContainerId, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer3')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => $this->_referenceDate, 'end_date' => NULL))));
     // add contract without customer
     $contract = new Sales_Model_Contract(array('number' => 6, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '6 unittest auto not possible', 'container_id' => $this->_sharedContractsContainerId, 'start_date' => $this->_referenceDate, 'end_date' => NULL, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer3')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId()));
     $contract->relations = array(array('own_model' => 'Sales_Model_Contract', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_CostCenter', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $this->_costcenterRecords->getFirstRecord()->getId(), 'type' => 'LEAD_COST_CENTER'));
     $this->_contractRecords->addRecord($this->_contractController->create($contract));
     // add contract without address
     $contract = new Sales_Model_Contract(array('number' => 7, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '7 unittest auto not possible', 'container_id' => $this->_sharedContractsContainerId, 'start_date' => $this->_referenceDate, 'end_date' => NULL));
     $this->_contractRecords->addRecord($this->_contractController->create($contract));
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     parent::setUp();
     Sales_Controller_Contract::getInstance()->setNumberPrefix();
     Sales_Controller_Contract::getInstance()->setNumberZerofill();
     $this->_object = Tinebase_Relations::getInstance();
     $this->_relations = array();
     $this->_crmId = array('model' => 'Crm_Model_Lead', 'backend' => 'SQL', 'id' => Tinebase_Record_Abstract::generateUID());
     $this->_crmId2 = array('model' => 'Crm_Model_Lead', 'backend' => 'SQL', 'id' => Tinebase_Record_Abstract::generateUID());
     $this->_relationData = array(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'SQL', 'own_id' => $this->_crmId['id'], 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Tasks_Model_Task', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => Tinebase_Record_Abstract::generateUID(), 'type' => 'CRM_TASK'), array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'SQL', 'own_id' => $this->_crmId['id'], 'own_degree' => Tinebase_Model_Relation::DEGREE_PARENT, 'related_model' => 'Tasks_Model_Task', 'related_backend' => '', 'related_id' => '', 'related_record' => array('summary' => 'phpunit test task for relations from crm', 'description' => 'This task was created by phpunit when testing relations', 'due' => '2010-06-11T15:47:40'), 'type' => 'CRM_TASK'), array('own_model' => '', 'own_backend' => '', 'own_id' => '', 'own_degree' => Tinebase_Model_Relation::DEGREE_PARENT, 'related_model' => 'Addressbook_Model_Contact', 'related_backend' => '', 'related_id' => '', 'related_record' => array('n_family' => 'Weiss', 'n_given' => 'Cornelius', 'bday' => '1979-06-05T00:00:00', 'container_id' => ''), 'type' => 'PARTNER'));
     $this->_object->setRelations($this->_crmId['model'], $this->_crmId['backend'], $this->_crmId['id'], $this->_relationData);
 }
 /**
  * (non-PHPdoc)
  * @see ActiveSync/ActiveSync_TestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     // replace email to make current user organizer and attendee
     $this->_testXMLInput = str_replace('*****@*****.**', Tinebase_Core::getUser()->accountEmailAddress, $this->_testXMLInput);
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->addMonth(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->addMonth(1)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true, 'attendee' => new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => Tinebase_Core::getUser()->contact_id, 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'status' => Calendar_Model_Attender::STATUS_ACCEPTED)))));
     $event = Calendar_Controller_Event::getInstance()->create($event);
     $this->objects['event'] = $event;
     $event2MonthsBack = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->subMonth(2)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->subMonth(2)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true));
     $event = Calendar_Controller_Event::getInstance()->create($event2MonthsBack);
     $this->objects['event2MonthsBack'] = $event;
     $eventDaily = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => 'SyncTest', 'dtstart' => Tinebase_DateTime::now()->addMonth(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'dtend' => Tinebase_DateTime::now()->addMonth(1)->addHour(1)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'originator_tz' => 'Europe/Berlin', 'rrule' => 'FREQ=DAILY;INTERVAL=1;UNTIL=' . Tinebase_DateTime::now()->addMonth(1)->addDay(6)->setHour(22)->setMinute(59)->setSecond(59)->toString(Tinebase_Record_Abstract::ISO8601LONG), 'container_id' => $this->_getContainerWithSyncGrant()->getId(), Tinebase_Model_Grants::GRANT_EDIT => true));
     $eventDaily = Calendar_Controller_Event::getInstance()->create($eventDaily);
     // compute recurset
     $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($eventDaily, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $eventDaily->dtstart, $eventDaily->rrule_until);
     // first deleted instance
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[0], true);
     // second deleted instance
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[1], true);
     // first exception instance
     $recurSet[2]->dtstart->addHour(2);
     $recurSet[2]->dtend->addHour(2);
     $recurSet[2]->summary = 'Test Exception 1';
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[2]);
     // first exception instance
     $recurSet[3]->dtstart->addHour(3);
     $recurSet[3]->dtend->addHour(3);
     $recurSet[3]->summary = 'Test Exception 2';
     Calendar_Controller_Event::getInstance()->createRecurException($recurSet[3]);
     // reread event from database again
     $eventDaily = Calendar_Controller_Event::getInstance()->get($eventDaily);
     #var_dump($eventDaily->toArray());
     $this->objects['eventDaily'] = $eventDaily;
     Tinebase_Core::getPreference('ActiveSync')->setValue(ActiveSync_Preference::DEFAULTCALENDAR, $this->_getContainerWithSyncGrant()->getId());
     ########### define test filter
     $filterBackend = new Tinebase_PersistentFilter_Backend_Sql();
     try {
         $filter = $filterBackend->getByProperty('Calendar Sync Test', 'name');
     } catch (Tinebase_Exception_NotFound $e) {
         $filter = new Tinebase_Model_PersistentFilter(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'account_id' => Tinebase_Core::getUser()->getId(), 'model' => 'Calendar_Model_EventFilter', 'filters' => array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getContainerWithSyncGrant()->getId())), 'name' => 'Calendar Sync Test', 'description' => 'Created by unit test'));
         $filter = $filterBackend->create($filter);
     }
     $this->objects['filter'] = $filter;
     ########### define test devices
     $palm = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_WEBOS);
     $palm->owner_id = $this->_testUser->getId();
     $palm->calendarfilter_id = $this->objects['filter']->getId();
     $this->objects['deviceWebOS'] = ActiveSync_Controller_Device::getInstance()->create($palm);
     $iphone = ActiveSync_Backend_DeviceTests::getTestDevice(Syncope_Model_Device::TYPE_IPHONE);
     $iphone->owner_id = $this->_testUser->getId();
     $iphone->calendarfilter_id = $this->objects['filter']->getId();
     $this->objects['deviceIPhone'] = ActiveSync_Controller_Device::getInstance()->create($iphone);
 }
 /**
  * interceptor before add
  * 
  * @param array $emailUserData
  */
 protected function _beforeAddOrUpdate(&$emailUserData)
 {
     // add configured domain to domains table
     $select = $this->_db->select()->from(array('domains'), array('name'))->where($this->_db->quoteIdentifier('domains.name') . ' = ?', $this->_config['domain']);
     $stmt = $this->_db->query($select);
     $domains = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
     // did we find all domains in domains table?
     if (count($domains) < 1) {
         $this->_db->insert('domains', array('id' => Tinebase_Record_Abstract::generateUID(), 'name' => $this->_config['domain'], 'backupmx' => 0, 'active' => 1));
     }
     $emailUserData['last_modified'] = Tinebase_DateTime::now()->format(Tinebase_Record_Abstract::ISO8601LONG);
 }
 /**
  * startSetupSession
  * 
  * TODO remove redundancy with Tinebase_Core::startCoreSession()
  */
 public static function startSetupSession()
 {
     Tinebase_Session::setSessionBackend();
     Zend_Session::start();
     $setupSession = Setup_Session::getSessionNamespace();
     if (isset($setupSession->setupuser)) {
         self::set(self::USER, $setupSession->setupuser);
     }
     if (!isset($setupSession->jsonKey)) {
         $setupSession->jsonKey = Tinebase_Record_Abstract::generateUID();
     }
     self::set('jsonKey', $setupSession->jsonKey);
 }
 public function testCreateMinimalTask()
 {
     $summary = 'minimal task by phpunit';
     $task = new Tasks_Model_Task(array('uid' => Tinebase_Record_Abstract::generateUID(), 'summary' => $summary, 'container_id' => $this->container_id));
     $persitantTask = $this->_backend->create($task);
     $pagination = new Tasks_Model_Pagination();
     $filter = new Tasks_Model_TaskFilter(array(array('field' => 'summary', 'operator' => 'contains', 'value' => $summary), array('field' => 'container_id', 'operator' => 'equals', 'value' => $task->container_id)));
     $tasks = $this->_backend->search($filter, $pagination);
     $this->assertEquals(1, count($tasks));
     $db = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'tasks'));
     $db->delete("summary LIKE '{$summary}'");
     Tinebase_Timemachine_ModificationLogTest::purgeLogs($persitantTask->getId());
 }
 /**
  * @return void
  */
 public function testEmailsToAttendee()
 {
     $event = $this->_getEvent();
     $persistentEvent = Calendar_Controller_Event::getInstance()->create($event);
     $sclever = Tinebase_User::getInstance()->getUserByLoginName('sclever', 'Tinebase_Model_FullUser');
     $newEmail = Tinebase_Record_Abstract::generateUID() . '@unittest.com';
     // delete newly created contact in tearDown()
     $this->_testEmailContacts[] = $newEmail;
     $newAttendees = array(array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'firstName' => $this->_originalTestUser->accountFirstName, 'lastName' => $this->_originalTestUser->accountLastName, 'partStat' => Calendar_Model_Attender::STATUS_ACCEPTED, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $this->_originalTestUser->accountEmailAddress), array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'displayName' => $sclever->accountDisplayName, 'partStat' => Calendar_Model_Attender::STATUS_DECLINED, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $sclever->accountEmailAddress), array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'firstName' => 'Lars', 'lastName' => 'Kneschke', 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $newEmail));
     Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE);
     $this->assertEquals(3, count($persistentEvent->attendee));
     $this->assertEquals(1, count($persistentEvent->attendee->filter('status', Calendar_Model_Attender::STATUS_ACCEPTED)));
     $this->assertEquals(1, count($persistentEvent->attendee->filter('status', Calendar_Model_Attender::STATUS_DECLINED)));
     $this->assertEquals(1, count($persistentEvent->attendee->filter('status', Calendar_Model_Attender::STATUS_TENTATIVE)));
 }
 /**
  * test create contact
  * 
  * @return Addressbook_Frontend_WebDAV_Contact
  */
 public function testCreateContact()
 {
     if (!isset($_SERVER['HTTP_USER_AGENT'])) {
         $_SERVER['HTTP_USER_AGENT'] = 'FooBar User Agent';
     }
     $vcardStream = fopen(dirname(__FILE__) . '/../../Import/files/sogo_connector.vcf', 'r');
     $id = Tinebase_Record_Abstract::generateUID();
     $contact = Addressbook_Frontend_WebDAV_Contact::create($this->objects['initialContainer'], "{$id}.vcf", $vcardStream);
     $this->objects['contactsToDelete'][] = $contact;
     $record = $contact->getRecord();
     $this->assertEquals('*****@*****.**', $record->email);
     $this->assertEquals('Kneschke', $record->n_family);
     $this->assertEquals('+49 BUSINESS', $record->tel_work);
     return $contact;
 }