array('user')); $this->assertFalse(windowsUser::isAccountExpired($attrs)); } public function test_isAccountExpired_notExpired() { $expire = $this->getTimeStamp(14); $attrs = array( 'objectClass' => array('user'), 'accounTExpIRes' => array(0 => $expire) ); $this->assertFalse(windowsUser::isAccountExpired($attrs)); } public function test_isAccountExpired_expired() { $expire = $this->getTimeStamp(-14); $attrs = array( 'objectClass' => array('user'), 'accounTExpIRes' => array(0 => $expire) ); $this->assertTrue(windowsUser::isAccountExpired($attrs)); } /** * Returns the timestamp from now with given time difference. * * @param int $diff time difference in days */ private function getTimeStamp($diff) { $timeBase = new DateTime('1601-01-01', getTimeZone()); $time = new DateTime(null, getTimeZone()); if ($diff > 0) { $time->add(new DateInterval('P' . $diff . 'D')); } else { $time->sub(new DateInterval('P' . abs($diff) . 'D')); } $timeDiff = $time->diff($timeBase); $days = $timeDiff->format('%a'); $seconds = $days * 24 * 3600 - ($time->getOffset()); return $seconds . '0000000'; } public function testWindowsManagedGroupsNotifyJob_getLastEffectiveExecutionDate() { if (!interface_exists('\LAM\JOB\Job', false)) { return; } $resultLog = new \LAM\JOB\JobResultLog(); $baseDate = DateTime::createFromFormat('Y-m-d', '2020-08-21', getTimeZone()); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 12, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-07-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 6, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-07-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 3, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-08-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 1, $resultLog)->format('Y-m-d')); $baseDate = DateTime::createFromFormat('Y-m-d', '2020-12-31', getTimeZone()); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 12, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-07-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 6, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-10-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 3, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-12-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 1, $resultLog)->format('Y-m-d')); $baseDate = DateTime::createFromFormat('Y-m-d', '2020-01-01', getTimeZone()); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 12, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 6, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 3, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 1, $resultLog)->format('Y-m-d')); $baseDate = DateTime::createFromFormat('Y-m-d', '2020-06-05', getTimeZone()); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 12, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-01-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 6, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-04-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 3, $resultLog)->format('Y-m-d')); $this->assertEquals('2020-06-01', WindowsManagedGroupsNotifyJob::getLastEffectiveExecutionDate($baseDate, 1, $resultLog)->format('Y-m-d')); } } ?>