/**
  * test employee creation/update with contracts
  */
 public function testContract()
 {
     $sdate = new Tinebase_DateTime();
     $sdate->subMonth(4);
     $edate = new Tinebase_DateTime();
     $edate->subMonth(3)->subDay(1);
     $now = new Tinebase_DateTime();
     $now->subHour(3);
     $nextMonth = clone $now;
     $nextMonth->addMonth(1);
     $fcId = $this->_getFeastCalendar();
     $contracts = array(array('start_date' => clone $sdate, 'end_date' => clone $edate, 'vacation_days' => 23, 'feast_calendar_id' => $fcId, 'creation_time' => $now, 'id' => 1234567891));
     $sdate->addMonth(1);
     $edate->addMonth(1);
     $contracts[] = array('start_date' => clone $sdate, 'end_date' => clone $edate, 'vacation_days' => 27, 'feast_calendar_id' => $fcId, 'creation_time' => $now, 'id' => 1234567890);
     $employee = $this->_getEmployee('unittest')->toArray();
     $employee['contracts'] = $contracts;
     $employee = $this->_json->saveEmployee($employee);
     $this->assertEquals(2, count($employee['contracts']));
     // get sure the ids are generated properly
     $this->assertEquals(40, strlen($employee['contracts'][1]['id']));
     $this->assertEquals(40, strlen($employee['contracts'][0]['id']));
     $this->_removeAllEmployees();
     // remove ids
     unset($employee['contracts'][0]['id']);
     unset($employee['contracts'][0]['employee_id']);
     unset($employee['contracts'][1]['id']);
     unset($employee['contracts'][1]['employee_id']);
     unset($employee['id']);
     // test overlapping
     // create overlapping contract
     $sdate1 = clone $sdate;
     $edate1 = clone $edate;
     $sdate1->addDay(3);
     $edate1->addMonth(1);
     $employee['contracts'][] = array('start_date' => $sdate1, 'end_date' => $nextMonth, 'vacation_days' => 22, 'feast_calendar_id' => $fcId, 'creation_time' => $now->toString(), 'number' => 1);
     // doing this manually, this won't be the last assertion, and more assertions are needed
     // $this->setExpectedException('Tinebase_Exception_Data');
     $exception = new Exception('no exception has been thrown');
     try {
         $this->_json->saveEmployee($employee);
     } catch (HumanResources_Exception_ContractOverlap $exception) {
         // thrown in HR_Controller_Employee
     }
     $this->assertEquals('The contracts must not overlap!', $exception->getMessage());
     $this->_removeAllEmployees();
     // prevent duplicate exception
     $employee['account_id'] = $this->_getAccount('rwright')->getId();
     // test startdate after end_date
     $employee['contracts'][2] = array('start_date' => $edate1->toString(), 'end_date' => $sdate1->toString(), 'vacation_days' => 22, 'feast_calendar_id' => $fcId, 'creation_time' => $now->toString());
     try {
         $this->_json->saveEmployee($employee);
         $this->fail('HumanResources_Exception_ContractDates exception expected');
     } catch (HumanResources_Exception_ContractDates $exception) {
         // thrown in HR_Controller_Contract
         $this->assertEquals('The start date of the contract must be before the end date!', $exception->getMessage());
     } catch (Tinebase_Exception_Duplicate $ted) {
         $this->fail('got duplicate exception: ' . print_r($ted->toArray(), true));
     }
 }
 /**
  * adds diff to date and applies dst fix
  *
  * @param Tinebase_DateTime $_dateInUTC
  * @param DateTimeInterval $_diff
  * @param string    $_timezoneForDstFix
  */
 public static function addUTCDateDstFix($_dateInUTC, $_diff, $_timezoneForDstFix)
 {
     $_dateInUTC->setTimezone($_timezoneForDstFix);
     $_dateInUTC->add($_dateInUTC->get('I') ? 1 : 0, Tinebase_DateTime::MODIFIER_HOUR);
     $_dateInUTC->add($_diff);
     $_dateInUTC->subHour($_dateInUTC->get('I') ? 1 : 0);
     $_dateInUTC->setTimezone('UTC');
 }
 /**
  * test deleting container and the containing events
  * #6704: events do not disappear when shared calendar got deleted
  * https://forge.tine20.org/mantisbt/view.php?id=6704
  */
 public function testDeleteContainerAndEvents()
 {
     $fe = new Tinebase_Frontend_Json_Container();
     $container = $fe->addContainer('Calendar', 'testdeletecontacts', Tinebase_Model_Container::TYPE_SHARED, '');
     // test if model is set automatically
     $this->assertEquals($container['model'], 'Calendar_Model_Event');
     $date = new Tinebase_DateTime();
     $event = new Calendar_Model_Event(array('dtstart' => $date, 'dtend' => $date->subHour(1), 'summary' => 'bla bla', 'class' => 'PUBLIC', 'transp' => 'OPAQUE', 'container_id' => $container['id'], 'organizer' => Tinebase_Core::getUser()->contact_id));
     $event = Calendar_Controller_Event::getInstance()->create($event);
     $this->assertEquals($container['id'], $event->container_id);
     $fe->deleteContainer($container['id']);
     $e = new Exception('dummy');
     $cb = new Calendar_Backend_Sql();
     $deletedEvent = $cb->get($event->getId(), true);
     // record should be deleted
     $this->assertEquals($deletedEvent->is_deleted, 1);
     try {
         Calendar_Controller_Event::getInstance()->get($event->getId(), $container['id']);
         $this->fail('The expected exception was not thrown');
     } catch (Tinebase_Exception_NotFound $e) {
         // ok;
     }
     // record should not be found
     $this->assertEquals($e->getMessage(), 'Calendar_Model_Event record with id ' . $event->getId() . ' not found!');
 }