/** * test autoComplete of an InventoryItem */ public function testAutoCompleteInventoryItems() { $inventoryRecord = $this->testCreateInventoryItem(); $inventoryRecordID = $inventoryRecord['id']; $json = new Tinebase_Frontend_Json(); $returned = $json->autoComplete('Inventory', 'InventoryItem', 'name', 'mini'); $this->assertEquals('minimal inventory item by PHPUnit::Inventory_JsonTest', $returned['results'][0]['name']); }
/** * testAttachTag * * @see 0008602: Hinzufügen von Tags in der FAQ mit Rechtsklick erzeugt Fehler */ public function testAttachTag() { $faqArray = $this->testAddFaq(); $filter = new SimpleFAQ_Model_FaqFilter(array(array('field' => 'id', 'operator' => 'in', 'value' => array($faqArray['id'])))); $tagData = array('type' => Tinebase_Model_Tag::TYPE_SHARED, 'name' => 'tag::testAttachTagToMultipleFaqRecords', 'description' => 'testAttachTagToMultipleFaqRecords', 'color' => '#009B31'); $tinebaseJson = new Tinebase_Frontend_Json(); $tinebaseJson->attachTagToMultipleRecords($filter->toArray(), 'SimpleFAQ_Model_FaqFilter', $tagData); $result = $this->_instance->getFaq($faqArray['id']); $this->assertEquals(1, count($result['tags'])); }
/** * testGetSaveApplicationConfig */ public function testGetSaveApplicationConfig() { $config = $this->_instance->getConfig('Admin'); $this->assertGreaterThan(0, count($config)); $data = array('id' => 'Admin', 'settings' => Admin_Controller::getInstance()->getConfigSettings()); $newConfig = $this->_instance->saveConfig($data); $this->assertEquals($config, $newConfig); }
/** * testOmitPersonalTagsOnSearch * * @see 0010732: add "use personal tags" right to all applications */ public function testOmitPersonalTagsOnSearch() { $personalTag = $this->_getTag(Tinebase_Model_Tag::TYPE_PERSONAL); Tinebase_Tags::getInstance()->createTag($personalTag); $this->_removeRoleRight('Addressbook', Tinebase_Acl_Rights::USE_PERSONAL_TAGS); $filter = array('application' => 'Addressbook', 'grant' => Tinebase_Model_TagRight::VIEW_RIGHT, 'type' => Tinebase_Model_Tag::TYPE_PERSONAL); $result = $this->_instance->searchTags($filter, array()); $this->assertEquals(0, $result['totalCount']); }
/** * Tests multiple update with relations */ public function testUpdateMultipleWithRelations() { $contract1 = $this->_getContract('contract 1'); $contract2 = $this->_getContract('contract 2'); $contract1 = Sales_Controller_Contract::getInstance()->create($contract1); $contract2 = Sales_Controller_Contract::getInstance()->create($contract2); // peter, bob, laura, lisa list($contact1, $contact2, $contact3, $contact4) = $this->_createContacts(); // add contact2 as customer relation to contract2 $this->_setContractRelations($contract2, array($contact2), 'CUSTOMER'); $contract1and2Ids = array($contract1->id, $contract2->id); $tbJson = new Tinebase_Frontend_Json(); // add Responsible contact1 to both contracts $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%RESPONSIBLE-Addressbook_Model_Contact', 'value' => $contact1->getId())), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(2, count($response['results'])); $contract1re = $this->_instance->getContract($contract1->getId()); $contract2re = $this->_instance->getContract($contract2->getId()); // only one CUSTOMER relation is allowed, contract2 still has related contact2 $this->assertEquals(1, count($contract1re['relations']), 'contract1 relations count failed: ' . print_r($contract1re, true)); $this->assertEquals(2, count($contract2re['relations']), 'contract2 relations count failed: ' . print_r($contract2re, true)); $this->assertEquals($contact1->getId(), $contract1re['relations'][0]['related_id']); if ($contract2re['relations'][1]['related_id'] == $contact1->getId()) { $this->assertEquals($contact1->getId(), $contract2re['relations'][1]['related_id']); $this->assertEquals($contact2->getId(), $contract2re['relations'][0]['related_id']); } else { $this->assertEquals($contact2->getId(), $contract2re['relations'][1]['related_id']); $this->assertEquals($contact1->getId(), $contract2re['relations'][0]['related_id']); } // update customer to contact3 and add responsible to contact4, so contract1 and 2 will have 2 relations $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%CUSTOMER-Addressbook_Model_Contact', 'value' => $contact3->getId()), array('name' => '%RESPONSIBLE-Addressbook_Model_Contact', 'value' => $contact4->getId())), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(count($response['results']), 2); $contract1re = $this->_instance->getContract($contract1->getId()); $contract2re = $this->_instance->getContract($contract2->getId()); $this->assertEquals(2, count($contract1re['relations'])); $this->assertEquals(2, count($contract2re['relations'])); // remove customer $response = $tbJson->updateMultipleRecords('Sales', 'Contract', array(array('name' => '%CUSTOMER-Addressbook_Model_Contact', 'value' => '')), array(array('field' => 'id', 'operator' => 'in', 'value' => $contract1and2Ids))); $this->assertEquals(2, count($response['results'])); $contract1res = $this->_instance->getContract($contract1->getId()); $contract2res = $this->_instance->getContract($contract2->getId()); $this->assertEquals(1, count($contract1res['relations'])); $this->assertEquals(1, count($contract2res['relations'])); }
/** * @see Tinebase_Setup_DemoData_Abstract */ protected function _onCreate() { $currentUser = Tinebase_Core::getUser(); $this->_getDays(); $this->_sharedTaskContainer = $this->_createSharedContainer('Tasks aus Leads', array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId()), false); $fe = new Tinebase_Frontend_Json(); $fe->savePreferences(array("Tasks" => array("defaultTaskList" => array('value' => $this->_sharedTaskContainer->getId()), "defaultpersistentfilter" => array('value' => '_default_'))), true); foreach ($this->_personas as $loginName => $persona) { $this->_containers[$loginName] = Tinebase_Container::getInstance()->getContainerById(Tinebase_Core::getPreference('Crm')->getValueForUser(Crm_Preference::DEFAULTLEADLIST, $persona->getId())); Tinebase_Container::getInstance()->addGrants($this->_containers[$loginName]->getId(), 'user', $this->_personas['sclever']->getId(), $this->_secretaryGrants, true); Tinebase_Container::getInstance()->addGrants($this->_containers[$loginName]->getId(), 'user', $this->_personas['rwright']->getId(), $this->_controllerGrants, true); } }
public function testAttachMultipleTagsToMultipleRecorstds() { $contact1 = $this->_addContact('contact1'); $contact2 = $this->_addContact('contact2'); $tag1 = Tinebase_Tags::getInstance()->create($this->_getTag(Tinebase_Model_Tag::TYPE_PERSONAL, 'tag1')); $tag2 = Tinebase_Tags::getInstance()->create($this->_getTag(Tinebase_Model_Tag::TYPE_PERSONAL, 'tag2')); $filter = array(array('field' => 'id', 'operator' => 'in', 'value' => array($contact1['id'], $contact2['id']))); $tinebaseJson = new Tinebase_Frontend_Json(); $tinebaseJson->attachMultipleTagsToMultipleRecords($filter, 'Addressbook_Model_ContactFilter', array($tag1->toArray(), $tag2->toArray())); $result = $this->_uit->searchContacts($filter, array()); $this->assertCount(2, $result['results'], 'search count failed'); foreach ($result['results'] as $contactData) { $this->assertCount(2, $contactData['tags'], $contactData['n_fn'] . ' tags failed'); } }
/** * search preferences by application felamimail * */ public function testSearchFelamimailPreferences() { // search prefs $result = $this->_frontend->searchPreferencesForApplication('Felamimail', ''); // check results $this->assertTrue(isset($result['results'])); $this->assertGreaterThan(0, $result['totalcount']); }
/** * testGetCoursesPreferences * * @see 0006436: Courses preferences do not work (in pref panel) */ public function testGetCoursesPreferences() { $tinebaseJson = new Tinebase_Frontend_Json(); $coursesPrefs = $tinebaseJson->searchPreferencesForApplication('Courses', array()); $this->assertTrue($coursesPrefs['totalcount'] > 0); $pref = $coursesPrefs['results'][0]; $this->assertEquals(Tinebase_Preference_Abstract::DEFAULTPERSISTENTFILTER, $pref['name']); $this->assertGreaterThanOrEqual(2, count($pref['options'])); }
public function initCalendarImport() { $tbjf = new Tinebase_Frontend_Json(); $registry = $tbjf->getRegistryData(); $_SERVER['HTTP_USER_AGENT'] = 'Tine20/' . $registry['version']['packageString']; }
/** * test search for preferences for anyone of calendar * * @see http://forge.tine20.org/mantisbt/view.php?id=5298 */ public function testSearchCalendarPreferencesForAnyone() { $tasksPersistentFilter = Tinebase_PersistentFilter::getInstance()->getPreferenceValues('Tasks', Tinebase_Core::getUser()->getId()); $json = new Tinebase_Frontend_Json(); $filter = $this->_getPreferenceFilter(NULL, Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE); $result = $json->searchPreferencesForApplication('Tasks', $filter->toArray()); $prefData = $result['results']; $prefToSave = array(); foreach ($prefData as $pref) { if ($pref['name'] === Tasks_Preference::DEFAULTPERSISTENTFILTER) { $prefToSave[$pref['id']] = array('name' => Tasks_Preference::DEFAULTPERSISTENTFILTER, 'value' => $tasksPersistentFilter[5][0], 'type' => Tinebase_Model_Preference::TYPE_ADMIN); } } Tinebase_Core::getPreference('Tasks')->saveAdminPreferences($prefToSave); $result = $json->searchPreferencesForApplication('Calendar', $filter->toArray()); $this->assertGreaterThan(0, $result['totalcount']); $filterPref = NULL; foreach ($result['results'] as $pref) { if ($pref['name'] === Calendar_Preference::DEFAULTPERSISTENTFILTER) { $filterPref = $pref; } } $this->assertTrue($filterPref !== NULL); $this->assertEquals(Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), $filterPref['application_id'], print_r($filterPref, TRUE)); }
/** * testUpdateMultipleTimesheets * @see http://forge.tine20.org/mantisbt/view.php?id=5878 */ public function testUpdateMultipleTimesheets() { // create 100+ timesheets $first = $this->_getTimesheet(array(), TRUE); for ($i = 0; $i < 122; $i++) { $this->_getTimesheet(array('timeaccount_id' => $first->timeaccount_id), TRUE); } // update multi with filter $filterArray = $this->_getTimesheetDateFilter(); $filterArray[] = array('field' => 'is_cleared_combined', 'operator' => 'equals', 'value' => 0); $tinebaseJson = new Tinebase_Frontend_Json(); $result = $tinebaseJson->updateMultipleRecords('Timetracker', 'Timesheet', array(array('name' => 'is_cleared', 'value' => 1)), $filterArray); // check if all got updated $this->assertEquals($result['totalcount'], 123); $this->assertEquals($result['failcount'], 0); $this->assertEquals(1, $result['results'][0]['is_cleared'], print_r($result['results'][0], TRUE)); $this->assertEquals(1, $result['results'][122]['is_cleared'], print_r($result['results'][122], TRUE)); }
/** * testGetRelations * * @see 0009542: load event relations on demand */ public function testGetRelations() { $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'Contact for relations test'))); $eventData = $this->_getEvent()->toArray(); $eventData['relations'] = array(array('own_model' => 'Calendar_Model_Event', 'own_backend' => 'Sql', 'own_id' => 0, 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'type' => '', 'related_backend' => 'Sql', 'related_id' => $contact->getId(), 'related_model' => 'Addressbook_Model_Contact', 'remark' => NULL)); $event = $this->_uit->saveEvent($eventData); $tfj = new Tinebase_Frontend_Json(); $relations = $tfj->getRelations('Calendar_Model_Event', $event['id']); $this->assertEquals(1, $relations['totalcount']); $this->assertEquals($contact->n_fn, $relations['results'][0]['related_record']['n_family'], print_r($relations['results'], true)); }
/** * testInitialRegistry */ public function testInitialRegistry() { $exampleFilterData = self::getPersistentFilterData(); $savedFilterData = $this->testSaveFilter($exampleFilterData); $tfj = new Tinebase_Frontend_Json(); $allRegData = $tfj->getRegistryData(); $this->assertTrue(isset($allRegData['persistentFilters']) || array_key_exists('persistentFilters', $allRegData), 'persistentFilters is missing in $allRegData'); $ids = array(); foreach ($allRegData['persistentFilters']['results'] as $filterData) { $ids[] = $filterData['id']; } $this->assertEquals(1, count(array_intersect($ids, array($savedFilterData['id'])))); }
/** * check 'changed' system note and modlog after tag/customfield update * * @param string $_recordId * @param string|array $_expectedText * @param integer $_changedNoteNumber */ protected function _checkChangedNote($_recordId, $_expectedText = array(), $_changedNoteNumber = 3) { $tinebaseJson = new Tinebase_Frontend_Json(); $history = $tinebaseJson->searchNotes(array(array('field' => 'record_id', 'operator' => 'equals', 'value' => $_recordId)), array('sort' => array('note_type_id', 'creation_time'))); $this->assertEquals($_changedNoteNumber, $history['totalcount'], print_r($history, TRUE)); $changedNote = $history['results'][$_changedNoteNumber - 1]; foreach ((array) $_expectedText as $text) { $this->assertContains($text, $changedNote['note'], print_r($changedNote, TRUE)); } }