Build package / xml-lint (push) Successful in 3m32s
Build package / unit-tests (push) Successful in 4m49s
Build package / php-lint (8.5) (push) Successful in 4m52s
Build package / php-lint (8.4) (push) Successful in 4m56s
Build package / package (push) Successful in 2m28s
Each workflow now has a trigger date (due or start): the runner compares either the card's due date or its start date against now, read straight from Deck's Card entity. Mails and Nextcloud notifications say whether the card was overdue or reached its start date. Cards without the chosen date stay put. Deck only has a start date since 1.18 and Entity getters are magic, so DeckIntegrationService::supportsStartdate() checks the property; without it the form rejects start-date workflows and the runner skips them without disabling them. WorkflowRunner::isOverdue() becomes hasPassed(), as it now covers both dates. Existing workflows keep the due date (migration Version1005). Bumps to 35.4.0 so the migration runs.
68 lines
2.8 KiB
PHP
68 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\WorkflowDeckAutomation\Tests\Unit\Service;
|
|
|
|
use DateTimeImmutable;
|
|
use DateTimeZone;
|
|
use OCA\WorkflowDeckAutomation\Service\WorkflowRunner;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class WorkflowRunnerTest extends TestCase {
|
|
private static function utc(string $time): DateTimeImmutable {
|
|
return new DateTimeImmutable($time, new DateTimeZone('UTC'));
|
|
}
|
|
|
|
public function testHasPassedReturnsFalseWithoutDate(): void {
|
|
$this->assertFalse(WorkflowRunner::hasPassed(null, self::utc('2026-01-15 12:00:00')));
|
|
}
|
|
|
|
public function testHasPassedReturnsFalseForFutureDate(): void {
|
|
$now = self::utc('2026-01-15 12:00:00');
|
|
$this->assertFalse(WorkflowRunner::hasPassed($now->modify('+1 hour'), $now));
|
|
$this->assertFalse(WorkflowRunner::hasPassed($now->modify('+3 days'), $now));
|
|
}
|
|
|
|
public function testHasPassedReturnsTrueForPastDate(): void {
|
|
$now = self::utc('2026-01-15 12:00:00');
|
|
$this->assertTrue(WorkflowRunner::hasPassed($now->modify('-1 hour'), $now));
|
|
$this->assertTrue(WorkflowRunner::hasPassed($now->modify('-30 days'), $now));
|
|
}
|
|
|
|
public function testHasPassedReturnsTrueForATimeEarlierTheSameDay(): void {
|
|
// Regression: comparing whole calendar days (as Deck's own
|
|
// Card::getDaysUntilDue() does) reports a card due earlier today as
|
|
// "0 days until due", not overdue, until the calendar date rolls
|
|
// over - holding every card back for up to 24h after it actually
|
|
// fell due. hasPassed() must compare the real timestamps instead.
|
|
$now = self::utc('2026-01-15 12:00:00');
|
|
$this->assertTrue(WorkflowRunner::hasPassed(self::utc('2026-01-15 06:00:00'), $now));
|
|
}
|
|
|
|
public function testHasPassedReadsTheStoredWallClockAsUtc(): void {
|
|
// What Entity hydration produces if PHP's default zone is not UTC:
|
|
// the stored UTC wall clock "12:00", tagged with the local zone.
|
|
$date = new DateTimeImmutable('2026-07-15 12:00:00', new DateTimeZone('Europe/Berlin'));
|
|
|
|
// Taken at face value that would be 10:00 UTC and already passed.
|
|
$this->assertFalse(WorkflowRunner::hasPassed($date, self::utc('2026-07-15 11:30:00')));
|
|
$this->assertTrue(WorkflowRunner::hasPassed($date, self::utc('2026-07-15 12:00:01')));
|
|
}
|
|
|
|
public function testHasPassedComparesNowAsAnAbsoluteInstant(): void {
|
|
$date = self::utc('2026-07-15 12:00:00');
|
|
$berlin = new DateTimeZone('Europe/Berlin');
|
|
|
|
// 13:30 in Berlin (CEST) is 11:30 UTC - not yet passed.
|
|
$this->assertFalse(WorkflowRunner::hasPassed($date, new DateTimeImmutable('2026-07-15 13:30:00', $berlin)));
|
|
// 14:30 in Berlin is 12:30 UTC - passed.
|
|
$this->assertTrue(WorkflowRunner::hasPassed($date, new DateTimeImmutable('2026-07-15 14:30:00', $berlin)));
|
|
}
|
|
|
|
public function testHasPassedIsFalseAtTheExactInstant(): void {
|
|
$now = self::utc('2026-01-15 12:00:00');
|
|
$this->assertFalse(WorkflowRunner::hasPassed($now, $now));
|
|
}
|
|
}
|