|
| 1 | +<?php |
| 2 | + |
| 3 | +use Carbon\CarbonImmutable; |
| 4 | +use Statamic\Modifiers\Modify; |
| 5 | + |
| 6 | +it('returns true when date is in param month', function () { |
| 7 | + expect(modifyInMonth(value: '2026-05-15', params: ['May']))->toBeTrue(); |
| 8 | +}); |
| 9 | + |
| 10 | +it('returns false when date is not in param month', function () { |
| 11 | + expect(modifyInMonth(value: '2026-04-15', params: ['May']))->toBeFalse(); |
| 12 | +}); |
| 13 | + |
| 14 | +it('returns true for first day of month', function () { |
| 15 | + expect(modifyInMonth(value: '2026-05-01', params: ['May']))->toBeTrue(); |
| 16 | +}); |
| 17 | + |
| 18 | +it('returns true for last day of month', function () { |
| 19 | + expect(modifyInMonth(value: '2026-05-31', params: ['May']))->toBeTrue(); |
| 20 | +}); |
| 21 | + |
| 22 | +it('returns false for day before month', function () { |
| 23 | + expect(modifyInMonth(value: '2026-04-30', params: ['May']))->toBeFalse(); |
| 24 | +}); |
| 25 | + |
| 26 | +it('returns false for day after month', function () { |
| 27 | + expect(modifyInMonth(value: '2026-06-01', params: ['May']))->toBeFalse(); |
| 28 | +}); |
| 29 | + |
| 30 | +it('returns true when date matches month from context', function () { |
| 31 | + expect(modifyInMonth(value: '2026-05-15', context: ['get' => ['month' => 'May']]))->toBeTrue(); |
| 32 | +}); |
| 33 | + |
| 34 | +it('returns false when date does not match month from context', function () { |
| 35 | + expect(modifyInMonth(value: '2026-04-15', context: ['get' => ['month' => 'May']]))->toBeFalse(); |
| 36 | +}); |
| 37 | + |
| 38 | +it('param takes precedence over context', function () { |
| 39 | + expect(modifyInMonth(value: '2026-06-01', params: ['June'], context: ['get' => ['month' => 'May']]))->toBeTrue(); |
| 40 | +}); |
| 41 | + |
| 42 | +it('uses current month when no param or context given', function () { |
| 43 | + CarbonImmutable::setTestNow('2026-05-15'); |
| 44 | + |
| 45 | + expect(modifyInMonth(value: '2026-05-01'))->toBeTrue(); |
| 46 | + expect(modifyInMonth(value: '2026-04-30'))->toBeFalse(); |
| 47 | + |
| 48 | + CarbonImmutable::setTestNow(); |
| 49 | +}); |
| 50 | + |
| 51 | +function modifyInMonth(string $value, array $params = [], array $context = []): bool |
| 52 | +{ |
| 53 | + return Modify::value($value)->context($context)->inMonth($params)->fetch(); |
| 54 | +} |
0 commit comments