setEnableQuickPunch( false ); //Helps prevent duplicate punch IDs and validation failures. $dd->setUserNamePostFix( '_' . uniqid( null, true ) ); //Needs to be super random to prevent conflicts and random failing tests. $this->company_id = $dd->createCompany(); $this->legal_entity_id = $dd->createLegalEntity( $this->company_id, 10 ); Debug::text( 'Company ID: ' . $this->company_id, __FILE__, __LINE__, __METHOD__, 10 ); //$dd->createPermissionGroups( $this->company_id, 40 ); //Administrator only. $dd->createCurrency( $this->company_id, 10 ); //$this->branch_id = $dd->createBranch( $this->company_id, 10 ); //NY //$this->department_id = $dd->createDepartment( $this->company_id, 10 ); $dd->createUserWageGroups( $this->company_id ); $this->user_id = $dd->createUser( $this->company_id, $this->legal_entity_id, 100 ); } public function tearDown(): void { Debug::text( 'Running tearDown(): ', __FILE__, __LINE__, __METHOD__, 10 ); } function createPayPeriodSchedule( $shift_assigned_day = 10 ) { $ppsf = new PayPeriodScheduleFactory(); $ppsf->setCompany( $this->company_id ); //$ppsf->setName( 'Bi-Weekly'.rand(1000,9999) ); $ppsf->setName( 'Bi-Weekly' ); $ppsf->setDescription( 'Pay every two weeks' ); $ppsf->setType( 20 ); $ppsf->setStartWeekDay( 0 ); $anchor_date = TTDate::getBeginWeekEpoch( TTDate::incrementDate( time(), -42, 'day' ) ); //Start 6 weeks ago $ppsf->setAnchorDate( $anchor_date ); $ppsf->setStartDayOfWeek( TTDate::getDayOfWeek( $anchor_date ) ); $ppsf->setTransactionDate( 7 ); $ppsf->setTransactionDateBusinessDay( true ); $ppsf->setTimeZone( 'America/Vancouver' ); $ppsf->setDayStartTime( 0 ); $ppsf->setNewDayTriggerTime( ( 4 * 3600 ) ); $ppsf->setMaximumShiftTime( ( 16 * 3600 ) ); $ppsf->setShiftAssignedDay( $shift_assigned_day ); $ppsf->setEnableInitialPayPeriods( false ); if ( $ppsf->isValid() ) { $insert_id = $ppsf->Save( false ); Debug::Text( 'Pay Period Schedule ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10 ); $ppsf->setUser( [ $this->user_id ] ); $ppsf->Save(); $this->pay_period_schedule_id = $insert_id; return $insert_id; } Debug::Text( 'Failed Creating Pay Period Schedule!', __FILE__, __LINE__, __METHOD__, 10 ); return false; } function createPayPeriods( $initial_date = false ) { $max_pay_periods = 35; $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getById( $this->pay_period_schedule_id ); if ( $ppslf->getRecordCount() > 0 ) { $pps_obj = $ppslf->getCurrent(); $end_date = null; for ( $i = 0; $i < $max_pay_periods; $i++ ) { if ( $i == 0 ) { if ( $initial_date !== false ) { $end_date = $initial_date; } else { $end_date = TTDate::getBeginWeekEpoch( TTDate::incrementDate( time(), -42, 'day' ) ); } } else { $end_date = TTDate::incrementDate( $end_date, 14, 'day' ); } Debug::Text( 'I: ' . $i . ' End Date: ' . TTDate::getDate( 'DATE+TIME', $end_date ), __FILE__, __LINE__, __METHOD__, 10 ); $pps_obj->createNextPayPeriod( $end_date, ( 86400 + 3600 ), false ); //Don't import punches, as that causes deadlocks when running tests in parallel. } } return true; } function getAllPayPeriods() { $pplf = new PayPeriodListFactory(); //$pplf->getByCompanyId( $this->company_id ); $pplf->getByPayPeriodScheduleId( $this->pay_period_schedule_id ); if ( $pplf->getRecordCount() > 0 ) { foreach ( $pplf as $pp_obj ) { Debug::text( 'Pay Period... Start: ' . TTDate::getDate( 'DATE+TIME', $pp_obj->getStartDate() ) . ' End: ' . TTDate::getDate( 'DATE+TIME', $pp_obj->getEndDate() ), __FILE__, __LINE__, __METHOD__, 10 ); $this->pay_period_objs[] = $pp_obj; } } $this->pay_period_objs = array_reverse( $this->pay_period_objs ); return true; } /** * @group testSystemLogA */ function testSystemLogA() { global $dd; global $config_vars; //Populate global variables for current_user. $ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */ $user_obj = $ulf->getById( $this->user_id )->getCurrent(); global $current_user, $current_company; $current_user = $user_obj; $current_company = $user_obj->getCompanyObject(); //Enable system log. $config_vars['other']['disable_audit_log'] = false; $config_vars['other']['disable_audit_log_detail'] = false; $user_id = $dd->createUser( $this->company_id, $this->legal_entity_id, 10 ); $llf = new LogListFactory(); $filter_data = [ 'table_name' => 'users', 'object_id' => $user_id ]; $llf->getAPISearchByCompanyIdAndArrayCriteria( $this->company_id, $filter_data ); if ( $llf->getRecordCount() == 1 ) { foreach ( $llf as $l_obj ) { $this->assertEquals( $l_obj->getUser(), $this->user_id ); $this->assertEquals( $l_obj->getObject(), $user_id ); $this->assertEquals( 10, $l_obj->getAction() ); $this->assertEquals( 'users', $l_obj->getTableName() ); $this->assertNotEmpty( $l_obj->getDescription() ); } $this->assertEquals( true, true ); } else { $this->assertEquals( true, false ); } //Disable system log again. $config_vars['other']['disable_audit_log'] = true; $config_vars['other']['disable_audit_log_detail'] = true; return true; } } ?>