Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Revision Query builder #10437

Open
wants to merge 6 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test the query builder
  • Loading branch information
ryanmitchell committed Jul 11, 2024
commit 62b1702769a96caff2a61ad205e0ba7113a7ad6e
32 changes: 32 additions & 0 deletions tests/Revisions/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\Attributes\Test;
use Statamic\Revisions\Revision;
use Statamic\Revisions\RevisionRepository;
use Statamic\Contracts\Revisions\RevisionQueryBuilder;
use Tests\TestCase;

class RepositoryTest extends TestCase
Expand All @@ -28,4 +29,35 @@ public function it_gets_revisions_and_excludes_working_copies()
$this->assertCount(2, $revisions);
$this->assertContainsOnlyInstancesOf(Revision::class, $revisions);
}

#[Test]
public function it_returns_a_query_builder()
{
$builder = $this->repo->query();

$this->assertInstanceOf(RevisionQueryBuilder::class, $builder);
}

#[Test]
public function it_gets_and_filters_items_using_query_builder()
{
$builder = $this->repo->query();

$revisions = $builder->get();

$this->assertInstanceOf(Collection::class, $revisions);
$this->assertCount(3, $revisions);
$this->assertContainsOnlyInstancesOf(Revision::class, $revisions);

$revisions = $builder->where('key','123')->get();

$this->assertInstanceOf(Collection::class, $revisions);
$this->assertCount(2, $revisions);
$this->assertContainsOnlyInstancesOf(Revision::class, $revisions);

$revisions = $builder->where('key','1234')->get();

$this->assertInstanceOf(Collection::class, $revisions);
$this->assertCount(0, $revisions);
}
}
2 changes: 2 additions & 0 deletions tests/Revisions/__fixtures__/456/1553546521.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
date: 1553546521
attributes: {}
1 change: 1 addition & 0 deletions tests/Revisions/__fixtures__/456/working.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attributes: {}