Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Feb 28, 2025
1 parent ba71eb5 commit f70b8cb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Collection;
use Statamic\Facades\Entry as EntryFacade;

class MinuteScheduledRevisions
class MinuteRevisions
{
public function __construct(private readonly CarbonInterface $minute)
{
Expand Down
67 changes: 67 additions & 0 deletions tests/Data/Entries/ScheduledRevisionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Tests\Data\Entries;

use Carbon\Carbon;
use Facades\Tests\Factories\EntryFactory;
use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Entries\MinuteRevisions;
use Statamic\Facades\Collection;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;

class ScheduledRevisionsTest extends TestCase
{
use PreventSavingStacheItemsToDisk;

public function setUp(): void
{
parent::setUp();
$this->dir = __DIR__.'/tmp';
config(['statamic.revisions.enabled' => true]);
config(['statamic.revisions.path' => $this->dir]);
}

public function tearDown(): void
{
File::deleteDirectory($this->dir);
parent::tearDown();
}

#[Test]
public function it_gets_entries_scheduled_for_given_minute()
{
Carbon::setTestNow($now = now()->setSeconds(2)->toImmutable());

Collection::make('revisable')->revisionsEnabled(true)->save();

EntryFactory::id(1)
->collection('revisable')
->create()
->makeRevision()
->publishAt($now->addSeconds(5))
->save();

EntryFactory::id(2)
->collection('revisable')
->create()
->makeRevision()
->save();

EntryFactory::id(3)
->collection('revisable')
->create()
->makeRevision()
->publishAt($now->addSeconds(65))
->save();

$this->assertEquals([1], $this->getRevisionsForMinute($now));
$this->assertEmpty($this->getRevisionsForMinute($now->addMinutes(2)));
}

private function getRevisionsForMinute($minute)
{
return (new MinuteRevisions($minute))()->map->id()->all();
}
}

0 comments on commit f70b8cb

Please sign in to comment.