/**
  * add timesheet with customfield
  *
  * @param Tinebase_Model_CustomField_Config $_customField1
  * @param string $_cf1Value
  */
 protected function _addTsWithCf($_customField1, $_cf1Value)
 {
     // create custom fields
     $customField2 = $this->_getCustomField();
     // create timesheet and add custom fields
     $timesheetArray = $this->_getTimesheet()->toArray();
     $timesheetArray[$_customField1->name] = $_cf1Value;
     $timesheetArray[$customField2->name] = Tinebase_Record_Abstract::generateUID();
     $timesheetData = $this->_json->saveTimesheet($timesheetArray);
     // checks
     $this->assertTrue(isset($timesheetData['customfields'][$_customField1->name]) || array_key_exists($_customField1->name, $timesheetData['customfields']), 'cf 1 not found');
     $this->assertTrue(isset($timesheetData['customfields'][$customField2->name]) || array_key_exists($customField2->name, $timesheetData['customfields']), 'cf 2 not found');
     $this->assertGreaterThan(0, count($timesheetData['customfields']));
     $this->assertEquals($timesheetArray[$_customField1->name], $timesheetData['customfields'][$_customField1->name]);
     $this->assertEquals($timesheetArray[$customField2->name], $timesheetData['customfields'][$customField2->name]);
     // check if custom fields are returned with search
     $searchResult = $this->_json->searchTimesheets($this->_getTimesheetFilter(), $this->_getPaging());
     $this->assertGreaterThan(0, count($searchResult['results'][0]['customfields']));
     foreach ($searchResult['results'] as $result) {
         if ($result['id'] == $timesheetData['id']) {
             $ts = $result;
         }
     }
     $this->assertTrue(isset($ts));
     $this->assertTrue(isset($ts['customfields'][$_customField1->name]) || array_key_exists($_customField1->name, $ts['customfields']));
     $this->assertTrue(isset($ts['customfields'][$customField2->name]) || array_key_exists($customField2->name, $ts['customfields']));
     $this->assertEquals($timesheetArray[$_customField1->name], $ts['customfields'][$_customField1->name]);
     $this->assertEquals($timesheetArray[$customField2->name], $ts['customfields'][$customField2->name]);
     // test search with custom field filter
     $searchResult = $this->_json->searchTimesheets($this->_getTimesheetFilterWithCustomField($_customField1->getId(), $_cf1Value), $this->_getPaging());
     $this->assertGreaterThan(0, $searchResult['totalcount'], 'cf filter not working');
 }
 /**
  * tests if invoice id gets removed from the billables if the invoice gets deleted
  */
 public function testRemoveInvoiceFromBillables()
 {
     if ($this->_dbIsPgsql()) {
         $this->markTestSkipped('0011670: fix Sales_Invoices Tests with postgresql backend');
     }
     $this->_createFullFixtures();
     $i = 0;
     $date = clone $this->_referenceDate;
     $date->addHour(3);
     $date->addMonth(1);
     $result = $this->_invoiceController->createAutoInvoices($date);
     $json = new Sales_Frontend_Json();
     $invoices = $json->searchInvoices(array(), array());
     $this->assertEquals(2, $invoices['totalcount']);
     foreach ($invoices['results'] as $result) {
         $ids[] = $result['id'];
     }
     $json->deleteInvoices($ids);
     $taJson = new Timetracker_Frontend_Json();
     $tas = $taJson->searchTimeaccounts(array(), array());
     $tss = $taJson->searchTimesheets(array(), array());
     foreach ($tas['results'] as $t) {
         $this->assertEquals(NULL, $t['invoice_id']);
     }
     foreach ($tss['results'] as $t) {
         $this->assertEquals(NULL, $t['invoice_id']);
     }
 }
 /**
  * test and filter
  * @see: 0009730: Fix & use Explicit_Related_Record Filter in all applications
  */
 public function testTimeaccountFailureFilter()
 {
     $req = Zend_Json::decode('{"params":{"filter":
         [{"condition":"OR","filters":[{"condition":"AND","filters":
         [{"field":"start_date","operator":"within","value":"weekLast","id":"ext-record-1"},{"field":"account_id","operator":"AND","value":
         [{"field":"query","operator":"contains","value":"43518","id":"ext-record-
         95"}],"id":"ext-record-2"}],"id":"ext-comp-1074","label":"Stundenzettel"}]}],"paging":
         {"sort":"start_date","dir":"ASC","start":0,"limit":50}}');
     $feTa = new Timetracker_Frontend_Json();
     $result = $feTa->searchTimesheets($req['params']['filter'], $req['params']['paging']);
     $this->assertArrayHasKey('results', $result);
 }