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');
     }
 }
Example #2
0
 /**
  * testContactDisabledFilter
  */
 public function testContactDisabledFilter()
 {
     $this->_makeSCleverVisibleAgain = TRUE;
     // hide sclever from adb
     $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
     $sclever->visibility = Tinebase_Model_User::VISIBILITY_HIDDEN;
     Tinebase_User::getInstance()->updateUser($sclever);
     // search for her with ContactDisabledFilter
     $filter = array(array('field' => 'n_given', 'operator' => 'equals', 'value' => 'Susan'));
     $result = $this->_instance->searchContacts($filter, array());
     $this->assertEquals(0, $result['totalcount']);
     $filter[] = array('field' => 'showDisabled', 'operator' => 'equals', 'value' => TRUE);
     $result = $this->_instance->searchContacts($filter, array());
     $this->assertEquals(1, $result['totalcount']);
 }
 /**
  * test searching records by bool as a customfield type
  * https://forge.tine20.org/mantisbt/view.php?id=6730
  */
 public function testSearchByBool()
 {
     $cf = self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact', 'definition' => array('type' => 'bool')));
     $this->_instance->addCustomField($cf);
     // contact1 with customfield bool = true
     $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
     $contact1->customfields = array($cf->name => true);
     $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
     // contact2 with customfield bool is not set -> should act like set to false
     $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
     $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
     // test bool = true
     $json = new Addressbook_Frontend_Json();
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => true)), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     // test bool = false
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-bool = true (Rita Blütenrein)');
     $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => false)), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-bool is not set (Rainer Blütenrein)');
     $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
 }
 /**
  * @see 0011704: PHP 7 can't decode empty JSON-strings
  */
 public function testEmptyPagingParamJsonDecode()
 {
     $filter = array(array('field' => 'n_family', 'operator' => 'equals', 'value' => 'somename'));
     $result = $this->_uit->searchContacts($filter, '');
     $this->assertEquals(0, $result['totalcount']);
 }
 /**
  * test searching records by record as a customfield type
  * https://forge.tine20.org/mantisbt/view.php?id=6730
  */
 public function testSearchByRecord()
 {
     $cf = self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact', 'definition' => array('type' => 'record', "recordConfig" => array("value" => array("records" => "Tine.Sales.Model.Contract")))));
     $this->_instance->addCustomField($cf);
     $contract = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('number' => Tinebase_Record_Abstract::generateUID(10), 'title' => Tinebase_Record_Abstract::generateUID(10), 'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId())));
     // contact1 with customfield record = contract
     $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
     $contact1->customfields = array($cf->name => $contract->getId());
     $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
     // contact2 with customfield record is not set -> should act like without this record
     $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
     $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
     $json = new Addressbook_Frontend_Json();
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId()))))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record = contract (Rita Blütenrein)');
     $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "not", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record is not set (Rainer Blütenrein)');
     $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
     // search using the same cf filter in an or - filter
     $contract2 = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('number' => Tinebase_Record_Abstract::generateUID(10), 'title' => Tinebase_Record_Abstract::generateUID(10), 'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId())));
     $contact2->customfields = array($cf->name => $contract2->getId());
     $contact2 = Addressbook_Controller_Contact::getInstance()->update($contact2, false);
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())))), array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract2->getId()))))))), array());
     $this->assertEquals(2, $result['totalcount'], 'Rainer and Rita should have been found.');
     $this->assertEquals('Blütenrein', $result['results'][0]['n_family'], 'Rainer and Rita should have been found.');
     $this->assertEquals('Blütenrein', $result['results'][1]['n_family'], 'Rainer and Rita should have been found.');
 }
 public function testPathResolvingForContacts()
 {
     $this->testBuildGroupMemberPathForContact();
     $adbJson = new Addressbook_Frontend_Json();
     $filter = $this->_getPathFilterArray('father');
     $result = $adbJson->searchContacts($filter, array());
     $this->assertEquals(2, $result['totalcount'], print_r($result['results'], true));
     $firstRecord = $result['results'][0];
     $this->assertTrue(isset($firstRecord['paths']), 'paths should be set in record' . print_r($firstRecord, true));
     // sometimes only 1 path is resolved. this is a little bit strange ...
     $this->assertGreaterThan(0, count($firstRecord['paths']), print_r($firstRecord['paths'], true));
     $this->assertContains('/grandparent', $firstRecord['paths'][0]['path'], 'could not find grandparent in paths of record' . print_r($firstRecord, true));
 }