/** * test custom fields * * - add custom field * - get custom fields for app * - delete custom field */ public function testCustomFields() { // create $customField = $this->_getCustomField(); $createdCustomField = $this->_instance->addCustomField($customField); $this->_objects[] = $createdCustomField; $this->assertEquals($customField->name, $createdCustomField->name); $this->assertNotNull($createdCustomField->getId()); // fetch $application = Tinebase_Application::getInstance()->getApplicationByName('Tinebase'); $appCustomFields = $this->_instance->getCustomFieldsForApplication($application->getId()); $this->assertGreaterThan(0, count($appCustomFields)); $this->assertEquals($application->getId(), $appCustomFields[0]->application_id); // check with model name $appCustomFieldsWithModelName = $this->_instance->getCustomFieldsForApplication($application->getId(), $customField->model); $this->assertGreaterThan(0, count($appCustomFieldsWithModelName)); $this->assertEquals($customField->model, $appCustomFieldsWithModelName[0]->model, 'didn\'t get correct model name'); // check if grants are returned $this->_instance->resolveConfigGrants($appCustomFields); $accountGrants = $appCustomFields->getFirstRecord()->account_grants; sort($accountGrants); $this->assertEquals(Tinebase_Model_CustomField_Grant::getAllGrants(), $accountGrants); // delete $this->_instance->deleteCustomField($createdCustomField); $this->setExpectedException('Tinebase_Exception_NotFound'); $this->_instance->getCustomField($createdCustomField->getId()); $this->_objects = array(); }
/** * test searching records by date as a customfield type * https://forge.tine20.org/mantisbt/view.php?id=6730 */ public function testSearchByDate() { $date = new Tinebase_DateTime(); $cf = self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact', 'definition' => array('type' => 'date'))); $this->_instance->addCustomField($cf); $contact = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein')); $contact->customfields = array($cf->name => $date); $contact = Addressbook_Controller_Contact::getInstance()->create($contact, false); $json = new Addressbook_Frontend_Json(); $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "within", "value" => array("cfId" => $cf->getId(), "value" => "weekThis"))))))), array()); $this->assertEquals(1, $result['totalcount']); $this->assertEquals('Rita', $result['results'][0]['n_given']); $json->deleteContacts(array($contact->getId())); $this->_instance->deleteCustomField($cf); }