/**
  * try to add a Timesheet with different grants
  * 
  * @param   Tinebase_Record_RecordSet $_grants
  * @param   string $_action
  * @param   mixed $_expect
  * @param   Timetracker_Model_Timesheet
  */
 protected function _grantTestHelper($_grants, $_action = 'create', $_expect = NULL, $_ts = NULL)
 {
     // take default ts?
     $ts = $_ts ? $_ts : $this->_objects['timesheet'];
     // remove BOOK_OWN + BOOK_ALL + ADMIN grant
     Timetracker_Model_TimeaccountGrants::setTimeaccountGrants($this->_objects['timeaccount'], $_grants, TRUE);
     // try to create timesheet
     switch ($_action) {
         case 'create':
             if ($_expect === 'Exception') {
                 $this->setExpectedException('Tinebase_Exception_AccessDenied');
                 $this->_timesheetController->create($ts);
             } else {
                 $ts = $this->_timesheetController->create($ts);
                 $this->assertEquals(Tinebase_Core::getUser()->getId(), $ts->created_by);
             }
             break;
         case 'create_deadline':
             // date is before deadline
             $date = new Tinebase_DateTime();
             $date->sub(8, Tinebase_DateTime::MODIFIER_DAY);
             $ts->start_date = $date->toString('Y-m-d');
             $this->setExpectedException('Timetracker_Exception_Deadline');
             $this->_timesheetController->create($ts);
             break;
         case 'search_bookable':
             $filter = $this->_getTimeaccountFilter(TRUE);
             $result = $this->_timeaccountController->search($filter);
             $this->assertEquals($_expect, count($result));
             break;
         case 'searchTA':
             $filter = $this->_getTimeaccountFilter();
             $result = $this->_timeaccountController->search($filter);
             $this->assertEquals($_expect, count($result));
             break;
         case 'searchTS':
             $filter = $this->_getTimesheetFilter();
             $ts = $this->_timesheetController->create($ts);
             $result = $this->_timesheetController->search($filter);
             $this->assertEquals($_expect, count($result));
             break;
         case 'searchTSExport':
             $filter = $this->_getTimesheetFilter();
             $result = $this->_timesheetController->search($filter, NULL, FALSE, FALSE, 'export');
             $this->assertEquals($_expect, count($result));
             break;
         default:
             echo "nothing tested.";
     }
     // delete (set delete grant first)
     $grants = new Tinebase_Record_RecordSet('Timetracker_Model_TimeaccountGrants', array(array('account_id' => Tinebase_Core::getUser()->getId(), 'account_type' => 'user', Timetracker_Model_TimeaccountGrants::MANAGE_BILLABLE => TRUE, Tinebase_Model_Grants::GRANT_ADMIN => TRUE, Timetracker_Model_TimeaccountGrants::BOOK_ALL => TRUE, Timetracker_Model_TimeaccountGrants::BOOK_OWN => TRUE, Timetracker_Model_TimeaccountGrants::VIEW_ALL => TRUE, Tinebase_Model_Grants::GRANT_EXPORT => TRUE)));
     Timetracker_Model_TimeaccountGrants::setTimeaccountGrants($this->_objects['timeaccount'], $grants, TRUE);
 }